mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
Merge branch 'master' into stable
This commit is contained in:
commit
180a7432ca
@ -151,3 +151,15 @@ settings.addModule((async function () {
|
|||||||
|
|
||||||
return {};
|
return {};
|
||||||
})());
|
})());
|
||||||
|
|
||||||
|
settings.addModule((async function () {
|
||||||
|
const forceFullSyncButton = $("#force-full-sync-button");
|
||||||
|
|
||||||
|
forceFullSyncButton.click(async () => {
|
||||||
|
await server.post('sync/force-full-sync');
|
||||||
|
|
||||||
|
showMessage("Full sync triggered");
|
||||||
|
});
|
||||||
|
|
||||||
|
return {};
|
||||||
|
})());
|
@ -33,19 +33,7 @@ router.put('/:noteTreeId/:notePath', auth.checkApiAuth, async (req, res, next) =
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function getRecentNotes() {
|
async function getRecentNotes() {
|
||||||
await deleteOld();
|
|
||||||
|
|
||||||
return await sql.getResults("SELECT * FROM recent_notes WHERE is_deleted = 0 ORDER BY date_accessed DESC");
|
return await sql.getResults("SELECT * FROM recent_notes WHERE is_deleted = 0 ORDER BY date_accessed DESC");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteOld() {
|
|
||||||
const cutoffDateAccessed = utils.dateStr(new Date(Date.now() - 24 * 60 * 60 * 1000));
|
|
||||||
|
|
||||||
await sql.doInTransaction(async () => {
|
|
||||||
await sql.execute("DELETE FROM recent_notes WHERE date_accessed < ?", [cutoffDateAccessed]);
|
|
||||||
|
|
||||||
await sql.execute("DELETE FROM sync WHERE entity_name = 'recent_notes' AND sync_date < ?", [cutoffDateAccessed]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
@ -20,6 +20,18 @@ router.post('/now', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
res.send(await sync.sync());
|
res.send(await sync.sync());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post('/force-full-sync', auth.checkApiAuth, async (req, res, next) => {
|
||||||
|
await sql.doInTransaction(async () => {
|
||||||
|
await options.setOption('last_synced_pull', 0);
|
||||||
|
await options.setOption('last_synced_push', 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
// not awaiting for the job to finish (will probably take a long time)
|
||||||
|
sync.sync();
|
||||||
|
|
||||||
|
res.send({});
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/changed', auth.checkApiAuth, async (req, res, next) => {
|
router.get('/changed', auth.checkApiAuth, async (req, res, next) => {
|
||||||
const lastSyncId = parseInt(req.query.lastSyncId);
|
const lastSyncId = parseInt(req.query.lastSyncId);
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
module.exports = { build_date:"2017-12-10T23:23:04-05:00", build_revision: "bdeaa2829d4c5436e86d0d943a2a332d0c016804" };
|
module.exports = { build_date:"2017-12-12T23:57:58-05:00", build_revision: "2fa57b79fd972b3eda6eb8ef1d26e9915b75fd96" };
|
||||||
|
@ -142,6 +142,7 @@ async function updateNote(noteId, newNote, ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
const nowStr = utils.nowDate();
|
||||||
|
|
||||||
const historySnapshotTimeInterval = parseInt(await options.getOption('history_snapshot_time_interval'));
|
const historySnapshotTimeInterval = parseInt(await options.getOption('history_snapshot_time_interval'));
|
||||||
|
|
||||||
@ -170,7 +171,7 @@ async function updateNote(noteId, newNote, ctx) {
|
|||||||
note_text: oldNote.note_text,
|
note_text: oldNote.note_text,
|
||||||
is_protected: 0, // will be fixed in the protectNoteHistory() call
|
is_protected: 0, // will be fixed in the protectNoteHistory() call
|
||||||
date_modified_from: oldNote.date_modified,
|
date_modified_from: oldNote.date_modified,
|
||||||
date_modified_to: now
|
date_modified_to: nowStr
|
||||||
});
|
});
|
||||||
|
|
||||||
await sync_table.addNoteHistorySync(newNoteHistoryId);
|
await sync_table.addNoteHistorySync(newNoteHistoryId);
|
||||||
@ -182,7 +183,7 @@ async function updateNote(noteId, newNote, ctx) {
|
|||||||
newNote.detail.note_title,
|
newNote.detail.note_title,
|
||||||
newNote.detail.note_text,
|
newNote.detail.note_text,
|
||||||
newNote.detail.is_protected,
|
newNote.detail.is_protected,
|
||||||
now,
|
nowStr,
|
||||||
noteId]);
|
noteId]);
|
||||||
|
|
||||||
await sync_table.addNoteSync(noteId);
|
await sync_table.addNoteSync(noteId);
|
||||||
|
@ -3,7 +3,7 @@ const source_id = require('./source_id');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const messaging = require('./messaging');
|
const messaging = require('./messaging');
|
||||||
const options = require('./options');
|
const options = require('./options');
|
||||||
const sync = require('./sync');
|
const sync_setup = require('./sync_setup');
|
||||||
|
|
||||||
let startTime = utils.nowDate();
|
let startTime = utils.nowDate();
|
||||||
let sentSyncId = [];
|
let sentSyncId = [];
|
||||||
@ -35,7 +35,7 @@ async function sendPing() {
|
|||||||
messaging.sendMessage({
|
messaging.sendMessage({
|
||||||
type: 'sync',
|
type: 'sync',
|
||||||
data: data,
|
data: data,
|
||||||
changesToPushCount: sync.isSyncSetup ? changesToPushCount : 0
|
changesToPushCount: sync_setup.isSyncSetup ? changesToPushCount : 0
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const syncId of syncIds) {
|
for (const syncId of syncIds) {
|
||||||
|
@ -5,7 +5,6 @@ const rp = require('request-promise');
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const options = require('./options');
|
const options = require('./options');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const config = require('./config');
|
|
||||||
const source_id = require('./source_id');
|
const source_id = require('./source_id');
|
||||||
const notes = require('./notes');
|
const notes = require('./notes');
|
||||||
const syncUpdate = require('./sync_update');
|
const syncUpdate = require('./sync_update');
|
||||||
@ -14,11 +13,7 @@ const event_log = require('./event_log');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const app_info = require('./app_info');
|
const app_info = require('./app_info');
|
||||||
const messaging = require('./messaging');
|
const messaging = require('./messaging');
|
||||||
|
const sync_setup = require('./sync_setup');
|
||||||
const SYNC_SERVER = config['Sync']['syncServerHost'];
|
|
||||||
const isSyncSetup = !!SYNC_SERVER;
|
|
||||||
const SYNC_TIMEOUT = config['Sync']['syncServerTimeout'] || 5000;
|
|
||||||
const SYNC_PROXY = config['Sync']['syncProxy'];
|
|
||||||
|
|
||||||
let syncInProgress = false;
|
let syncInProgress = false;
|
||||||
let proxyToggle = true;
|
let proxyToggle = true;
|
||||||
@ -278,7 +273,7 @@ async function checkContentHash(syncContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function syncRequest(syncContext, method, uri, body) {
|
async function syncRequest(syncContext, method, uri, body) {
|
||||||
const fullUri = SYNC_SERVER + uri;
|
const fullUri = sync_setup.SYNC_SERVER + uri;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {
|
const options = {
|
||||||
@ -287,15 +282,15 @@ async function syncRequest(syncContext, method, uri, body) {
|
|||||||
jar: syncContext.cookieJar,
|
jar: syncContext.cookieJar,
|
||||||
json: true,
|
json: true,
|
||||||
body: body,
|
body: body,
|
||||||
timeout: SYNC_TIMEOUT
|
timeout: sync_setup.SYNC_TIMEOUT
|
||||||
};
|
};
|
||||||
|
|
||||||
if (syncServerCertificate) {
|
if (syncServerCertificate) {
|
||||||
options.ca = syncServerCertificate;
|
options.ca = syncServerCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SYNC_PROXY && proxyToggle) {
|
if (sync_setup.SYNC_PROXY && proxyToggle) {
|
||||||
options.proxy = SYNC_PROXY;
|
options.proxy = sync_setup.SYNC_PROXY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rp(options);
|
return await rp(options);
|
||||||
@ -306,19 +301,17 @@ async function syncRequest(syncContext, method, uri, body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql.dbReady.then(() => {
|
sql.dbReady.then(() => {
|
||||||
if (isSyncSetup) {
|
if (sync_setup.isSyncSetup) {
|
||||||
log.info("Setting up sync to " + SYNC_SERVER + " with timeout " + SYNC_TIMEOUT);
|
log.info("Setting up sync to " + sync_setup.SYNC_SERVER + " with timeout " + sync_setup.SYNC_TIMEOUT);
|
||||||
|
|
||||||
if (SYNC_PROXY) {
|
if (sync_setup.SYNC_PROXY) {
|
||||||
log.info("Sync proxy: " + SYNC_PROXY);
|
log.info("Sync proxy: " + sync_setup.SYNC_PROXY);
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncCertPath = config['Sync']['syncServerCertificate'];
|
if (sync_setup.SYNC_CERT_PATH) {
|
||||||
|
log.info('Sync certificate: ' + sync_setup.SYNC_CERT_PATH);
|
||||||
|
|
||||||
if (syncCertPath) {
|
syncServerCertificate = fs.readFileSync(sync_setup.SYNC_CERT_PATH);
|
||||||
log.info('Sync certificate: ' + syncCertPath);
|
|
||||||
|
|
||||||
syncServerCertificate = fs.readFileSync(syncCertPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(sync, 60000);
|
setInterval(sync, 60000);
|
||||||
@ -332,6 +325,5 @@ sql.dbReady.then(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sync,
|
sync
|
||||||
isSyncSetup
|
|
||||||
};
|
};
|
11
services/sync_setup.js
Normal file
11
services/sync_setup.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const config = require('./config');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
SYNC_SERVER: config['Sync']['syncServerHost'],
|
||||||
|
isSyncSetup: !!config['Sync']['syncServerHost'],
|
||||||
|
SYNC_TIMEOUT: config['Sync']['syncServerTimeout'] || 5000,
|
||||||
|
SYNC_PROXY: config['Sync']['syncProxy'],
|
||||||
|
SYNC_CERT_PATH: config['Sync']['syncServerCertificate']
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const source_id = require('./source_id');
|
const source_id = require('./source_id');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
const sync_setup = require('./sync_setup');
|
||||||
|
|
||||||
async function addNoteSync(noteId, sourceId) {
|
async function addNoteSync(noteId, sourceId) {
|
||||||
await addEntitySync("notes", noteId, sourceId)
|
await addEntitySync("notes", noteId, sourceId)
|
||||||
@ -27,12 +28,14 @@ async function addRecentNoteSync(notePath, sourceId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addEntitySync(entityName, entityId, sourceId) {
|
async function addEntitySync(entityName, entityId, sourceId) {
|
||||||
await sql.replace("sync", {
|
if (sync_setup.isSyncSetup) {
|
||||||
entity_name: entityName,
|
await sql.replace("sync", {
|
||||||
entity_id: entityId,
|
entity_name: entityName,
|
||||||
sync_date: utils.nowDate(),
|
entity_id: entityId,
|
||||||
source_id: sourceId || source_id.currentSourceId
|
sync_date: utils.nowDate(),
|
||||||
});
|
source_id: sourceId || source_id.currentSourceId
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const options = require('./options');
|
const options = require('./options');
|
||||||
const utils = require('./utils');
|
|
||||||
const eventLog = require('./event_log');
|
const eventLog = require('./event_log');
|
||||||
const notes = require('./notes');
|
const notes = require('./notes');
|
||||||
const sync_table = require('./sync_table');
|
const sync_table = require('./sync_table');
|
||||||
@ -19,9 +18,6 @@ async function updateNote(entity, sourceId) {
|
|||||||
|
|
||||||
log.info("Update/sync note " + entity.note_id);
|
log.info("Update/sync note " + entity.note_id);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note <note>, " + utils.formatTwoDates(origNote.date_modified, entity.date_modified));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateNoteTree(entity, sourceId) {
|
async function updateNoteTree(entity, sourceId) {
|
||||||
@ -37,9 +33,6 @@ async function updateNoteTree(entity, sourceId) {
|
|||||||
|
|
||||||
log.info("Update/sync note tree " + entity.note_tree_id);
|
log.info("Update/sync note tree " + entity.note_tree_id);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
await eventLog.addNoteEvent(entity.note_tree_id, "Sync conflict in note tree <note>, " + utils.formatTwoDates(orig.date_modified, entity.date_modified));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,9 +47,6 @@ async function updateNoteHistory(entity, sourceId) {
|
|||||||
|
|
||||||
log.info("Update/sync note history " + entity.note_history_id);
|
log.info("Update/sync note history " + entity.note_history_id);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note history for <note>, " + utils.formatTwoDates(orig.date_modified_to, entity.date_modified_to));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,9 +75,6 @@ async function updateOptions(entity, sourceId) {
|
|||||||
|
|
||||||
await eventLog.addEvent("Synced option " + entity.opt_name);
|
await eventLog.addEvent("Synced option " + entity.opt_name);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
await eventLog.addEvent("Sync conflict in options for " + entity.opt_name + ", " + utils.formatTwoDates(orig.date_modified, entity.date_modified));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +62,6 @@ function isElectron() {
|
|||||||
return !!process.versions['electron'];
|
return !!process.versions['electron'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTwoDates(origDate, newDate) {
|
|
||||||
return "orig: " + origDate + ", new: " + newDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hash(text) {
|
function hash(text) {
|
||||||
return crypto.createHash('sha1').update(text).digest('base64');
|
return crypto.createHash('sha1').update(text).digest('base64');
|
||||||
}
|
}
|
||||||
@ -88,7 +84,6 @@ module.exports = {
|
|||||||
fromBase64,
|
fromBase64,
|
||||||
hmac,
|
hmac,
|
||||||
isElectron,
|
isElectron,
|
||||||
formatTwoDates,
|
|
||||||
hash,
|
hash,
|
||||||
isEmptyOrWhitespace
|
isEmptyOrWhitespace
|
||||||
};
|
};
|
@ -165,6 +165,7 @@
|
|||||||
<li><a href="#change-password">Change password</a></li>
|
<li><a href="#change-password">Change password</a></li>
|
||||||
<li><a href="#protected-session-timeout">Protected session</a></li>
|
<li><a href="#protected-session-timeout">Protected session</a></li>
|
||||||
<li><a href="#history-snapshot-time-interval">History snapshots</a></li>
|
<li><a href="#history-snapshot-time-interval">History snapshots</a></li>
|
||||||
|
<li><a href="#sync">Sync</a></li>
|
||||||
<li><a href="#about">About Trilium</a></li>
|
<li><a href="#about">About Trilium</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div id="change-password">
|
<div id="change-password">
|
||||||
@ -212,6 +213,9 @@
|
|||||||
<button class="btn btn-sm">Save</button>
|
<button class="btn btn-sm">Save</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="sync">
|
||||||
|
<button id="force-full-sync-button" class="btn btn-sm">Force full sync</button>
|
||||||
|
</div>
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user