From a06618d851ac5106820437220b706b7b5e1b5799 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 23 Jul 2018 10:29:17 +0200 Subject: [PATCH] #98, test sync impl --- src/public/javascripts/dialogs/options.js | 12 ++++++++++++ src/routes/api/setup.js | 2 +- src/routes/api/sync.js | 15 +++++++++++++++ src/routes/routes.js | 1 + src/services/sync.js | 1 + src/views/index.ejs | 14 +++++++++++++- 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/dialogs/options.js b/src/public/javascripts/dialogs/options.js index e106cbf0e..e0fa9d5f6 100644 --- a/src/public/javascripts/dialogs/options.js +++ b/src/public/javascripts/dialogs/options.js @@ -192,6 +192,7 @@ addTabHandler((function() { const $syncServerHost = $("#sync-server-host"); const $syncServerTimeout = $("#sync-server-timeout"); const $syncProxy = $("#sync-proxy"); + const $testSyncButton = $("#test-sync-button"); function optionsLoaded(options) { $syncServerHost.val(options['syncServerHost']); @@ -209,6 +210,17 @@ addTabHandler((function() { return false; }); + $testSyncButton.click(async () => { + const result = await server.post('sync/test'); + + if (result.connection === "Success") { + infoService.showMessage("Sync server handshake has been successful"); + } + else { + infoService.showError("Sync server handshake failed, error: " + result.error); + } + }); + return { optionsLoaded }; diff --git a/src/routes/api/setup.js b/src/routes/api/setup.js index 93f5dcba4..a07674169 100644 --- a/src/routes/api/setup.js +++ b/src/routes/api/setup.js @@ -35,7 +35,7 @@ async function setupSyncFromServer(req) { auth: username + ':' + password }; - log.info("Getting document from: " + serverAddress + JSON.stringify(options)); + log.info("Getting document from: " + serverAddress); http.request(options, function(response) { response.pipe(file); diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index 5daa446ce..1400b0037 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -9,6 +9,20 @@ const contentHashService = require('../../services/content_hash'); const log = require('../../services/log'); const DOCUMENT_PATH = require('../../services/data_dir').DOCUMENT_PATH; +async function testSync() { + try { + await syncService.login(); + + return { connection: "Success" }; + } + catch (e) { + return { + connection: "Failure", + error: e.message + }; + } +} + async function checkSync() { return { hashes: await contentHashService.getHashes(), @@ -80,6 +94,7 @@ async function getDocument(req, resp) { } module.exports = { + testSync, checkSync, syncNow, fillSyncRows, diff --git a/src/routes/routes.js b/src/routes/routes.js index fdc894aa8..e1b3f5942 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -148,6 +148,7 @@ function register(app) { apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword); + apiRoute(POST, '/api/sync/test', syncApiRoute.testSync); apiRoute(GET, '/api/sync/check', syncApiRoute.checkSync); apiRoute(POST, '/api/sync/now', syncApiRoute.syncNow); apiRoute(POST, '/api/sync/fill-sync-rows', syncApiRoute.fillSyncRows); diff --git a/src/services/sync.js b/src/services/sync.js index a0edd8349..fb40abbcf 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -289,5 +289,6 @@ sqlInit.dbReady.then(async () => { module.exports = { sync, + login, getSyncRecords }; \ No newline at end of file diff --git a/src/views/index.ejs b/src/views/index.ejs index f5a8e8f31..4a5669d84 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -406,7 +406,7 @@
-

Sync

+

Sync configuration

@@ -426,6 +426,18 @@ + +

Sync test

+ +

This will test connection and handshake to the sync server.

+ + + +

Copy document to the server instance

+ +

This is used when you're setting up server instance of Trilium. After the installation the databa

+ +

Sync