Notes/src/routes/api/setup.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-12-03 22:29:23 -05:00
"use strict";
const sqlInit = require('../../services/sql_init');
const setupService = require('../../services/setup');
2018-07-25 09:46:57 +02:00
const log = require('../../services/log');
const appInfo = require('../../services/app_info');
2020-06-20 12:31:38 +02:00
function getStatus() {
return {
2020-06-20 12:31:38 +02:00
isInitialized: sqlInit.isDbInitialized(),
schemaExists: sqlInit.schemaExists(),
syncVersion: appInfo.syncVersion
};
}
2017-12-03 22:29:23 -05:00
2020-07-02 21:08:18 +02:00
async function setupNewDocument(req) {
const { username, password, theme } = req.body;
2017-12-03 22:29:23 -05:00
2020-07-02 21:08:18 +02:00
await sqlInit.createInitialDatabase(username, password, theme);
}
2017-12-03 22:29:23 -05:00
2020-06-20 12:31:38 +02:00
function setupSyncFromServer(req) {
2018-07-25 08:30:41 +02:00
const { syncServerHost, syncProxy, username, password } = req.body;
2020-06-20 12:31:38 +02:00
return setupService.setupSyncFromSyncServer(syncServerHost, syncProxy, username, password);
}
2020-06-20 12:31:38 +02:00
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
}]
}
2020-06-20 12:31:38 +02:00
sqlInit.createDatabaseForSync(options);
}
2020-06-20 12:31:38 +02:00
function getSyncSeed() {
2018-07-25 09:46:57 +02:00
log.info("Serving sync seed.");
return {
2020-06-20 12:31:38 +02:00
options: setupService.getSyncSeedOptions(),
syncVersion: appInfo.syncVersion
};
2018-07-25 09:46:57 +02:00
}
module.exports = {
getStatus,
setupNewDocument,
setupSyncFromServer,
2018-07-25 09:46:57 +02:00
getSyncSeed,
saveSyncSeed
2020-06-20 12:31:38 +02:00
};