Extract API endpoint for moving UI
This commit is contained in:
parent
b261c8c4a9
commit
abb8bdbc1e
|
@ -2175,7 +2175,7 @@ async function saveMovingUI() {
|
|||
};
|
||||
console.log(movingUIPreset);
|
||||
|
||||
const response = await fetch('/savemovingui', {
|
||||
const response = await fetch('/api/moving-ui/save', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify(movingUIPreset),
|
||||
|
|
22
server.js
22
server.js
|
@ -10,8 +10,6 @@ const util = require('util');
|
|||
|
||||
// cli/fs related library imports
|
||||
const open = require('open');
|
||||
const sanitize = require('sanitize-filename');
|
||||
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||
const yargs = require('yargs/yargs');
|
||||
const { hideBin } = require('yargs/helpers');
|
||||
|
||||
|
@ -36,7 +34,6 @@ util.inspect.defaultOptions.maxStringLength = null;
|
|||
// local library imports
|
||||
const basicAuthMiddleware = require('./src/middleware/basicAuth');
|
||||
const whitelistMiddleware = require('./src/middleware/whitelist');
|
||||
const { jsonParser } = require('./src/express-common.js');
|
||||
const contentManager = require('./src/endpoints/content-manager');
|
||||
const {
|
||||
getVersion,
|
||||
|
@ -200,7 +197,7 @@ if (getConfigValue('enableCorsProxy', false) || cliArguments.corsProxy) {
|
|||
app.use(express.static(process.cwd() + '/public', {}));
|
||||
|
||||
app.use('/backgrounds', (req, res) => {
|
||||
const filePath = decodeURIComponent(path.join(process.cwd(), 'public/backgrounds', req.url.replace(/%20/g, ' ')));
|
||||
const filePath = decodeURIComponent(path.join(process.cwd(), DIRECTORIES.backgrounds, req.url.replace(/%20/g, ' ')));
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
res.status(404).send('File not found');
|
||||
|
@ -230,17 +227,6 @@ app.get('/version', async function (_, response) {
|
|||
response.send(data);
|
||||
});
|
||||
|
||||
app.post('/savemovingui', jsonParser, (request, response) => {
|
||||
if (!request.body || !request.body.name) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const filename = path.join(DIRECTORIES.movingUI, sanitize(request.body.name) + '.json');
|
||||
writeFileAtomicSync(filename, JSON.stringify(request.body, null, 4), 'utf8');
|
||||
|
||||
return response.sendStatus(200);
|
||||
});
|
||||
|
||||
function cleanUploads() {
|
||||
try {
|
||||
if (fs.existsSync(UPLOADS_PATH)) {
|
||||
|
@ -340,6 +326,12 @@ redirect('/savequickreply', '/api/quick-replies/save');
|
|||
redirect('/uploadimage', '/api/images/upload');
|
||||
redirect('/listimgfiles/:folder', '/api/images/list/:folder');
|
||||
|
||||
// Redirect deprecated moving UI endpoints
|
||||
redirect('/savemovingui', '/api/moving-ui/save');
|
||||
|
||||
// Moving UI
|
||||
app.use('/api/moving-ui', require('./src/endpoints/moving-ui').router);
|
||||
|
||||
// Image management
|
||||
app.use('/api/images', require('./src/endpoints/images').router);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ const { DIRECTORIES, UPLOADS_PATH } = require('../constants');
|
|||
const { invalidateThumbnail } = require('./thumbnails');
|
||||
const { getImages } = require('../util');
|
||||
|
||||
const router = new express.Router();
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/all', jsonParser, function (request, response) {
|
||||
var images = getImages('public/backgrounds');
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const path = require('path');
|
||||
const express = require('express');
|
||||
const sanitize = require('sanitize-filename');
|
||||
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||
|
||||
const { jsonParser } = require('../express-common');
|
||||
const { DIRECTORIES } = require('../constants');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/save', jsonParser, (request, response) => {
|
||||
if (!request.body || !request.body.name) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const filename = path.join(DIRECTORIES.movingUI, sanitize(request.body.name) + '.json');
|
||||
writeFileAtomicSync(filename, JSON.stringify(request.body, null, 4), 'utf8');
|
||||
|
||||
return response.sendStatus(200);
|
||||
});
|
||||
|
||||
module.exports = { router };
|
Loading…
Reference in New Issue