2017-10-22 09:10:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-16 07:47:05 +08:00
|
|
|
const sql = require('../../services/sql');
|
2018-04-02 09:27:46 +08:00
|
|
|
const optionService = require('../../services/options');
|
2018-06-03 01:02:20 +08:00
|
|
|
const log = require('../../services/log');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-04-02 05:41:28 +08:00
|
|
|
// options allowed to be updated directly in options dialog
|
2018-07-23 04:21:16 +08:00
|
|
|
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval',
|
2018-12-12 04:53:56 +08:00
|
|
|
'zoomFactor', 'theme', 'syncServerHost', 'syncServerTimeout', 'syncProxy', 'leftPaneMinWidth', 'leftPaneWidthPercent', 'hoistedNoteId'];
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-04-02 08:33:10 +08:00
|
|
|
async function getOptions() {
|
2018-09-06 17:54:04 +08:00
|
|
|
return await optionService.getOptionsMap(ALLOWED_OPTIONS);
|
2018-03-31 01:56:46 +08:00
|
|
|
}
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-04-02 05:41:28 +08:00
|
|
|
async function updateOption(req) {
|
2018-04-02 08:33:10 +08:00
|
|
|
const {name, value} = req.params;
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-07-23 04:21:16 +08:00
|
|
|
if (!update(name, value)) {
|
|
|
|
return [400, "not allowed option to change"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateOptions(req) {
|
|
|
|
for (const optionName in req.body) {
|
|
|
|
if (!update(optionName, req.body[optionName])) {
|
|
|
|
// this should be improved
|
|
|
|
// it should return 400 instead of current 500, but at least it now rollbacks transaction
|
|
|
|
throw new Error(`${optionName} is not allowed to change`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function update(name, value) {
|
2018-04-02 08:33:10 +08:00
|
|
|
if (!ALLOWED_OPTIONS.includes(name)) {
|
2018-07-23 04:21:16 +08:00
|
|
|
return false;
|
2017-10-15 11:31:44 +08:00
|
|
|
}
|
|
|
|
|
2018-06-03 01:02:20 +08:00
|
|
|
log.info(`Updating option ${name} to ${value}`);
|
|
|
|
|
2018-04-02 09:27:46 +08:00
|
|
|
await optionService.setOption(name, value);
|
2018-07-23 04:21:16 +08:00
|
|
|
|
|
|
|
return true;
|
2018-03-31 01:56:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2018-04-02 08:33:10 +08:00
|
|
|
getOptions,
|
2018-07-23 04:21:16 +08:00
|
|
|
updateOption,
|
|
|
|
updateOptions
|
2018-03-31 01:56:46 +08:00
|
|
|
};
|