mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
* chore: configure project-wide linting and formatting * chore: run lint autofix and formatter
30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
import restana from 'restana';
|
|
import { config, getDirName, readConfigFromStorage, refreshConfig } from '../../utils.js';
|
|
import fs from 'fs';
|
|
import { handleDemoUser } from '../../services/storage/userStorage.js';
|
|
const service = restana();
|
|
const generalSettingsRouter = service.newRouter();
|
|
generalSettingsRouter.get('/', async (req, res) => {
|
|
res.body = Object.assign({}, config);
|
|
res.send();
|
|
});
|
|
generalSettingsRouter.post('/', async (req, res) => {
|
|
const settings = req.body;
|
|
try {
|
|
if (config.demoMode) {
|
|
res.send(new Error('In demo mode, it is not allowed to change these settings.'));
|
|
return;
|
|
}
|
|
const currentConfig = await readConfigFromStorage();
|
|
fs.writeFileSync(`${getDirName()}/../conf/config.json`, JSON.stringify({ ...currentConfig, ...settings }));
|
|
await refreshConfig();
|
|
handleDemoUser();
|
|
} catch (err) {
|
|
console.error(err);
|
|
res.send(new Error('Error while trying to write settings.'));
|
|
return;
|
|
}
|
|
res.send();
|
|
});
|
|
export { generalSettingsRouter };
|