trilium/src/routes/api/options.js

29 lines
768 B
JavaScript
Raw Normal View History

2017-10-22 09:10:33 +08:00
"use strict";
2017-10-16 07:47:05 +08:00
const sql = require('../../services/sql');
const optionService = require('../../services/options');
// options allowed to be updated directly in options dialog
const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval'];
2018-04-02 08:33:10 +08:00
async function getOptions() {
const options = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
+ ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS);
return options;
}
async function updateOption(req) {
2018-04-02 08:33:10 +08:00
const {name, value} = req.params;
2018-04-02 08:33:10 +08:00
if (!ALLOWED_OPTIONS.includes(name)) {
return [400, "not allowed option to set"];
}
await optionService.setOption(name, value);
}
module.exports = {
2018-04-02 08:33:10 +08:00
getOptions,
updateOption
};