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');
|
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-03-26 08:52:38 +08:00
|
|
|
const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval'];
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-04-02 08:33:10 +08:00
|
|
|
async function getOptions() {
|
2018-04-02 05:41:28 +08:00
|
|
|
const options = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
|
2017-11-05 07:57:40 +08:00
|
|
|
+ ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS);
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-04-02 05:41:28 +08:00
|
|
|
return 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-04-02 08:33:10 +08:00
|
|
|
if (!ALLOWED_OPTIONS.includes(name)) {
|
2018-03-31 01:56:46 +08:00
|
|
|
return [400, "not allowed option to set"];
|
2017-10-15 11:31:44 +08:00
|
|
|
}
|
|
|
|
|
2018-04-02 09:27:46 +08:00
|
|
|
await optionService.setOption(name, value);
|
2018-03-31 01:56:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2018-04-02 08:33:10 +08:00
|
|
|
getOptions,
|
2018-04-02 05:41:28 +08:00
|
|
|
updateOption
|
2018-03-31 01:56:46 +08:00
|
|
|
};
|