Skip to content

Build your personal knowledge base with Trilium Notes

fix problem with headers / source ids

azivner669d189ab77d
diff --git a/public/javascripts/messaging.js b/public/javascripts/messaging.js
index 415047e602..704d1bf1d3 100644
--- a/public/javascripts/messaging.js
+++ b/public/javascripts/messaging.js
@@ -38,7 +38,7 @@ const messaging = (function() {
}
if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === noteEditor.getCurrentNoteId())) {
- showMessage('Reloading note because background change');
+ showMessage('Reloading note because of background changes');
noteEditor.reload();
}
diff --git a/public/javascripts/server.js b/public/javascripts/server.js
index a6b7d531c5..3bdfbd4f1f 100644
--- a/public/javascripts/server.js
+++ b/public/javascripts/server.js
@@ -7,9 +7,11 @@ const server = (function() {
}
catch(e) {}
+ // headers need to be lowercase because node.js automatically converts them to lower case
+ // so hypothetical protectedSessionId becomes protectedsessionid on the backend
return {
protected_session_id: protectedSessionId,
- sourceId: glob.sourceId
+ source_id: glob.sourceId
};
}
diff --git a/routes/api/cleanup.js b/routes/api/cleanup.js
index c52f3d24b3..cc04c35443 100644
--- a/routes/api/cleanup.js
+++ b/routes/api/cleanup.js
@@ -46,7 +46,7 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, wrap(async (req, r
}));
router.post('/cleanup-unused-images', auth.checkApiAuth, wrap(async (req, res, next) => {
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
await sql.doInTransaction(async () => {
const unusedImageIds = await sql.getFirstColumn(`
diff --git a/routes/api/cloning.js b/routes/api/cloning.js
index e8d6bc509d..c3849ca200 100644
--- a/routes/api/cloning.js
+++ b/routes/api/cloning.js
@@ -13,7 +13,7 @@ router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, wrap(async
const parentNoteId = req.params.parentNoteId;
const childNoteId = req.params.childNoteId;
const prefix = req.body.prefix;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
if (!await tree.validateParentChild(res, parentNoteId, childNoteId)) {
return;
@@ -47,7 +47,7 @@ router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, wrap(async
router.put('/:noteId/clone-after/:afterNoteTreeId', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteId = req.params.noteId;
const afterNoteTreeId = req.params.afterNoteTreeId;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const afterNote = await tree.getNoteTree(afterNoteTreeId);
diff --git a/routes/api/image.js b/routes/api/image.js
index 9d6a52b6d8..c911fa2cf8 100644
--- a/routes/api/image.js
+++ b/routes/api/image.js
@@ -35,7 +35,7 @@ router.get('/:imageId/:filename', auth.checkApiAuthOrElectron, wrap(async (req,
}));
router.post('', auth.checkApiAuthOrElectron, multer.single('upload'), wrap(async (req, res, next) => {
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const noteId = req.query.noteId;
const file = req.file;
diff --git a/routes/api/note_history.js b/routes/api/note_history.js
index fcbb7a362e..36dd6ca0bf 100644
--- a/routes/api/note_history.js
+++ b/routes/api/note_history.js
@@ -17,7 +17,7 @@ router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
}));
router.put('', auth.checkApiAuth, wrap(async (req, res, next) => {
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
await sql.doInTransaction(async () => {
await sql.replace("note_revisions", req.body);
diff --git a/routes/api/notes.js b/routes/api/notes.js
index 1124a109d4..90f0c17dbd 100644
--- a/routes/api/notes.js
+++ b/routes/api/notes.js
@@ -31,7 +31,7 @@ router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
}));
router.post('/:parentNoteId/children', auth.checkApiAuth, wrap(async (req, res, next) => {
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const parentNoteId = req.params.parentNoteId;
const newNote = req.body;
@@ -49,7 +49,7 @@ router.post('/:parentNoteId/children', auth.checkApiAuth, wrap(async (req, res,
router.put('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
const note = req.body;
const noteId = req.params.noteId;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const dataKey = protected_session.getDataKey(req);
await notes.updateNote(noteId, note, dataKey, sourceId);
@@ -69,7 +69,7 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
router.put('/:noteId/sort', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteId = req.params.noteId;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const dataKey = protected_session.getDataKey(req);
await tree.sortNotesAlphabetically(noteId, dataKey, sourceId);
@@ -81,7 +81,7 @@ router.put('/:noteId/protect-sub-tree/:isProtected', auth.checkApiAuth, wrap(asy
const noteId = req.params.noteId;
const isProtected = !!parseInt(req.params.isProtected);
const dataKey = protected_session.getDataKey(req);
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
await sql.doInTransaction(async () => {
await notes.protectNoteRecursively(noteId, dataKey, isProtected, sourceId);
@@ -94,7 +94,7 @@ router.put(/\/(.*)\/type\/(.*)\/mime\/(.*)/, auth.checkApiAuth, wrap(async (req,
const noteId = req.params[0];
const type = req.params[1];
const mime = req.params[2];
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
await sql.doInTransaction(async () => {
await sql.execute("UPDATE notes SET type = ?, mime = ?, dateModified = ? WHERE noteId = ?",
diff --git a/routes/api/recent_notes.js b/routes/api/recent_notes.js
index 3f946d63c7..3e7985e38d 100644
--- a/routes/api/recent_notes.js
+++ b/routes/api/recent_notes.js
@@ -16,7 +16,7 @@ router.get('', auth.checkApiAuth, wrap(async (req, res, next) => {
router.put('/:noteTreeId/:notePath', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteTreeId = req.params.noteTreeId;
const notePath = req.params.notePath;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
await sql.doInTransaction(async () => {
await sql.replace('recent_notes', {
diff --git a/routes/api/settings.js b/routes/api/settings.js
index 215dd7c099..210a3ff637 100644
--- a/routes/api/settings.js
+++ b/routes/api/settings.js
@@ -25,7 +25,7 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
router.post('/', auth.checkApiAuth, wrap(async (req, res, next) => {
const body = req.body;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
if (ALLOWED_OPTIONS.includes(body['name'])) {
const optionName = await options.getOption(body['name']);
diff --git a/routes/api/sync.js b/routes/api/sync.js
index 0491c9cbb4..d8b094d887 100644
--- a/routes/api/sync.js
+++ b/routes/api/sync.js
@@ -109,7 +109,7 @@ router.get('/options/:name', auth.checkApiAuth, wrap(async (req, res, next) => {
}
}));
-router.get('/notes_reordering/:parentNoteId', auth.checkApiAuth, wrap(async (req, res, next) => {
+router.get('/note_reordering/:parentNoteId', auth.checkApiAuth, wrap(async (req, res, next) => {
const parentNoteId = req.params.parentNoteId;
res.send({
@@ -165,7 +165,7 @@ router.put('/note_revisions', auth.checkApiAuth, wrap(async (req, res, next) =>
res.send({});
}));
-router.put('/notes_reordering', auth.checkApiAuth, wrap(async (req, res, next) => {
+router.put('/note_reordering', auth.checkApiAuth, wrap(async (req, res, next) => {
await syncUpdate.updateNoteReordering(req.body.entity, req.body.sourceId);
res.send({});
diff --git a/routes/api/tree.js b/routes/api/tree.js
index 03e1f7dfa3..edf2ab8f79 100644
--- a/routes/api/tree.js
+++ b/routes/api/tree.js
@@ -37,7 +37,7 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
router.put('/:noteTreeId/set-prefix', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteTreeId = req.params.noteTreeId;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix;
await sql.doInTransaction(async () => {
diff --git a/routes/api/tree_changes.js b/routes/api/tree_changes.js
index 7867159c1f..173979db79 100644
--- a/routes/api/tree_changes.js
+++ b/routes/api/tree_changes.js
@@ -18,7 +18,7 @@ const wrap = require('express-promise-wrap').wrap;
router.put('/:noteTreeId/move-to/:parentNoteId', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteTreeId = req.params.noteTreeId;
const parentNoteId = req.params.parentNoteId;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const noteToMove = await tree.getNoteTree(noteTreeId);
@@ -44,7 +44,7 @@ router.put('/:noteTreeId/move-to/:parentNoteId', auth.checkApiAuth, wrap(async (
router.put('/:noteTreeId/move-before/:beforeNoteTreeId', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteTreeId = req.params.noteTreeId;
const beforeNoteTreeId = req.params.beforeNoteTreeId;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const noteToMove = await tree.getNoteTree(noteTreeId);
const beforeNote = await tree.getNoteTree(beforeNoteTreeId);
@@ -75,7 +75,7 @@ router.put('/:noteTreeId/move-before/:beforeNoteTreeId', auth.checkApiAuth, wrap
router.put('/:noteTreeId/move-after/:afterNoteTreeId', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteTreeId = req.params.noteTreeId;
const afterNoteTreeId = req.params.afterNoteTreeId;
- const sourceId = req.headers.sourceId;
+ const sourceId = req.headers.source_id;
const noteToMove = await tree.getNoteTree(noteTreeId);
const afterNote = await tree.getNoteTree(afterNoteTreeId);
@@ -116,7 +116,7 @@ router.put('/:noteTreeId/expanded/:expanded', auth.checkApiAuth, wrap(async (req
router.delete('/:noteTreeId', auth.checkApiAuth, wrap(async (req, res, next) => {
await sql.doInTransaction(async () => {
- await notes.deleteNote(req.params.noteTreeId, req.headers.sourceId);
+ await notes.deleteNote(req.params.noteTreeId, req.headers.source_id);
});
res.send({});
diff --git a/services/sync.js b/services/sync.js
index d83ec33397..ef5ece7a1c 100644
--- a/services/sync.js
+++ b/services/sync.js
@@ -131,7 +131,7 @@ async function pullSync(syncContext) {
else if (sync.entityName === 'note_revisions') {
await syncUpdate.updateNoteHistory(resp, syncContext.sourceId);
}
- else if (sync.entityName === 'notes_reordering') {
+ else if (sync.entityName === 'note_reordering') {
await syncUpdate.updateNoteReordering(resp, syncContext.sourceId);
}
else if (sync.entityName === 'options') {
@@ -208,7 +208,7 @@ async function pushEntity(sync, syncContext) {
else if (sync.entityName === 'note_revisions') {
entity = await sql.getFirst('SELECT * FROM note_revisions WHERE noteRevisionId = ?', [sync.entityId]);
}
- else if (sync.entityName === 'notes_reordering') {
+ else if (sync.entityName === 'note_reordering') {
entity = {
parentNoteId: sync.entityId,
ordering: await sql.getMap('SELECT noteTreeId, notePosition FROM note_tree WHERE parentNoteId = ? AND isDeleted = 0', [sync.entityId])
diff --git a/services/sync_table.js b/services/sync_table.js
index 33c6bde47a..e4ea0944f5 100644
--- a/services/sync_table.js
+++ b/services/sync_table.js
@@ -12,8 +12,8 @@ async function addNoteTreeSync(noteTreeId, sourceId) {
await addEntitySync("note_tree", noteTreeId, sourceId)
}
-async function addNoteReorderingSync(parentNoteTreeId, sourceId) {
- await addEntitySync("notes_reordering", parentNoteTreeId, sourceId)
+async function addNoteReorderingSync(parentNoteId, sourceId) {
+ await addEntitySync("note_reordering", parentNoteId, sourceId)
}
async function addNoteHistorySync(noteRevisionId, sourceId) {