2023-03-13 13:42:43 +01:00
|
|
|
import restana from 'restana';
|
2025-07-26 20:42:58 +02:00
|
|
|
import { config, getDirName, readConfigFromStorage, refreshConfig } from '../../utils.js';
|
2023-03-13 13:42:43 +01:00
|
|
|
import fs from 'fs';
|
2025-07-26 20:42:58 +02:00
|
|
|
import { handleDemoUser } from '../../services/storage/userStorage.js';
|
2023-03-13 13:42:43 +01:00
|
|
|
const service = restana();
|
2021-05-30 09:37:45 +02:00
|
|
|
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 {
|
2025-07-26 20:42:58 +02:00
|
|
|
if (config.demoMode) {
|
2024-11-22 09:11:10 +01:00
|
|
|
res.send(new Error('In demo mode, it is not allowed to change these settings.'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-11-20 22:22:16 +01:00
|
|
|
const currentConfig = await readConfigFromStorage();
|
2025-07-26 20:42:58 +02:00
|
|
|
fs.writeFileSync(`${getDirName()}/../conf/config.json`, JSON.stringify({ ...currentConfig, ...settings }));
|
2024-11-20 22:22:16 +01:00
|
|
|
await refreshConfig();
|
2024-11-22 09:11:10 +01:00
|
|
|
handleDemoUser();
|
2021-05-30 09:37:45 +02:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
res.send(new Error('Error while trying to write settings.'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
res.send();
|
|
|
|
|
});
|
2023-03-13 13:42:43 +01:00
|
|
|
export { generalSettingsRouter };
|