92 lines
2.2 KiB
TypeScript
Raw Normal View History

2017-12-03 22:29:23 -05:00
"use strict";
import sqlInit from "../../services/sql_init.js";
import setupService from "../../services/setup.js";
import log from "../../services/log.js";
import appInfo from "../../services/app_info.js";
import type { Request } from "express";
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
2021-12-28 22:59:38 +01:00
async function setupNewDocument() {
await sqlInit.createInitialDatabase();
}
2017-12-03 22:29:23 -05:00
2024-04-06 23:08:41 +03:00
function setupSyncFromServer(req: Request) {
2021-12-29 23:37:12 +01:00
const { syncServerHost, syncProxy, password } = req.body;
2021-12-29 23:37:12 +01:00
return setupService.setupSyncFromSyncServer(syncServerHost, syncProxy, password);
}
2024-04-06 23:08:41 +03:00
function saveSyncSeed(req: Request) {
2024-04-03 23:28:26 +03:00
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);
2025-01-09 18:07:02 +02:00
return [
400,
{
error: message
}
];
}
log.info("Saved sync seed.");
2020-06-20 12:31:38 +02:00
sqlInit.createDatabaseForSync(options);
}
2025-02-13 17:02:03 +01:00
/**
* @swagger
* /api/setup/sync-seed:
* get:
* tags:
* - auth
* summary: Sync documentSecret value
* description: First step to logging in.
* operationId: setup-sync-seed
* responses:
* '200':
* description: Successful operation
* content:
* application/json:
* schema:
* type: object
* properties:
* syncVersion:
* type: integer
* example: 34
* options:
* type: object
* properties:
* documentSecret:
* type: string
* security:
* - user-password: []
*/
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
}
export default {
getStatus,
setupNewDocument,
setupSyncFromServer,
2018-07-25 09:46:57 +02:00
getSyncSeed,
saveSyncSeed
2020-06-20 12:31:38 +02:00
};