trilium/src/routes/api/setup.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-12-04 11:29:23 +08:00
"use strict";
const sqlInit = require('../../services/sql_init');
const setupService = require('../../services/setup');
2018-07-25 15:46:57 +08:00
const log = require('../../services/log');
const appInfo = require('../../services/app_info');
async function getStatus() {
return {
2018-09-11 16:01:40 +08:00
isInitialized: await sqlInit.isDbInitialized(),
schemaExists: await sqlInit.schemaExists(),
syncVersion: appInfo.syncVersion
};
}
2017-12-04 11:29:23 +08:00
async function setupNewDocument(req) {
const { username, password, theme } = req.body;
2017-12-04 11:29:23 +08:00
await sqlInit.createInitialDatabase(username, password, theme);
}
2017-12-04 11:29:23 +08:00
async function setupSyncFromServer(req) {
2018-07-25 14:30:41 +08:00
const { syncServerHost, syncProxy, username, password } = req.body;
2018-07-25 14:30:41 +08:00
return await setupService.setupSyncFromSyncServer(syncServerHost, syncProxy, username, password);
}
2018-07-25 15:46:57 +08:00
async function saveSyncSeed(req) {
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);
}
2018-07-25 15:46:57 +08:00
async function getSyncSeed() {
log.info("Serving sync seed.");
return {
options: await setupService.getSyncSeedOptions(),
syncVersion: appInfo.syncVersion
};
2018-07-25 15:46:57 +08:00
}
module.exports = {
getStatus,
setupNewDocument,
setupSyncFromServer,
2018-07-25 15:46:57 +08:00
getSyncSeed,
saveSyncSeed
};