mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 16:25:51 +01:00
#98 some sync setup refactorings
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
const sqlInit = require('../../services/sql_init');
|
||||
const setupService = require('../../services/setup');
|
||||
const optionService = require('../../services/options');
|
||||
const syncService = require('../../services/sync');
|
||||
const log = require('../../services/log');
|
||||
const rp = require('request-promise');
|
||||
|
||||
async function setupNewDocument(req) {
|
||||
const { username, password } = req.body;
|
||||
@@ -15,14 +19,51 @@ async function setupSyncFromServer(req) {
|
||||
return await setupService.setupSyncFromSyncServer(syncServerHost, syncProxy, username, password);
|
||||
}
|
||||
|
||||
async function setupSyncFromClient(req) {
|
||||
async function setupSyncToSyncServer() {
|
||||
log.info("Initiating sync to server");
|
||||
|
||||
const syncServerHost = await optionService.getOption('syncServerHost');
|
||||
const syncProxy = await optionService.getOption('syncProxy');
|
||||
|
||||
const rpOpts = {
|
||||
uri: syncServerHost + '/api/setup/sync-seed',
|
||||
method: 'POST',
|
||||
json: true,
|
||||
body: {
|
||||
options: await setupService.getSyncSeedOptions()
|
||||
}
|
||||
};
|
||||
|
||||
if (syncProxy) {
|
||||
rpOpts.proxy = syncProxy;
|
||||
}
|
||||
|
||||
await rp(rpOpts);
|
||||
|
||||
// this is completely new sync, need to reset counters. If this would not be new sync,
|
||||
// the previous request would have failed.
|
||||
await optionService.setOption('lastSyncedPush', 0);
|
||||
await optionService.setOption('lastSyncedPull', 0);
|
||||
|
||||
syncService.sync();
|
||||
}
|
||||
|
||||
async function saveSyncSeed(req) {
|
||||
const options = req.body.options;
|
||||
|
||||
await sqlInit.createDatabaseForSync(options);
|
||||
}
|
||||
|
||||
async function getSyncSeed() {
|
||||
log.info("Serving sync seed.");
|
||||
|
||||
return await setupService.getSyncSeedOptions();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setupNewDocument,
|
||||
setupSyncFromServer,
|
||||
setupSyncFromClient
|
||||
setupSyncToSyncServer,
|
||||
getSyncSeed,
|
||||
saveSyncSeed
|
||||
};
|
||||
Reference in New Issue
Block a user