mirror of
https://github.com/zadam/trilium.git
synced 2025-01-29 10:28:02 +08:00
40 lines
No EOL
1.2 KiB
JavaScript
40 lines
No EOL
1.2 KiB
JavaScript
const sql = require('./sql');
|
|
const utils = require('./utils');
|
|
const sync_table = require('./sync_table');
|
|
|
|
const SYNCED_OPTIONS = [ 'username', 'password_verification_hash', 'encrypted_data_key', 'protected_session_timeout',
|
|
'history_snapshot_time_interval' ];
|
|
|
|
async function getOption(optName) {
|
|
const row = await sql.getSingleResultOrNull("SELECT opt_value FROM options WHERE opt_name = ?", [optName]);
|
|
|
|
if (!row) {
|
|
throw new Error("Option " + optName + " doesn't exist");
|
|
}
|
|
|
|
return row['opt_value'];
|
|
}
|
|
|
|
async function setOption(optName, optValue) {
|
|
if (SYNCED_OPTIONS.includes(optName)) {
|
|
await sync_table.addOptionsSync(optName);
|
|
}
|
|
|
|
await sql.execute("UPDATE options SET opt_value = ?, date_modified = ? WHERE opt_name = ?",
|
|
[optValue, utils.nowTimestamp(), optName]);
|
|
}
|
|
|
|
sql.dbReady.then(async () => {
|
|
if (!await getOption('document_id') || !await getOption('document_secret')) {
|
|
await sql.doInTransaction(async () => {
|
|
await setOption('document_id', utils.randomSecureToken(16));
|
|
await setOption('document_secret', utils.randomSecureToken(16));
|
|
});
|
|
}
|
|
});
|
|
|
|
module.exports = {
|
|
getOption,
|
|
setOption,
|
|
SYNCED_OPTIONS
|
|
}; |