mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix init of synced options in new database
This commit is contained in:
parent
a42bbba0e5
commit
7f9a8a55ca
@ -64,7 +64,7 @@ async function getTree() {
|
|||||||
const relations = await getRelations(noteIds);
|
const relations = await getRelations(noteIds);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startNotePath: await optionService.getOption('startNotePath'),
|
startNotePath: (await optionService.getOption('startNotePath')) || 'root',
|
||||||
branches,
|
branches,
|
||||||
notes,
|
notes,
|
||||||
relations
|
relations
|
||||||
|
@ -68,9 +68,18 @@ async function runSyncRowChecks(table, key, errorList) {
|
|||||||
${table}
|
${table}
|
||||||
LEFT JOIN sync ON sync.entityName = '${table}' AND entityId = ${key}
|
LEFT JOIN sync ON sync.entityName = '${table}' AND entityId = ${key}
|
||||||
WHERE
|
WHERE
|
||||||
sync.id IS NULL`,
|
sync.id IS NULL AND ` + (table === 'options' ? 'isSynced = 1' : '1'),
|
||||||
`Missing sync records for ${key} in table ${table}`, errorList);
|
`Missing sync records for ${key} in table ${table}`, errorList);
|
||||||
|
|
||||||
|
console.log(`
|
||||||
|
SELECT
|
||||||
|
${key}
|
||||||
|
FROM
|
||||||
|
${table}
|
||||||
|
LEFT JOIN sync ON sync.entityName = '${table}' AND entityId = ${key}
|
||||||
|
WHERE
|
||||||
|
sync.id IS NULL AND ` + (table === 'options' ? 'isSynced = 1' : '1'));
|
||||||
|
|
||||||
await runCheck(`
|
await runCheck(`
|
||||||
SELECT
|
SELECT
|
||||||
entityId
|
entityId
|
||||||
@ -224,6 +233,7 @@ async function runAllChecks() {
|
|||||||
await runSyncRowChecks("note_images", "noteImageId", errorList);
|
await runSyncRowChecks("note_images", "noteImageId", errorList);
|
||||||
await runSyncRowChecks("attributes", "attributeId", errorList);
|
await runSyncRowChecks("attributes", "attributeId", errorList);
|
||||||
await runSyncRowChecks("api_tokens", "apiTokenId", errorList);
|
await runSyncRowChecks("api_tokens", "apiTokenId", errorList);
|
||||||
|
await runSyncRowChecks("options", "name", errorList);
|
||||||
|
|
||||||
if (errorList.length === 0) {
|
if (errorList.length === 0) {
|
||||||
// we run this only if basic checks passed since this assumes basic data consistency
|
// we run this only if basic checks passed since this assumes basic data consistency
|
||||||
|
@ -11,22 +11,22 @@ async function initDocumentOptions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initSyncedOptions(username, password) {
|
async function initSyncedOptions(username, password) {
|
||||||
await optionService.createOption('protectedSessionTimeout', 600);
|
await optionService.createOption('protectedSessionTimeout', 600, true);
|
||||||
await optionService.createOption('noteRevisionSnapshotTimeInterval', 600);
|
await optionService.createOption('noteRevisionSnapshotTimeInterval', 600, true);
|
||||||
|
|
||||||
await optionService.createOption('username', username);
|
await optionService.createOption('username', username, true);
|
||||||
|
|
||||||
await optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32));
|
await optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32), true);
|
||||||
await optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32));
|
await optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32), true);
|
||||||
|
|
||||||
const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password));
|
const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password), true);
|
||||||
await optionService.createOption('passwordVerificationHash', passwordVerificationKey);
|
await optionService.createOption('passwordVerificationHash', passwordVerificationKey, true);
|
||||||
|
|
||||||
// passwordEncryptionService expects these options to already exist
|
// passwordEncryptionService expects these options to already exist
|
||||||
await optionService.createOption('encryptedDataKey', '');
|
await optionService.createOption('encryptedDataKey', '', true);
|
||||||
await optionService.createOption('encryptedDataKeyIv', '');
|
await optionService.createOption('encryptedDataKeyIv', '', true);
|
||||||
|
|
||||||
await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16));
|
await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initNotSyncedOptions(initialized, startNotePath = 'root', syncServerHost = '', syncProxy = '') {
|
async function initNotSyncedOptions(initialized, startNotePath = 'root', syncServerHost = '', syncProxy = '') {
|
||||||
|
@ -111,7 +111,7 @@ async function createDatabaseForSync(options, syncServerHost = '', syncProxy = '
|
|||||||
await sql.transactional(async () => {
|
await sql.transactional(async () => {
|
||||||
await sql.executeScript(schema);
|
await sql.executeScript(schema);
|
||||||
|
|
||||||
await require('./options_init').initNotSyncedOptions(false, '', syncServerHost, syncProxy);
|
await require('./options_init').initNotSyncedOptions(false, 'root', syncServerHost, syncProxy);
|
||||||
|
|
||||||
// document options required for sync to kick off
|
// document options required for sync to kick off
|
||||||
for (const opt of options) {
|
for (const opt of options) {
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username">Username</label>
|
<label for="username">Username</label>
|
||||||
<input type="text" class="form-control" data-bind="value: username" placeholder="Arbitrary string">
|
<input type="text" class="form-control" data-bind="value: username" placeholder="Choose alphanumeric username">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password1">Password</label>
|
<label for="password1">Password</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user