2017-12-03 22:29:23 -05:00
"use strict" ;
2024-04-06 23:08:41 +03:00
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' ;
2018-09-10 20:05:10 +02:00
2020-06-20 12:31:38 +02:00
function getStatus() {
2018-09-10 20:05:10 +02:00
return {
2020-06-20 12:31:38 +02:00
isInitialized : sqlInit.isDbInitialized ( ) ,
schemaExists : sqlInit.schemaExists ( ) ,
2019-06-11 20:42:06 +02:00
syncVersion : appInfo.syncVersion
2018-09-10 20:05:10 +02:00
} ;
}
2017-12-03 22:29:23 -05:00
2021-12-28 22:59:38 +01:00
async function setupNewDocument() {
await sqlInit . createInitialDatabase ( ) ;
2018-03-30 17:07:41 -04:00
}
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 ;
2018-07-22 19:56:20 +02:00
2021-12-29 23:37:12 +01:00
return setupService . setupSyncFromSyncServer ( syncServerHost , syncProxy , password ) ;
2018-07-22 19:56:20 +02:00
}
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 ;
2019-06-11 20:42:06 +02:00
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
} ]
}
2018-07-24 20:35:03 +02:00
2020-12-06 22:11:49 +01:00
log . info ( "Saved sync seed." ) ;
2020-06-20 12:31:38 +02:00
sqlInit . createDatabaseForSync ( options ) ;
2018-07-24 20:35:03 +02:00
}
2020-06-20 12:31:38 +02:00
function getSyncSeed() {
2018-07-25 09:46:57 +02:00
log . info ( "Serving sync seed." ) ;
2019-06-11 20:42:06 +02:00
return {
2020-06-20 12:31:38 +02:00
options : setupService.getSyncSeedOptions ( ) ,
2019-06-11 20:42:06 +02:00
syncVersion : appInfo.syncVersion
} ;
2018-07-25 09:46:57 +02:00
}
2024-04-06 23:08:41 +03:00
export = {
2018-09-10 20:05:10 +02:00
getStatus ,
2018-07-22 19:56:20 +02:00
setupNewDocument ,
2018-07-24 20:35:03 +02:00
setupSyncFromServer ,
2018-07-25 09:46:57 +02:00
getSyncSeed ,
saveSyncSeed
2020-06-20 12:31:38 +02:00
} ;