#98, test sync impl

This commit is contained in:
azivner 2018-07-23 10:29:17 +02:00
parent e7460ca3a9
commit a06618d851
6 changed files with 43 additions and 2 deletions

View File

@ -192,6 +192,7 @@ addTabHandler((function() {
const $syncServerHost = $("#sync-server-host"); const $syncServerHost = $("#sync-server-host");
const $syncServerTimeout = $("#sync-server-timeout"); const $syncServerTimeout = $("#sync-server-timeout");
const $syncProxy = $("#sync-proxy"); const $syncProxy = $("#sync-proxy");
const $testSyncButton = $("#test-sync-button");
function optionsLoaded(options) { function optionsLoaded(options) {
$syncServerHost.val(options['syncServerHost']); $syncServerHost.val(options['syncServerHost']);
@ -209,6 +210,17 @@ addTabHandler((function() {
return false; 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 { return {
optionsLoaded optionsLoaded
}; };

View File

@ -35,7 +35,7 @@ async function setupSyncFromServer(req) {
auth: username + ':' + password auth: username + ':' + password
}; };
log.info("Getting document from: " + serverAddress + JSON.stringify(options)); log.info("Getting document from: " + serverAddress);
http.request(options, function(response) { http.request(options, function(response) {
response.pipe(file); response.pipe(file);

View File

@ -9,6 +9,20 @@ const contentHashService = require('../../services/content_hash');
const log = require('../../services/log'); const log = require('../../services/log');
const DOCUMENT_PATH = require('../../services/data_dir').DOCUMENT_PATH; 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() { async function checkSync() {
return { return {
hashes: await contentHashService.getHashes(), hashes: await contentHashService.getHashes(),
@ -80,6 +94,7 @@ async function getDocument(req, resp) {
} }
module.exports = { module.exports = {
testSync,
checkSync, checkSync,
syncNow, syncNow,
fillSyncRows, fillSyncRows,

View File

@ -148,6 +148,7 @@ function register(app) {
apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword); apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword);
apiRoute(POST, '/api/sync/test', syncApiRoute.testSync);
apiRoute(GET, '/api/sync/check', syncApiRoute.checkSync); apiRoute(GET, '/api/sync/check', syncApiRoute.checkSync);
apiRoute(POST, '/api/sync/now', syncApiRoute.syncNow); apiRoute(POST, '/api/sync/now', syncApiRoute.syncNow);
apiRoute(POST, '/api/sync/fill-sync-rows', syncApiRoute.fillSyncRows); apiRoute(POST, '/api/sync/fill-sync-rows', syncApiRoute.fillSyncRows);

View File

@ -289,5 +289,6 @@ sqlInit.dbReady.then(async () => {
module.exports = { module.exports = {
sync, sync,
login,
getSyncRecords getSyncRecords
}; };

View File

@ -406,7 +406,7 @@
</form> </form>
</div> </div>
<div id="sync-setup"> <div id="sync-setup">
<h4 style="margin-top: 0px;">Sync</h4> <h4 style="margin-top: 0px;">Sync configuration</h4>
<form id="sync-setup-form"> <form id="sync-setup-form">
<div class="form-group"> <div class="form-group">
@ -426,6 +426,18 @@
<button class="btn btn-sm">Save</button> <button class="btn btn-sm">Save</button>
</form> </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>
<div id="advanced"> <div id="advanced">
<h4 style="margin-top: 0px;">Sync</h4> <h4 style="margin-top: 0px;">Sync</h4>