mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	option names now follow camelCase
This commit is contained in:
		
							
								
								
									
										14
									
								
								db/migrations/0082__camelCase_options.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								db/migrations/0082__camelCase_options.sql
									
									
									
									
									
										Normal 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'; | ||||||
| @@ -93,7 +93,7 @@ addTabHandler((function() { | |||||||
| addTabHandler((function() { | addTabHandler((function() { | ||||||
|     const $form = $("#protected-session-timeout-form"); |     const $form = $("#protected-session-timeout-form"); | ||||||
|     const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds"); |     const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds"); | ||||||
|     const optionName = 'protected_session_timeout'; |     const optionName = 'protectedSessionTimeout'; | ||||||
|  |  | ||||||
|     function optionsLoaded(options) { |     function optionsLoaded(options) { | ||||||
|         $protectedSessionTimeout.val(options[optionName]); |         $protectedSessionTimeout.val(options[optionName]); | ||||||
| @@ -117,7 +117,7 @@ addTabHandler((function() { | |||||||
| addTabHandler((function () { | addTabHandler((function () { | ||||||
|     const $form = $("#note-revision-snapshot-time-interval-form"); |     const $form = $("#note-revision-snapshot-time-interval-form"); | ||||||
|     const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds"); |     const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds"); | ||||||
|     const optionName = 'note_revision_snapshot_time_interval'; |     const optionName = 'noteRevisionSnapshotTimeInterval'; | ||||||
|  |  | ||||||
|     function optionsLoaded(options) { |     function optionsLoaded(options) { | ||||||
|         $timeInterval.val(options[optionName]); |         $timeInterval.val(options[optionName]); | ||||||
| @@ -143,7 +143,7 @@ addTabHandler((async function () { | |||||||
|     const appInfo = await server.get('app-info'); |     const appInfo = await server.get('app-info'); | ||||||
|  |  | ||||||
|     $appVersion.html(appInfo.app_version); |     $appVersion.html(appInfo.app_version); | ||||||
|     $dbVersion.html(appInfo.db_version); |     $dbVersion.html(appInfo.dbVersion); | ||||||
|     $buildDate.html(appInfo.build_date); |     $buildDate.html(appInfo.build_date); | ||||||
|     $buildRevision.html(appInfo.build_revision); |     $buildRevision.html(appInfo.build_revision); | ||||||
|     $buildRevision.attr('href', 'https://github.com/zadam/trilium/commit/' + appInfo.build_revision); |     $buildRevision.attr('href', 'https://github.com/zadam/trilium/commit/' + appInfo.build_revision); | ||||||
|   | |||||||
| @@ -2,8 +2,8 @@ import server from './services/server.js'; | |||||||
|  |  | ||||||
| $(document).ready(() => { | $(document).ready(() => { | ||||||
|     server.get('migration').then(result => { |     server.get('migration').then(result => { | ||||||
|         const appDbVersion = result.app_db_version; |         const appDbVersion = result.app_dbVersion; | ||||||
|         const dbVersion = result.db_version; |         const dbVersion = result.dbVersion; | ||||||
|  |  | ||||||
|         if (appDbVersion === dbVersion) { |         if (appDbVersion === dbVersion) { | ||||||
|             $("#up-to-date").show(); |             $("#up-to-date").show(); | ||||||
| @@ -26,7 +26,7 @@ $("#run-migration").click(async () => { | |||||||
|  |  | ||||||
|     for (const migration of result.migrations) { |     for (const migration of result.migrations) { | ||||||
|         const row = $('<tr>') |         const row = $('<tr>') | ||||||
|             .append($('<td>').html(migration.db_version)) |             .append($('<td>').html(migration.dbVersion)) | ||||||
|             .append($('<td>').html(migration.name)) |             .append($('<td>').html(migration.name)) | ||||||
|             .append($('<td>').html(migration.success ? 'Yes' : 'No')) |             .append($('<td>').html(migration.success ? 'Yes' : 'No')) | ||||||
|             .append($('<td>').html(migration.success ? 'N/A' : migration.error)); |             .append($('<td>').html(migration.success ? 'N/A' : migration.error)); | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ let protectedSessionTimeout = null; | |||||||
| let protectedSessionId = null; | let protectedSessionId = null; | ||||||
|  |  | ||||||
| $(document).ready(() => { | $(document).ready(() => { | ||||||
|     server.get('options').then(options => protectedSessionTimeout = options.protected_session_timeout); |     server.get('options').then(options => protectedSessionTimeout = options.protectedSessionTimeout); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| setInterval(() => { | setInterval(() => { | ||||||
|   | |||||||
| @@ -369,7 +369,7 @@ function getNotePathFromAddress() { | |||||||
|  |  | ||||||
| async function loadTree() { | async function loadTree() { | ||||||
|     const resp = await server.get('tree'); |     const resp = await server.get('tree'); | ||||||
|     startNotePath = resp.start_note_path; |     startNotePath = resp.startNotePath; | ||||||
|  |  | ||||||
|     if (document.location.hash) { |     if (document.location.hash) { | ||||||
|         startNotePath = getNotePathFromAddress(); |         startNotePath = getNotePathFromAddress(); | ||||||
|   | |||||||
| @@ -21,11 +21,11 @@ async function loginSync(req) { | |||||||
|  |  | ||||||
|     const dbVersion = req.body.dbVersion; |     const dbVersion = req.body.dbVersion; | ||||||
|  |  | ||||||
|     if (dbVersion !== appInfo.db_version) { |     if (dbVersion !== appInfo.dbVersion) { | ||||||
|         return [400, { message: 'Non-matching db versions, local is version ' + appInfo.db_version }]; |         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 expectedHash = utils.hmac(documentSecret, timestampStr); | ||||||
|  |  | ||||||
|     const givenHash = req.body.hash; |     const givenHash = req.body.hash; | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ const appInfo = require('../../services/app_info'); | |||||||
|  |  | ||||||
| async function getMigrationInfo() { | async function getMigrationInfo() { | ||||||
|     return { |     return { | ||||||
|         db_version: parseInt(await optionService.getOption('db_version')), |         dbVersion: parseInt(await optionService.getOption('dbVersion')), | ||||||
|         app_db_version: appInfo.db_version |         app_dbVersion: appInfo.dbVersion | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ const sql = require('../../services/sql'); | |||||||
| const optionService = require('../../services/options'); | const optionService = require('../../services/options'); | ||||||
|  |  | ||||||
| // options allowed to be updated directly in options dialog | // 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() { | async function getOptions() { | ||||||
|     const options = await sql.getMap("SELECT name, value FROM options WHERE name IN (" |     const options = await sql.getMap("SELECT name, value FROM options WHERE name IN (" | ||||||
|   | |||||||
| @@ -33,7 +33,7 @@ async function addRecentNote(req) { | |||||||
|  |  | ||||||
|     await recentNote.save(); |     await recentNote.save(); | ||||||
|  |  | ||||||
|     await optionService.setOption('start_note_path', notePath); |     await optionService.setOption('startNotePath', notePath); | ||||||
|  |  | ||||||
|     return await getRecentNotes(); |     return await getRecentNotes(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,11 +11,11 @@ async function setup(req) { | |||||||
|  |  | ||||||
|     await optionService.setOption('username', username); |     await optionService.setOption('username', username); | ||||||
|  |  | ||||||
|     await optionService.setOption('password_verification_salt', utils.randomSecureToken(32)); |     await optionService.setOption('passwordVerificationSalt', utils.randomSecureToken(32)); | ||||||
|     await optionService.setOption('password_derived_key_salt', utils.randomSecureToken(32)); |     await optionService.setOption('passwordDerivedKeySalt', utils.randomSecureToken(32)); | ||||||
|  |  | ||||||
|     const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password)); |     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)); |     await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16)); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -26,8 +26,8 @@ async function fillSyncRows() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function forceFullSync() { | async function forceFullSync() { | ||||||
|     await optionService.setOption('last_synced_pull', 0); |     await optionService.setOption('lastSyncedPull', 0); | ||||||
|     await optionService.setOption('last_synced_push', 0); |     await optionService.setOption('lastSyncedPush', 0); | ||||||
|  |  | ||||||
|     log.info("Forcing full sync."); |     log.info("Forcing full sync."); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -51,7 +51,7 @@ async function getTree() { | |||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|         start_note_path: await optionService.getOption('start_note_path'), |         startNotePath: await optionService.getOption('startNotePath'), | ||||||
|         branches: branches, |         branches: branches, | ||||||
|         notes: notes |         notes: notes | ||||||
|     }; |     }; | ||||||
|   | |||||||
| @@ -33,7 +33,7 @@ async function login(req, res) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function verifyPassword(guessedPassword) { | 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); |     const guess_hashed = await myScryptService.getVerificationHash(guessedPassword); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,8 +20,8 @@ async function anonymize() { | |||||||
|     await db.run("UPDATE note_revisions SET title = 'title', content = 'text'"); |     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 branches SET prefix = 'prefix' WHERE prefix IS NOT NULL"); | ||||||
|     await db.run(`UPDATE options SET value = 'anonymized' WHERE name IN  |     await db.run(`UPDATE options SET value = 'anonymized' WHERE name IN  | ||||||
|                     ('document_secret', 'encrypted_data_key', 'password_verification_hash',  |                     ('documentSecret', 'encryptedDataKey', 'passwordVerificationHash',  | ||||||
|                      'password_verification_salt', 'password_derived_key_salt')`); |                      'passwordVerificationSalt', 'passwordDerivedKeySalt')`); | ||||||
|     await db.run("VACUUM"); |     await db.run("VACUUM"); | ||||||
|  |  | ||||||
|     await db.close(); |     await db.close(); | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ const APP_DB_VERSION = 81; | |||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     app_version: packageJson.version, |     app_version: packageJson.version, | ||||||
|     db_version: APP_DB_VERSION, |     dbVersion: APP_DB_VERSION, | ||||||
|     build_date: build.build_date, |     build_date: build.build_date, | ||||||
|     build_revision: build.build_revision |     build_revision: build.build_revision | ||||||
| }; | }; | ||||||
| @@ -11,7 +11,7 @@ const cls = require('./cls'); | |||||||
|  |  | ||||||
| async function regularBackup() { | async function regularBackup() { | ||||||
|     const now = new Date(); |     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); |     console.log(lastBackupDate); | ||||||
|  |  | ||||||
| @@ -32,7 +32,7 @@ async function backupNow() { | |||||||
|  |  | ||||||
|         log.info("Created backup at " + backupFile); |         log.info("Created backup at " + backupFile); | ||||||
|  |  | ||||||
|         await optionService.setOption('last_backup_date', dateUtils.nowDate()); |         await optionService.setOption('lastBackupDate', dateUtils.nowDate()); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,7 +20,7 @@ async function changePassword(currentPassword, newPassword) { | |||||||
|     await sql.doInTransaction(async () => { |     await sql.doInTransaction(async () => { | ||||||
|         await passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); |         await passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); | ||||||
|  |  | ||||||
|         await optionService.setOption('password_verification_hash', newPasswordVerificationKey); |         await optionService.setOption('passwordVerificationHash', newPasswordVerificationKey); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|   | |||||||
| @@ -66,7 +66,7 @@ async function sendMessageToAllClients(message) { | |||||||
| async function sendPing(client, lastSentSyncId) { | async function sendPing(client, lastSentSyncId) { | ||||||
|     const syncData = await sql.getRows("SELECT * FROM sync WHERE id > ?", [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]); |     const changesToPushCount = await sql.getValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ async function migrate() { | |||||||
|     // backup before attempting migration |     // backup before attempting migration | ||||||
|     await backupService.backupNow(); |     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 => { |     fs.readdirSync(resourceDir.MIGRATIONS_DIR).forEach(file => { | ||||||
|         const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)/); |         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); |                     throw new Error("Unknown migration type " + mig.type); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 await optionService.setOption("db_version", mig.dbVersion); |                 await optionService.setOption("dbVersion", mig.dbVersion); | ||||||
|  |  | ||||||
|             }); |             }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,13 +4,13 @@ const optionService = require('./options'); | |||||||
| const scrypt = require('scrypt'); | const scrypt = require('scrypt'); | ||||||
|  |  | ||||||
| async function getVerificationHash(password) { | async function getVerificationHash(password) { | ||||||
|     const salt = await optionService.getOption('password_verification_salt'); |     const salt = await optionService.getOption('passwordVerificationSalt'); | ||||||
|  |  | ||||||
|     return getScryptHash(password, salt); |     return getScryptHash(password, salt); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getPasswordDerivedKey(password) { | async function getPasswordDerivedKey(password) { | ||||||
|     const salt = await optionService.getOption('password_derived_key_salt'); |     const salt = await optionService.getOption('passwordDerivedKeySalt'); | ||||||
|  |  | ||||||
|     return getScryptHash(password, salt); |     return getScryptHash(password, salt); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -165,7 +165,7 @@ async function saveNoteRevision(note) { | |||||||
|     const labelsMap = await note.getLabelMap(); |     const labelsMap = await note.getLabelMap(); | ||||||
|  |  | ||||||
|     const now = new Date(); |     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)); |     const revisionCutoff = dateUtils.dateStr(new Date(now.getTime() - noteRevisionSnapshotTimeInterval * 1000)); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -47,24 +47,24 @@ async function createOption(name, value, isSynced) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function initOptions(startNotePath) { | async function initOptions(startNotePath) { | ||||||
|     await createOption('document_id', utils.randomSecureToken(16), false); |     await createOption('documentId', utils.randomSecureToken(16), false); | ||||||
|     await createOption('document_secret', utils.randomSecureToken(16), false); |     await createOption('documentSecret', utils.randomSecureToken(16), false); | ||||||
|  |  | ||||||
|     await createOption('username', '', true); |     await createOption('username', '', true); | ||||||
|     await createOption('password_verification_hash', '', true); |     await createOption('passwordVerificationHash', '', true); | ||||||
|     await createOption('password_verification_salt', '', true); |     await createOption('passwordVerificationSalt', '', true); | ||||||
|     await createOption('password_derived_key_salt', '', true); |     await createOption('passwordDerivedKeySalt', '', true); | ||||||
|     await createOption('encrypted_data_key', '', true); |     await createOption('encryptedDataKey', '', true); | ||||||
|     await createOption('encrypted_data_key_iv', '', true); |     await createOption('encryptedDataKey_iv', '', true); | ||||||
|  |  | ||||||
|     await createOption('start_note_path', startNotePath, false); |     await createOption('startNotePath', startNotePath, false); | ||||||
|     await createOption('protected_session_timeout', 600, true); |     await createOption('protectedSessionTimeout', 600, true); | ||||||
|     await createOption('note_revision_snapshot_time_interval', 600, true); |     await createOption('noteRevisionSnapshotTimeInterval', 600, true); | ||||||
|     await createOption('last_backup_date', dateUtils.nowDate(), false); |     await createOption('lastBackupDate', dateUtils.nowDate(), false); | ||||||
|     await createOption('db_version', appInfo.db_version, false); |     await createOption('dbVersion', appInfo.dbVersion, false); | ||||||
|  |  | ||||||
|     await createOption('last_synced_pull', appInfo.db_version, false); |     await createOption('lastSyncedPull', appInfo.dbVersion, false); | ||||||
|     await createOption('last_synced_push', 0, false); |     await createOption('lastSyncedPush', 0, false); | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ const dataEncryptionService = require('./data_encryption'); | |||||||
| async function verifyPassword(password) { | async function verifyPassword(password) { | ||||||
|     const givenPasswordHash = utils.toBase64(await myScryptService.getVerificationHash(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; |     return givenPasswordHash === dbPasswordHash; | ||||||
| } | } | ||||||
| @@ -16,20 +16,20 @@ async function setDataKey(password, plainTextDataKey) { | |||||||
|  |  | ||||||
|     const encryptedDataKeyIv = utils.randomString(16); |     const encryptedDataKeyIv = utils.randomString(16); | ||||||
|  |  | ||||||
|     await optionService.setOption('encrypted_data_key_iv', encryptedDataKeyIv); |     await optionService.setOption('encryptedDataKeyIv', encryptedDataKeyIv); | ||||||
|  |  | ||||||
|     const buffer = Buffer.from(plainTextDataKey); |     const buffer = Buffer.from(plainTextDataKey); | ||||||
|  |  | ||||||
|     const newEncryptedDataKey = dataEncryptionService.encrypt(passwordDerivedKey, encryptedDataKeyIv, buffer); |     const newEncryptedDataKey = dataEncryptionService.encrypt(passwordDerivedKey, encryptedDataKeyIv, buffer); | ||||||
|  |  | ||||||
|     await optionService.setOption('encrypted_data_key', newEncryptedDataKey); |     await optionService.setOption('encryptedDataKey', newEncryptedDataKey); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getDataKey(password) { | async function getDataKey(password) { | ||||||
|     const passwordDerivedKey = await myScryptService.getPasswordDerivedKey(password); |     const passwordDerivedKey = await myScryptService.getPasswordDerivedKey(password); | ||||||
|  |  | ||||||
|     const encryptedDataKeyIv = await optionService.getOption('encrypted_data_key_iv'); |     const encryptedDataKeyIv = await optionService.getOption('encryptedDataKeyIv'); | ||||||
|     const encryptedDataKey = await optionService.getOption('encrypted_data_key'); |     const encryptedDataKey = await optionService.getOption('encryptedDataKey'); | ||||||
|  |  | ||||||
|     const decryptedDataKey = dataEncryptionService.decrypt(passwordDerivedKey, encryptedDataKeyIv, encryptedDataKey); |     const decryptedDataKey = dataEncryptionService.decrypt(passwordDerivedKey, encryptedDataKeyIv, encryptedDataKey); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -76,12 +76,12 @@ function setDbReadyAsResolved() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function isDbUpToDate() { | 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) { |     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; |     return upToDate; | ||||||
|   | |||||||
| @@ -71,14 +71,14 @@ async function sync() { | |||||||
| async function login() { | async function login() { | ||||||
|     const timestamp = dateUtils.nowDate(); |     const timestamp = dateUtils.nowDate(); | ||||||
|  |  | ||||||
|     const documentSecret = await optionService.getOption('document_secret'); |     const documentSecret = await optionService.getOption('documentSecret'); | ||||||
|     const hash = utils.hmac(documentSecret, timestamp); |     const hash = utils.hmac(documentSecret, timestamp); | ||||||
|  |  | ||||||
|     const syncContext = { cookieJar: rp.jar() }; |     const syncContext = { cookieJar: rp.jar() }; | ||||||
|  |  | ||||||
|     const resp = await syncRequest(syncContext, 'POST', '/api/login/sync', { |     const resp = await syncRequest(syncContext, 'POST', '/api/login/sync', { | ||||||
|         timestamp: timestamp, |         timestamp: timestamp, | ||||||
|         dbVersion: appInfo.db_version, |         dbVersion: appInfo.dbVersion, | ||||||
|         hash: hash |         hash: hash | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
| @@ -92,11 +92,11 @@ async function login() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function getLastSyncedPull() { | async function getLastSyncedPull() { | ||||||
|     return parseInt(await optionService.getOption('last_synced_pull')); |     return parseInt(await optionService.getOption('lastSyncedPull')); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function setLastSyncedPull(syncId) { | async function setLastSyncedPull(syncId) { | ||||||
|     await optionService.setOption('last_synced_pull', syncId); |     await optionService.setOption('lastSyncedPull', syncId); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function pullSync(syncContext) { | async function pullSync(syncContext) { | ||||||
| @@ -163,11 +163,11 @@ async function pullSync(syncContext) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function getLastSyncedPush() { | async function getLastSyncedPush() { | ||||||
|     return parseInt(await optionService.getOption('last_synced_push')); |     return parseInt(await optionService.getOption('lastSyncedPush')); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function setLastSyncedPush(lastSyncedPush) { | async function setLastSyncedPush(lastSyncedPush) { | ||||||
|     await optionService.setOption('last_synced_push', lastSyncedPush); |     await optionService.setOption('lastSyncedPush', lastSyncedPush); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function pushSync(syncContext) { | async function pushSync(syncContext) { | ||||||
|   | |||||||
| @@ -56,7 +56,7 @@ async function addEntitySync(entityName, entityId, sourceId) { | |||||||
|     if (!syncSetup.isSyncSetup) { |     if (!syncSetup.isSyncSetup) { | ||||||
|         // this is because the "server" instances shouldn't have outstanding pushes |         // 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 |         // 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')"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user