trilium/src/routes/api/options.js

34 lines
902 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');
2017-11-03 08:48:02 +08:00
const options = require('../../services/options');
// options allowed to be updated directly in options dialog
const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval'];
async function getAllOptions() {
return await sql.getMap("SELECT name, value FROM options");
}
async function getAllowedOptions() {
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) {
2017-10-25 10:58:59 +08:00
const body = req.body;
if (!ALLOWED_OPTIONS.includes(body['name'])) {
return [400, "not allowed option to set"];
}
await options.setOption(body['name'], body['value']);
}
module.exports = {
getAllowedOptions,
getAllOptions,
updateOption
};