mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
check sync version before setting up the sync, fixes #559
This commit is contained in:
parent
41cdd5c640
commit
a72eeb9a98
@ -3,11 +3,13 @@
|
|||||||
const sqlInit = require('../../services/sql_init');
|
const sqlInit = require('../../services/sql_init');
|
||||||
const setupService = require('../../services/setup');
|
const setupService = require('../../services/setup');
|
||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
|
const appInfo = require('../../services/app_info');
|
||||||
|
|
||||||
async function getStatus() {
|
async function getStatus() {
|
||||||
return {
|
return {
|
||||||
isInitialized: await sqlInit.isDbInitialized(),
|
isInitialized: await sqlInit.isDbInitialized(),
|
||||||
schemaExists: await sqlInit.schemaExists()
|
schemaExists: await sqlInit.schemaExists(),
|
||||||
|
syncVersion: appInfo.syncVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +26,17 @@ async function setupSyncFromServer(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveSyncSeed(req) {
|
async function saveSyncSeed(req) {
|
||||||
const options = req.body.options;
|
const {options, syncVersion} = req.body;
|
||||||
|
|
||||||
|
if (appInfo.syncVersion !== syncVersion) {
|
||||||
|
const message = `Could not setup sync since local sync protocol version is ${appInfo.syncVersion} while remote is ${syncVersion}. To fix this issue, use same Trilium version on all instances.`;
|
||||||
|
|
||||||
|
log.error(message);
|
||||||
|
|
||||||
|
return [400, {
|
||||||
|
error: message
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
await sqlInit.createDatabaseForSync(options);
|
await sqlInit.createDatabaseForSync(options);
|
||||||
}
|
}
|
||||||
@ -32,7 +44,10 @@ async function saveSyncSeed(req) {
|
|||||||
async function getSyncSeed() {
|
async function getSyncSeed() {
|
||||||
log.info("Serving sync seed.");
|
log.info("Serving sync seed.");
|
||||||
|
|
||||||
return await setupService.getSyncSeedOptions();
|
return {
|
||||||
|
options: await setupService.getSyncSeedOptions(),
|
||||||
|
syncVersion: appInfo.syncVersion
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -10,6 +10,10 @@ const appInfo = require('./app_info');
|
|||||||
async function hasSyncServerSchemaAndSeed() {
|
async function hasSyncServerSchemaAndSeed() {
|
||||||
const response = await requestToSyncServer('GET', '/api/setup/status');
|
const response = await requestToSyncServer('GET', '/api/setup/status');
|
||||||
|
|
||||||
|
if (response.syncVersion !== appInfo.syncVersion) {
|
||||||
|
throw new Error(`Could not setup sync since local sync protocol version is ${appInfo.syncVersion} while remote is ${response.syncVersion}. To fix this issue, use same Trilium version on all instances.`);
|
||||||
|
}
|
||||||
|
|
||||||
return response.schemaExists;
|
return response.schemaExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +64,7 @@ async function setupSyncFromSyncServer(syncServerHost, syncProxy, username, pass
|
|||||||
log.info("Getting document options from sync server.");
|
log.info("Getting document options from sync server.");
|
||||||
|
|
||||||
// response is expected to contain documentId and documentSecret options
|
// response is expected to contain documentId and documentSecret options
|
||||||
const options = await request.exec({
|
const resp = await request.exec({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: syncServerHost + '/api/setup/sync-seed',
|
url: syncServerHost + '/api/setup/sync-seed',
|
||||||
auth: {
|
auth: {
|
||||||
@ -70,7 +74,18 @@ async function setupSyncFromSyncServer(syncServerHost, syncProxy, username, pass
|
|||||||
proxy: syncProxy
|
proxy: syncProxy
|
||||||
});
|
});
|
||||||
|
|
||||||
await sqlInit.createDatabaseForSync(options, syncServerHost, syncProxy);
|
if (resp.syncVersion !== appInfo.syncVersion) {
|
||||||
|
const message = `Could not setup sync since local sync protocol version is ${appInfo.syncVersion} while remote is ${resp.syncVersion}. To fix this issue, use same Trilium version on all instances.`;
|
||||||
|
|
||||||
|
log.error(message);
|
||||||
|
|
||||||
|
return {
|
||||||
|
result: 'failure',
|
||||||
|
error: message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await sqlInit.createDatabaseForSync(resp.options, syncServerHost, syncProxy);
|
||||||
|
|
||||||
triggerSync();
|
triggerSync();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user