mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
"use strict";
|
|
|
|
import sqlInit = require('../../services/sql_init');
|
|
import setupService = require('../../services/setup');
|
|
import log = require('../../services/log');
|
|
import appInfo = require('../../services/app_info');
|
|
import { Request } from 'express';
|
|
|
|
function getStatus() {
|
|
return {
|
|
isInitialized: sqlInit.isDbInitialized(),
|
|
schemaExists: sqlInit.schemaExists(),
|
|
syncVersion: appInfo.syncVersion
|
|
};
|
|
}
|
|
|
|
async function setupNewDocument() {
|
|
await sqlInit.createInitialDatabase();
|
|
}
|
|
|
|
function setupSyncFromServer(req: Request) {
|
|
const { syncServerHost, syncProxy, password } = req.body;
|
|
|
|
return setupService.setupSyncFromSyncServer(syncServerHost, syncProxy, password);
|
|
}
|
|
|
|
function saveSyncSeed(req: Request) {
|
|
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
|
|
}]
|
|
}
|
|
|
|
log.info("Saved sync seed.");
|
|
|
|
sqlInit.createDatabaseForSync(options);
|
|
}
|
|
|
|
function getSyncSeed() {
|
|
log.info("Serving sync seed.");
|
|
|
|
return {
|
|
options: setupService.getSyncSeedOptions(),
|
|
syncVersion: appInfo.syncVersion
|
|
};
|
|
}
|
|
|
|
export = {
|
|
getStatus,
|
|
setupNewDocument,
|
|
setupSyncFromServer,
|
|
getSyncSeed,
|
|
saveSyncSeed
|
|
};
|