Use Express router for content endpoint

This commit is contained in:
valadaptive 2023-12-04 12:47:38 -05:00
parent 414c9bd5fb
commit 4c911d3155
2 changed files with 45 additions and 48 deletions

View File

@ -3603,7 +3603,7 @@ require('./src/endpoints/assets').registerEndpoints(app, jsonParser);
require('./src/endpoints/sprites').registerEndpoints(app, jsonParser, urlencodedParser); require('./src/endpoints/sprites').registerEndpoints(app, jsonParser, urlencodedParser);
// Custom content management // Custom content management
require('./src/endpoints/content-manager').registerEndpoints(app, jsonParser); app.use('/api/content', require('./src/endpoints/content-manager').router);
// Stable Diffusion generation // Stable Diffusion generation
require('./src/endpoints/stable-diffusion').registerEndpoints(app, jsonParser); require('./src/endpoints/stable-diffusion').registerEndpoints(app, jsonParser);

View File

@ -1,8 +1,10 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const express = require('express');
const fetch = require('node-fetch').default; const fetch = require('node-fetch').default;
const sanitize = require('sanitize-filename'); const sanitize = require('sanitize-filename');
const { getConfigValue } = require('../util'); const { getConfigValue } = require('../util');
const { jsonParser } = require('../express-common');
const contentDirectory = path.join(process.cwd(), 'default/content'); const contentDirectory = path.join(process.cwd(), 'default/content');
const contentLogPath = path.join(contentDirectory, 'content.log'); const contentLogPath = path.join(contentDirectory, 'content.log');
const contentIndexPath = path.join(contentDirectory, 'index.json'); const contentIndexPath = path.join(contentDirectory, 'index.json');
@ -302,13 +304,9 @@ function parseJannyUrl(url) {
return uuid; return uuid;
} }
/** const router = express.Router();
* Registers endpoints for custom content management
* @param {import('express').Express} app Express app router.post('/import', jsonParser, async (request, response) => {
* @param {any} jsonParser JSON parser middleware
*/
function registerEndpoints(app, jsonParser) {
app.post('/api/content/import', jsonParser, async (request, response) => {
if (!request.body.url) { if (!request.body.url) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -353,11 +351,10 @@ function registerEndpoints(app, jsonParser) {
return response.sendStatus(500); return response.sendStatus(500);
} }
}); });
}
module.exports = { module.exports = {
checkForNewContent, checkForNewContent,
registerEndpoints,
getDefaultPresets, getDefaultPresets,
getDefaultPresetFile, getDefaultPresetFile,
router,
}; };