Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
#98, test sync impl
azivnera06618d851ac
diff --git a/src/public/javascripts/dialogs/options.js b/src/public/javascripts/dialogs/options.jsindex e106cbf0ef..e0fa9d5f6b 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.jsindex 93f5dcba47..a07674169f 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.jsindex 5daa446ce0..1400b00377 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.jsindex fdc894aa8e..e1b3f59424 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.jsindex a0edd83494..fb40abbcf3 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 filediff --git a/src/views/index.ejs b/src/views/index.ejsindex f5a8e8f316..4a5669d843 100644--- a/src/views/index.ejs+++ b/src/views/index.ejs@@ -406,7 +406,7 @@</form></div><div id="sync-setup">- <h4 style="margin-top: 0px;">Sync</h4>+ <h4 style="margin-top: 0px;">Sync configuration</h4><form id="sync-setup-form"><div class="form-group">@@ -426,6 +426,18 @@<button class="btn btn-sm">Save</button></form>++ <h4>Sync test</h4>++ <p>This will test connection and handshake to the sync server.</p>++ <button id="test-sync-button" class="btn btn-sm">Test sync</button>++ <h4>Copy document to the server instance</h4>++ <p>This is used when you're setting up server instance of Trilium. After the installation the databa</p>++ <button id="test-sync-button" class="btn btn-sm">Copy document to the sync server</button></div><div id="advanced"><h4 style="margin-top: 0px;">Sync</h4>