mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 15:25:51 +01:00
server-ts: Convert routes/api/setup
This commit is contained in:
60
src/routes/api/setup.ts
Normal file
60
src/routes/api/setup.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
"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
|
||||
};
|
||||
Reference in New Issue
Block a user