trilium/src/routes/api/options.js

29 lines
762 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
2018-04-03 09:47:46 +08:00
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval'];
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
};