option names now follow camelCase

This commit is contained in:
azivner 2018-04-02 21:47:46 -04:00
parent 429d3f518e
commit c6c76ba360
26 changed files with 77 additions and 63 deletions

View File

@ -0,0 +1,14 @@
UPDATE "options" SET "name" = 'passwordVerificationHash' WHERE "name" = 'password_verification_hash';
UPDATE "options" SET "name" = 'dbVersion' WHERE "name" = 'db_version';
UPDATE "options" SET "name" = 'passwordDerivedKeySalt' WHERE "name" = 'password_derived_key_salt';
UPDATE "options" SET "name" = 'documentId' WHERE "name" = 'document_id';
UPDATE "options" SET "name" = 'lastSyncedPull' WHERE "name" = 'last_synced_pull';
UPDATE "options" SET "name" = 'startNotePath' WHERE "name" = 'start_note_path';
UPDATE "options" SET "name" = 'lastSyncedPush' WHERE "name" = 'last_synced_push';
UPDATE "options" SET "name" = 'documentSecret' WHERE "name" = 'document_secret';
UPDATE "options" SET "name" = 'lastBackupDate' WHERE "name" = 'last_backup_date';
UPDATE "options" SET "name" = 'noteRevisionSnapshotTimeInterval' WHERE "name" = 'note_revision_snapshot_time_interval';
UPDATE "options" SET "name" = 'protectedSessionTimeout' WHERE "name" = 'protected_session_timeout';
UPDATE "options" SET "name" = 'encryptedDataKey' WHERE "name" = 'encrypted_data_key';
UPDATE "options" SET "name" = 'encryptedDataKeyIv' WHERE "name" = 'encrypted_data_key_iv';
UPDATE "options" SET "name" = 'passwordVerificationSalt' WHERE "name" = 'password_verification_salt';

View File

