2024-03-20 00:07:28 +01:00
|
|
|
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 router = express.Router();
|
|
|
|
|
|
|
|
router.post('/save', jsonParser, (request, response) => {
|
|
|
|
if (!request.body || !request.body.name) {
|
|
|
|
return response.sendStatus(400);
|
|
|
|
}
|
|
|
|
|
2024-04-07 00:47:07 +02:00
|
|
|
const filename = path.join(request.user.directories.movingUI, sanitize(request.body.name) + '.json');
|
2024-03-20 00:07:28 +01:00
|
|
|
writeFileAtomicSync(filename, JSON.stringify(request.body, null, 4), 'utf8');
|
|
|
|
|
|
|
|
return response.sendStatus(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = { router };
|