merged "Sync local document" into "Test sync"

This commit is contained in:
azivner
2018-09-10 20:05:10 +02:00
parent b4a566df9e
commit e4381d10e8
7 changed files with 70 additions and 68 deletions

View File

@@ -38,7 +38,7 @@ async function loginSync(req) {
const givenHash = req.body.hash;
if (expectedHash !== givenHash) {
return [400, { message: "Sync login hash doesn't match" }];
return [400, { message: "Sync login credentials are incorrect." }];
}
req.session.loggedIn = true;

View File

@@ -2,10 +2,13 @@
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 getStatus() {
return {
isInitialized: await sqlInit.isDbInitialized()
};
}
async function setupNewDocument(req) {
const { username, password } = req.body;
@@ -19,42 +22,6 @@ async function setupSyncFromServer(req) {
return await setupService.setupSyncFromSyncServer(syncServerHost, syncProxy, username, password);
}
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;
}
try {
await rp(rpOpts);
}
catch (e) {
return { success: false, error: e.message };
}
// 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();
return { success: true };
}
async function saveSyncSeed(req) {
const options = req.body.options;
@@ -68,9 +35,9 @@ async function getSyncSeed() {
}
module.exports = {
getStatus,
setupNewDocument,
setupSyncFromServer,
setupSyncToSyncServer,
getSyncSeed,
saveSyncSeed
};

View File

@@ -1,6 +1,7 @@
"use strict";
const syncService = require('../../services/sync');
const setupService = require('../../services/setup');
const syncUpdateService = require('../../services/sync_update');
const syncTableService = require('../../services/sync_table');
const sql = require('../../services/sql');
@@ -11,13 +12,20 @@ const log = require('../../services/log');
async function testSync() {
try {
await syncService.login();
if (await setupService.isSyncServerInitialized()) {
await syncService.login();
return { connection: "Success" };
return { success: true, message: "Sync server handshake has been successful" };
}
else {
await setupService.setupSyncToSyncServer();
return { success: true, message: "Sync has been established to the server instance. It will take some time to finish." };
}
}
catch (e) {
return {
connection: "Failure",
success: false,
error: e.message
};
}