mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	fix problem with headers / source ids
This commit is contained in:
		
							parent
							
								
									9a0c2b6bcd
								
							
						
					
					
						commit
						669d189ab7
					
				| @ -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(); | ||||
|             } | ||||
|  | ||||
| @ -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 | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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(` | ||||
|  | ||||
| @ -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); | ||||
| 
 | ||||
|  | ||||
| @ -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; | ||||
| 
 | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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 = ?", | ||||
|  | ||||
| @ -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', { | ||||
|  | ||||
| @ -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']); | ||||
|  | ||||
| @ -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({}); | ||||
|  | ||||
| @ -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 () => { | ||||
|  | ||||
| @ -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({}); | ||||
|  | ||||
| @ -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]) | ||||
|  | ||||
| @ -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) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner