mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
sync fixes
This commit is contained in:
parent
ba24281f22
commit
2a9a8da045
@ -16,8 +16,8 @@ router.post('', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
const browserId = req.get('x-browser-id');
|
const browserId = req.get('x-browser-id');
|
||||||
|
|
||||||
const noteTreeChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
|
const noteTreeChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
|
||||||
"AND date_modified >= ? AND category IN (?, ?, ?)", [browserId, treeLoadTime,
|
"AND date_modified >= ? AND category IN (?, ?, ?, ?)", [browserId, treeLoadTime,
|
||||||
audit_category.UPDATE_TITLE, audit_category.CHANGE_PARENT, audit_category.CHANGE_POSITION]);
|
audit_category.UPDATE_TITLE, audit_category.CHANGE_PARENT, audit_category.CHANGE_POSITION, audit_category.DELETE_NOTE]);
|
||||||
|
|
||||||
const currentNoteChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
|
const currentNoteChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
|
||||||
"AND date_modified >= ? AND note_id = ? AND category IN (?, ?)", [browserId, currentNoteLoadTime, currentNoteId,
|
"AND date_modified >= ? AND note_id = ? AND category IN (?, ?)", [browserId, currentNoteLoadTime, currentNoteId,
|
||||||
|
@ -6,6 +6,7 @@ const sql = require('../../services/sql');
|
|||||||
const options = require('../../services/options');
|
const options = require('../../services/options');
|
||||||
const utils = require('../../services/utils');
|
const utils = require('../../services/utils');
|
||||||
const auth = require('../../services/auth');
|
const auth = require('../../services/auth');
|
||||||
|
const log = require('../../services/log');
|
||||||
|
|
||||||
router.get('/', auth.checkApiAuth, async (req, res, next) => {
|
router.get('/', auth.checkApiAuth, async (req, res, next) => {
|
||||||
const notes = await sql.getResults("select "
|
const notes = await sql.getResults("select "
|
||||||
@ -24,33 +25,37 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
const notes_map = {};
|
const notes_map = {};
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
note['children'] = [];
|
note.children = [];
|
||||||
|
|
||||||
if (!note['note_pid']) {
|
if (!note.note_pid) {
|
||||||
root_notes.push(note);
|
root_notes.push(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
notes_map[note['note_id']] = note;
|
notes_map[note.note_id] = note;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
if (note['note_pid'] !== "") {
|
if (note.note_pid !== "") {
|
||||||
const parent = notes_map[note['note_pid']];
|
const parent = notes_map[note.note_pid];
|
||||||
|
|
||||||
parent['children'].push(note);
|
if (!parent) {
|
||||||
parent['folder'] = true;
|
log.error("Parent " + note.note_pid + ' has not been found');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
parent.children.push(note);
|
||||||
|
parent.folder = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
'notes': root_notes,
|
notes: root_notes,
|
||||||
'start_note_id': await options.getOption('start_node'),
|
start_note_id: await options.getOption('start_node'),
|
||||||
'password_verification_salt': await options.getOption('password_verification_salt'),
|
password_verification_salt: await options.getOption('password_verification_salt'),
|
||||||
'password_derived_key_salt': await options.getOption('password_derived_key_salt'),
|
password_derived_key_salt: await options.getOption('password_derived_key_salt'),
|
||||||
'encrypted_data_key': await options.getOption('encrypted_data_key'),
|
encrypted_data_key: await options.getOption('encrypted_data_key'),
|
||||||
'encryption_session_timeout': await options.getOption('encryption_session_timeout'),
|
encryption_session_timeout: await options.getOption('encryption_session_timeout'),
|
||||||
'browser_id': utils.randomString(12),
|
browser_id: utils.randomString(12),
|
||||||
'tree_load_time': utils.nowTimestamp()
|
tree_load_time: utils.nowTimestamp()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ async function createNewNote(parentNoteId, note, browserId) {
|
|||||||
|
|
||||||
await sql.doInTransaction(async () => {
|
await sql.doInTransaction(async () => {
|
||||||
await sql.addAudit(audit_category.CREATE_NOTE, browserId, noteId);
|
await sql.addAudit(audit_category.CREATE_NOTE, browserId, noteId);
|
||||||
|
await sql.addNoteTreeSync(noteId, browserId);
|
||||||
|
await sql.addNoteSync(noteId, browserId);
|
||||||
|
|
||||||
const now = utils.nowTimestamp();
|
const now = utils.nowTimestamp();
|
||||||
|
|
||||||
@ -127,25 +129,28 @@ async function updateNote(noteId, newNote, browserId) {
|
|||||||
await sql.insert("links", link);
|
await sql.insert("links", link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await sql.addNoteTreeSync(noteId);
|
||||||
await sql.addNoteSync(noteId);
|
await sql.addNoteSync(noteId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addNoteAudits(origNote, newNote, browserId) {
|
async function addNoteAudits(origNote, newNote, browserId) {
|
||||||
const noteId = origNote.note_id;
|
const noteId = newNote.note_id;
|
||||||
|
|
||||||
if (newNote.note_title !== origNote.note_title) {
|
if (!origNote || newNote.note_title !== origNote.note_title) {
|
||||||
await sql.deleteRecentAudits(audit_category.UPDATE_TITLE, browserId, noteId);
|
await sql.deleteRecentAudits(audit_category.UPDATE_TITLE, browserId, noteId);
|
||||||
await sql.addAudit(audit_category.UPDATE_TITLE, browserId, noteId);
|
await sql.addAudit(audit_category.UPDATE_TITLE, browserId, noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newNote.note_text !== origNote.note_text) {
|
if (!origNote || newNote.note_text !== origNote.note_text) {
|
||||||
await sql.deleteRecentAudits(audit_category.UPDATE_CONTENT, browserId, noteId);
|
await sql.deleteRecentAudits(audit_category.UPDATE_CONTENT, browserId, noteId);
|
||||||
await sql.addAudit(audit_category.UPDATE_CONTENT, browserId, noteId);
|
await sql.addAudit(audit_category.UPDATE_CONTENT, browserId, noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newNote.encryption !== origNote.encryption) {
|
if (!origNote || newNote.encryption !== origNote.encryption) {
|
||||||
await sql.addAudit(audit_category.ENCRYPTION, browserId, noteId, origNote.encryption, newNote.encryption);
|
const origEncryption = origNote ? origNote.encryption : null;
|
||||||
|
|
||||||
|
await sql.addAudit(audit_category.ENCRYPTION, browserId, noteId, origEncryption, newNote.encryption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +167,9 @@ async function deleteNote(noteId, browserId) {
|
|||||||
await sql.execute("update notes_tree set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
|
await sql.execute("update notes_tree set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
|
||||||
await sql.execute("update notes set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
|
await sql.execute("update notes set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
|
||||||
|
|
||||||
|
await sql.addNoteTreeSync(noteId, browserId);
|
||||||
|
await sql.addNoteSync(noteId, browserId);
|
||||||
|
|
||||||
await sql.addAudit(audit_category.DELETE_NOTE, browserId, noteId);
|
await sql.addAudit(audit_category.DELETE_NOTE, browserId, noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,8 +225,10 @@ async function sync() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let syncContext;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const syncContext = await login();
|
syncContext = await login();
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.message.indexOf('ECONNREFUSED') !== -1) {
|
if (e.message.indexOf('ECONNREFUSED') !== -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user