| 1 | import path from 'node:path'; |
| 2 | import express from 'express'; |
| 3 | import sanitize from 'sanitize-filename'; |
| 4 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| 5 | |
| 6 | export const router = express.Router(); |
| 7 | |
| 8 | router.post('/save', (request, response) => { |
| 9 | if (!request.body || !request.body.name) { |
| 10 | return response.sendStatus(400); |
| 11 | } |
| 12 | |
| 13 | const filename = path.join(request.user.directories.movingUI, sanitize(`${request.body.name}.json`)); |
| 14 | writeFileAtomicSync(filename, JSON.stringify(request.body, null, 4), 'utf8'); |
| 15 | |
| 16 | return response.sendStatus(200); |
| 17 | }); |