@ -93,7 +93,7 @@ addTabHandler((function() {
addTabHandler((function() {
const $form = $("#protected-session-timeout-form");
const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds");
const optionName = 'protected_session_timeout';
const optionName = 'protectedSessionTimeout';
function optionsLoaded(options) {
$protectedSessionTimeout.val(options[optionName]);
@ -117,7 +117,7 @@ addTabHandler((function() {
addTabHandler((function () {
const $form = $("#note-revision-snapshot-time-interval-form");
const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds");
const optionName = 'note_revision_snapshot_time_interval';
const optionName = 'noteRevisionSnapshotTimeInterval';
function optionsLoaded(options) {
$timeInterval.val(options[optionName]);
@ -143,7 +143,7 @@ addTabHandler((async function () {
const appInfo = await server.get('app-info');
$appVersion.html(appInfo.app_version);
$dbVersion.html(appInfo.db_version);
$dbVersion.html(appInfo.dbVersion);
$buildDate.html(appInfo.build_date);
$buildRevision.html(appInfo.build_revision);
$buildRevision.attr('href', 'https://github.com/zadam/trilium/commit/' + appInfo.build_revision);

View File

@ -2,8 +2,8 @@ import server from './services/server.js';
$(document).ready(() => {
server.get('migration').then(result => {
const appDbVersion = result.app_db_version;
const dbVersion = result.db_version;
const appDbVersion = result.app_dbVersion;
const dbVersion = result.dbVersion;
if (appDbVersion === dbVersion) {
$("#up-to-date").show();
@ -26,7 +26,7 @@ $("#run-migration").click(async () => {
for (const migration of result.migrations) {
const row = $('<tr>')
.append($('<td>').html(migration.db_version))
.append($('<td>').html(migration.dbVersion))
.append($('<td>').html(migration.name))
.append($('<td>').html(migration.success ? 'Yes' : 'No'))
.append($('<td>').html(migration.success ? 'N/A' : migration.error));

View File

@ -6,7 +6,7 @@ let protectedSessionTimeout = null;
let protectedSessionId = null;
$(document).ready(() => {
server.get('options').then(options => protectedSessionTimeout = options.protected_session_timeout);
server.get('options').then(options => protectedSessionTimeout = options.protectedSessionTimeout);
});
setInterval(() => {

View File

@ -369,7 +369,7 @@ function getNotePathFromAddress() {
async function loadTree() {
const resp = await server.get('tree');
startNotePath = resp.start_note_path;
startNotePath = resp.startNotePath;
if (document.location.hash) {
startNotePath = getNotePathFromAddress();

View File

@ -21,11 +21,11 @@ async function loginSync(req) {
const dbVersion = req.body.dbVersion;
if (dbVersion !== appInfo.db_version) {
return [400, { message: 'Non-matching db versions, local is version ' + appInfo.db_version }];
if (dbVersion !== appInfo.dbVersion) {
return [400, { message: 'Non-matching db versions, local is version ' + appInfo.dbVersion }];
}
const documentSecret = await options.getOption('document_secret');
const documentSecret = await options.getOption('documentSecret');
const expectedHash = utils.hmac(documentSecret, timestampStr);
const givenHash = req.body.hash;

View File

@ -6,8 +6,8 @@ const appInfo = require('../../services/app_info');
async function getMigrationInfo() {
return {
db_version: parseInt(await optionService.getOption('db_version')),
app_db_version: appInfo.db_version
dbVersion: parseInt(await optionService.getOption('dbVersion')),
app_dbVersion: appInfo.dbVersion
};
}

View File

@ -4,7 +4,7 @@ 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'];
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval'];
async function getOptions() {
const options = await sql.getMap("SELECT name, value FROM options WHERE name IN ("

View File

@ -33,7 +33,7 @@ async function addRecentNote(req) {
await recentNote.save();
await optionService.setOption('start_note_path', notePath);
await optionService.setOption('startNotePath', notePath);
return await getRecentNotes();
}

View File

@ -11,11 +11,11 @@ async function setup(req) {
await optionService.setOption('username', username);
await optionService.setOption('password_verification_salt', utils.randomSecureToken(32));
await optionService.setOption('password_derived_key_salt', utils.randomSecureToken(32));
await optionService.setOption('passwordVerificationSalt', utils.randomSecureToken(32));
await optionService.setOption('passwordDerivedKeySalt', utils.randomSecureToken(32));
const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password));
await optionService.setOption('password_verification_hash', passwordVerificationKey);
await optionService.setOption('passwordVerificationHash', passwordVerificationKey);
await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16));

View File

@ -26,8 +26,8 @@ async function fillSyncRows() {
}
async function forceFullSync() {
await optionService.setOption('last_synced_pull', 0);
await optionService.setOption('last_synced_push', 0);
await optionService.setOption('lastSyncedPull', 0);
await optionService.setOption('lastSyncedPush', 0);
log.info("Forcing full sync.");

View File

@ -51,7 +51,7 @@ async function getTree() {
});
return {
start_note_path: await optionService.getOption('start_note_path'),
startNotePath: await optionService.getOption('startNotePath'),
branches: branches,
notes: notes
};

View File

@ -33,7 +33,7 @@ async function login(req, res) {
}
async function verifyPassword(guessedPassword) {
const hashed_password = utils.fromBase64(await optionService.getOption('password_verification_hash'));
const hashed_password = utils.fromBase64(await optionService.getOption('passwordVerificationHash'));
const guess_hashed = await myScryptService.getVerificationHash(guessedPassword);

View File

@ -20,8 +20,8 @@ async function anonymize() {
await db.run("UPDATE note_revisions SET title = 'title', content = 'text'");
await db.run("UPDATE branches SET prefix = 'prefix' WHERE prefix IS NOT NULL");
await db.run(`UPDATE options SET value = 'anonymized' WHERE name IN
('document_secret', 'encrypted_data_key', 'password_verification_hash',
'password_verification_salt', 'password_derived_key_salt')`);
('documentSecret', 'encryptedDataKey', 'passwordVerificationHash',
'passwordVerificationSalt', 'passwordDerivedKeySalt')`);
await db.run("VACUUM");
await db.close();

View File

@ -7,7 +7,7 @@ const APP_DB_VERSION = 81;
module.exports = {
app_version: packageJson.version,
db_version: APP_DB_VERSION,
dbVersion: APP_DB_VERSION,
build_date: build.build_date,
build_revision: build.build_revision
};

View File

@ -11,7 +11,7 @@ const cls = require('./cls');
async function regularBackup() {
const now = new Date();
const lastBackupDate = dateUtils.parseDateTime(await optionService.getOption('last_backup_date'));
const lastBackupDate = dateUtils.parseDateTime(await optionService.getOption('lastBackupDate'));
console.log(lastBackupDate);
@ -32,7 +32,7 @@ async function backupNow() {
log.info("Created backup at " + backupFile);
await optionService.setOption('last_backup_date', dateUtils.nowDate());
await optionService.setOption('lastBackupDate', dateUtils.nowDate());
});
}

View File

@ -20,7 +20,7 @@ async function changePassword(currentPassword, newPassword) {
await sql.doInTransaction(async () => {
await passwordEncryptionService.setDataKey(newPassword, decryptedDataKey);
await optionService.setOption('password_verification_hash', newPasswordVerificationKey);
await optionService.setOption('passwordVerificationHash', newPasswordVerificationKey);
});
return {

View File

@ -66,7 +66,7 @@ async function sendMessageToAllClients(message) {
async function sendPing(client, lastSentSyncId) {
const syncData = await sql.getRows("SELECT * FROM sync WHERE id > ?", [lastSentSyncId]);
const lastSyncedPush = await optionService.getOption('last_synced_push');
const lastSyncedPush = await optionService.getOption('lastSyncedPush');
const changesToPushCount = await sql.getValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);

View File

@ -12,7 +12,7 @@ async function migrate() {
// backup before attempting migration
await backupService.backupNow();
const currentDbVersion = parseInt(await optionService.getOption('db_version'));
const currentDbVersion = parseInt(await optionService.getOption('dbVersion'));
fs.readdirSync(resourceDir.MIGRATIONS_DIR).forEach(file => {
const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)/);
@ -63,7 +63,7 @@ async function migrate() {
throw new Error("Unknown migration type " + mig.type);
}
await optionService.setOption("db_version", mig.dbVersion);
await optionService.setOption("dbVersion", mig.dbVersion);
});

View File

@ -4,13 +4,13 @@ const optionService = require('./options');
const scrypt = require('scrypt');
async function getVerificationHash(password) {
const salt = await optionService.getOption('password_verification_salt');
const salt = await optionService.getOption('passwordVerificationSalt');
return getScryptHash(password, salt);
}
async function getPasswordDerivedKey(password) {
const salt = await optionService.getOption('password_derived_key_salt');
const salt = await optionService.getOption('passwordDerivedKeySalt');
return getScryptHash(password, salt);
}

View File

@ -165,7 +165,7 @@ async function saveNoteRevision(note) {
const labelsMap = await note.getLabelMap();
const now = new Date();
const noteRevisionSnapshotTimeInterval = parseInt(await optionService.getOption('note_revision_snapshot_time_interval'));
const noteRevisionSnapshotTimeInterval = parseInt(await optionService.getOption('noteRevisionSnapshotTimeInterval'));
const revisionCutoff = dateUtils.dateStr(new Date(now.getTime() - noteRevisionSnapshotTimeInterval * 1000));

View File

@ -47,24 +47,24 @@ async function createOption(name, value, isSynced) {
}
async function initOptions(startNotePath) {
await createOption('document_id', utils.randomSecureToken(16), false);
await createOption('document_secret', utils.randomSecureToken(16), false);
await createOption('documentId', utils.randomSecureToken(16), false);
await createOption('documentSecret', utils.randomSecureToken(16), false);
await createOption('username', '', true);
await createOption('password_verification_hash', '', true);
await createOption('password_verification_salt', '', true);
await createOption('password_derived_key_salt', '', true);
await createOption('encrypted_data_key', '', true);
await createOption('encrypted_data_key_iv', '', true);
await createOption('passwordVerificationHash', '', true);
await createOption('passwordVerificationSalt', '', true);
await createOption('passwordDerivedKeySalt', '', true);
await createOption('encryptedDataKey', '', true);
await createOption('encryptedDataKey_iv', '', true);
await createOption('start_note_path', startNotePath, false);
await createOption('protected_session_timeout', 600, true);
await createOption('note_revision_snapshot_time_interval', 600, true);
await createOption('last_backup_date', dateUtils.nowDate(), false);
await createOption('db_version', appInfo.db_version, false);
await createOption('startNotePath', startNotePath, false);
await createOption('protectedSessionTimeout', 600, true);
await createOption('noteRevisionSnapshotTimeInterval', 600, true);
await createOption('lastBackupDate', dateUtils.nowDate(), false);
await createOption('dbVersion', appInfo.dbVersion, false);
await createOption('last_synced_pull', appInfo.db_version, false);
await createOption('last_synced_push', 0, false);
await createOption('lastSyncedPull', appInfo.dbVersion, false);
await createOption('lastSyncedPush', 0, false);
}
module.exports = {

View File

@ -6,7 +6,7 @@ const dataEncryptionService = require('./data_encryption');
async function verifyPassword(password) {
const givenPasswordHash = utils.toBase64(await myScryptService.getVerificationHash(password));
const dbPasswordHash = await optionService.getOption('password_verification_hash');
const dbPasswordHash = await optionService.getOption('passwordVerificationHash');
return givenPasswordHash === dbPasswordHash;
}
@ -16,20 +16,20 @@ async function setDataKey(password, plainTextDataKey) {
const encryptedDataKeyIv = utils.randomString(16);
await optionService.setOption('encrypted_data_key_iv', encryptedDataKeyIv);
await optionService.setOption('encryptedDataKeyIv', encryptedDataKeyIv);
const buffer = Buffer.from(plainTextDataKey);
const newEncryptedDataKey = dataEncryptionService.encrypt(passwordDerivedKey, encryptedDataKeyIv, buffer);
await optionService.setOption('encrypted_data_key', newEncryptedDataKey);
await optionService.setOption('encryptedDataKey', newEncryptedDataKey);
}
async function getDataKey(password) {
const passwordDerivedKey = await myScryptService.getPasswordDerivedKey(password);
const encryptedDataKeyIv = await optionService.getOption('encrypted_data_key_iv');
const encryptedDataKey = await optionService.getOption('encrypted_data_key');
const encryptedDataKeyIv = await optionService.getOption('encryptedDataKeyIv');
const encryptedDataKey = await optionService.getOption('encryptedDataKey');
const decryptedDataKey = dataEncryptionService.decrypt(passwordDerivedKey, encryptedDataKeyIv, encryptedDataKey);

View File

@ -76,12 +76,12 @@ function setDbReadyAsResolved() {
}
async function isDbUpToDate() {
const dbVersion = parseInt(await sql.getValue("SELECT value FROM options WHERE name = 'db_version'"));
const dbVersion = parseInt(await sql.getValue("SELECT value FROM options WHERE name = 'dbVersion'"));
const upToDate = dbVersion >= appInfo.db_version;
const upToDate = dbVersion >= appInfo.dbVersion;
if (!upToDate) {
log.info("App db version is " + appInfo.db_version + ", while db version is " + dbVersion + ". Migration needed.");
log.info("App db version is " + appInfo.dbVersion + ", while db version is " + dbVersion + ". Migration needed.");
}
return upToDate;

View File

@ -71,14 +71,14 @@ async function sync() {
async function login() {
const timestamp = dateUtils.nowDate();
const documentSecret = await optionService.getOption('document_secret');
const documentSecret = await optionService.getOption('documentSecret');
const hash = utils.hmac(documentSecret, timestamp);
const syncContext = { cookieJar: rp.jar() };
const resp = await syncRequest(syncContext, 'POST', '/api/login/sync', {
timestamp: timestamp,
dbVersion: appInfo.db_version,
dbVersion: appInfo.dbVersion,
hash: hash
});
@ -92,11 +92,11 @@ async function login() {
}
async function getLastSyncedPull() {
return parseInt(await optionService.getOption('last_synced_pull'));
return parseInt(await optionService.getOption('lastSyncedPull'));
}
async function setLastSyncedPull(syncId) {
await optionService.setOption('last_synced_pull', syncId);
await optionService.setOption('lastSyncedPull', syncId);
}
async function pullSync(syncContext) {
@ -163,11 +163,11 @@ async function pullSync(syncContext) {
}
async function getLastSyncedPush() {
return parseInt(await optionService.getOption('last_synced_push'));
return parseInt(await optionService.getOption('lastSyncedPush'));
}
async function setLastSyncedPush(lastSyncedPush) {
await optionService.setOption('last_synced_push', lastSyncedPush);
await optionService.setOption('lastSyncedPush', lastSyncedPush);
}
async function pushSync(syncContext) {

View File

@ -56,7 +56,7 @@ async function addEntitySync(entityName, entityId, sourceId) {
if (!syncSetup.isSyncSetup) {
// this is because the "server" instances shouldn't have outstanding pushes
// useful when you fork the DB for new "client" instance, it won't try to sync the whole DB
await sql.execute("UPDATE options SET value = (SELECT MAX(id) FROM sync) WHERE name IN('last_synced_push', 'last_synced_pull')");
await sql.execute("UPDATE options SET value = (SELECT MAX(id) FROM sync) WHERE name IN('lastSyncedPush', 'lastSyncedPull')");
}
}