mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
fixes for dates in sync
This commit is contained in:
parent
cba457bd61
commit
f68ffe1581
@ -119,7 +119,7 @@ CREATE TABLE `source_ids` (
|
||||
DROP TABLE recent_notes;
|
||||
|
||||
CREATE TABLE `recent_notes` (
|
||||
'note_tree_id'TEXT NOT NULL PRIMARY KEY,
|
||||
`note_tree_id` TEXT NOT NULL PRIMARY KEY,
|
||||
`note_path` TEXT NOT NULL,
|
||||
`date_accessed` TEXT NOT NULL,
|
||||
is_deleted INT
|
||||
|
@ -11,11 +11,15 @@ const protected_session = require('../../services/protected_session');
|
||||
const app_info = require('../../services/app_info');
|
||||
|
||||
router.post('/sync', async (req, res, next) => {
|
||||
const timestamp = req.body.timestamp;
|
||||
const timestampStr = req.body.timestamp;
|
||||
|
||||
const now = utils.nowTimestamp();
|
||||
console.log(req.body);
|
||||
|
||||
if (Math.abs(timestamp - now) > 5) {
|
||||
const timestamp = utils.parseDate(timestampStr);
|
||||
|
||||
const now = new Date();
|
||||
|
||||
if (Math.abs(timestamp.getTime() - now.getTime()) > 5000) {
|
||||
res.status(400);
|
||||
res.send({ message: 'Auth request time is out of sync' });
|
||||
}
|
||||
@ -28,13 +32,13 @@ router.post('/sync', async (req, res, next) => {
|
||||
}
|
||||
|
||||
const documentSecret = await options.getOption('document_secret');
|
||||
const expectedHash = utils.hmac(documentSecret, timestamp);
|
||||
const expectedHash = utils.hmac(documentSecret, timestampStr);
|
||||
|
||||
const givenHash = req.body.hash;
|
||||
|
||||
if (expectedHash !== givenHash) {
|
||||
res.status(400);
|
||||
res.send({ message: "Hash doesn't match" });
|
||||
res.send({ message: "Sync login hash doesn't match" });
|
||||
}
|
||||
|
||||
req.session.loggedIn = true;
|
||||
|
@ -84,7 +84,7 @@ async function sync() {
|
||||
}
|
||||
|
||||
async function login() {
|
||||
const timestamp = utils.nowTimestamp();
|
||||
const timestamp = utils.nowDate();
|
||||
|
||||
const documentSecret = await options.getOption('document_secret');
|
||||
const hash = utils.hmac(documentSecret, timestamp);
|
||||
@ -135,8 +135,7 @@ async function pullSync(syncContext) {
|
||||
if (!resp) {
|
||||
log.error("Empty response to pull for " + sync.entity_name + ", id=" + sync.entity_id);
|
||||
}
|
||||
|
||||
if (sync.entity_name === 'notes') {
|
||||
else if (sync.entity_name === 'notes') {
|
||||
await syncUpdate.updateNote(resp.entity, syncContext.sourceId);
|
||||
}
|
||||
else if (sync.entity_name === 'notes_tree') {
|
||||
|
@ -20,7 +20,7 @@ async function updateNote(entity, sourceId) {
|
||||
log.info("Update/sync note " + entity.note_id);
|
||||
}
|
||||
else {
|
||||
await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note <note>, " + utils.formatTwoTimestamps(origNote.date_modified, entity.date_modified));
|
||||
await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note <note>, " + utils.formatTwoDates(origNote.date_modified, entity.date_modified));
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ async function updateNoteTree(entity, sourceId) {
|
||||
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.formatTwoTimestamps(orig.date_modified, entity.date_modified));
|
||||
await eventLog.addNoteEvent(entity.note_tree_id, "Sync conflict in note tree <note>, " + utils.formatTwoDates(orig.date_modified, entity.date_modified));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -55,7 +55,7 @@ async function updateNoteHistory(entity, sourceId) {
|
||||
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.formatTwoTimestamps(orig.date_modified_to, entity.date_modified_to));
|
||||
await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note history for <note>, " + utils.formatTwoDates(orig.date_modified_to, entity.date_modified_to));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -86,7 +86,7 @@ async function updateOptions(entity, sourceId) {
|
||||
await eventLog.addEvent("Synced option " + entity.opt_name);
|
||||
}
|
||||
else {
|
||||
await eventLog.addEvent("Sync conflict in options for " + entity.opt_name + ", " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified));
|
||||
await eventLog.addEvent("Sync conflict in options for " + entity.opt_name + ", " + utils.formatTwoDates(orig.date_modified, entity.date_modified));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -23,10 +23,6 @@ function randomSecureToken(bytes = 32) {
|
||||
return crypto.randomBytes(bytes).toString('base64');
|
||||
}
|
||||
|
||||
function nowTimestamp() {
|
||||
return Math.floor(Date.now() / 1000);
|
||||
}
|
||||
|
||||
function nowDate() {
|
||||
return dateStr(new Date());
|
||||
}
|
||||
@ -66,14 +62,8 @@ function isElectron() {
|
||||
return !!process.versions['electron'];
|
||||
}
|
||||
|
||||
function formatDateTimeFromTS(timestamp) {
|
||||
const date = new Date(timestamp * 1000);
|
||||
|
||||
return date.toISOString();
|
||||
}
|
||||
|
||||
function formatTwoTimestamps(origTS, newTS) {
|
||||
return "orig: " + formatDateTimeFromTS(origTS) + ", new: " + formatDateTimeFromTS(newTS);
|
||||
function formatTwoDates(origDate, newDate) {
|
||||
return "orig: " + origDate + ", new: " + newDate;
|
||||
}
|
||||
|
||||
function hash(text) {
|
||||
@ -88,7 +78,6 @@ function isEmptyOrWhitespace(str) {
|
||||
module.exports = {
|
||||
randomSecureToken,
|
||||
randomString,
|
||||
nowTimestamp,
|
||||
nowDate,
|
||||
dateStr,
|
||||
parseDate,
|
||||
@ -99,7 +88,7 @@ module.exports = {
|
||||
fromBase64,
|
||||
hmac,
|
||||
isElectron,
|
||||
formatTwoTimestamps,
|
||||
formatTwoDates,
|
||||
hash,
|
||||
isEmptyOrWhitespace
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user