mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	sync fixes
This commit is contained in:
		
							
								
								
									
										1
									
								
								migrations/0035__root_notes_will_have_note_id_root.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								migrations/0035__root_notes_will_have_note_id_root.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | UPDATE notes_tree SET note_pid = 'root' WHERE note_pid = '' | ||||||
							
								
								
									
										1
									
								
								migrations/0036__clear_sync_table.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								migrations/0036__clear_sync_table.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | DELETE FROM sync; | ||||||
| @@ -13,7 +13,7 @@ router.put('/:noteId/moveTo/:parentId', auth.checkApiAuth, async (req, res, next | |||||||
|     let parentId = req.params.parentId; |     let parentId = req.params.parentId; | ||||||
|  |  | ||||||
|     const row = await sql.getSingleResult('select max(note_pos) as max_note_pos from notes_tree where note_pid = ? and is_deleted = 0', [parentId]); |     const row = await sql.getSingleResult('select max(note_pos) as max_note_pos from notes_tree where note_pid = ? and is_deleted = 0', [parentId]); | ||||||
|     const maxNotePos = row['max_note_pos']; |     const maxNotePos = row.max_note_pos; | ||||||
|     let newNotePos = 0; |     let newNotePos = 0; | ||||||
|  |  | ||||||
|     if (maxNotePos === null)  // no children yet |     if (maxNotePos === null)  // no children yet | ||||||
| @@ -44,16 +44,16 @@ router.put('/:noteId/moveBefore/:beforeNoteId', async (req, res, next) => { | |||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
|             // we don't change date_modified so other changes are prioritized in case of conflict |             // we don't change date_modified so other changes are prioritized in case of conflict | ||||||
|             await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos >= ? and is_deleted = 0", |             await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos >= ? and is_deleted = 0", | ||||||
|                 [beforeNote['note_pid'], beforeNote['note_pos']]); |                 [beforeNote.note_pid, beforeNote.note_pos]); | ||||||
|  |  | ||||||
|             const now = utils.nowTimestamp(); |             const now = utils.nowTimestamp(); | ||||||
|  |  | ||||||
|             await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?", |             await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?", | ||||||
|                 [beforeNote['note_pid'], beforeNote['note_pos'], now, noteId]); |                 [beforeNote.note_pid, beforeNote.note_pos, now, noteId]); | ||||||
|  |  | ||||||
|             await sync_table.addNoteTreeSync(noteId); |             await sync_table.addNoteTreeSync(noteId); | ||||||
|             await sync_table.addNoteReorderingSync(beforeNote['note_pid']); |             await sync_table.addNoteReorderingSync(beforeNote.note_pid); | ||||||
|             await sql.addAudit(audit_category.CHANGE_POSITION, utils.browserId(req), beforeNote['note_pid']); |             await sql.addAudit(audit_category.CHANGE_POSITION, utils.browserId(req), beforeNote.note_pid); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -70,16 +70,16 @@ router.put('/:noteId/moveAfter/:afterNoteId', async (req, res, next) => { | |||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
|             // we don't change date_modified so other changes are prioritized in case of conflict |             // we don't change date_modified so other changes are prioritized in case of conflict | ||||||
|             await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos > ? and is_deleted = 0", |             await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos > ? and is_deleted = 0", | ||||||
|                 [afterNote['note_pid'], afterNote['note_pos']]); |                 [afterNote.note_pid, afterNote.note_pos]); | ||||||
|  |  | ||||||
|             const now = utils.nowTimestamp(); |             const now = utils.nowTimestamp(); | ||||||
|  |  | ||||||
|             await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?", |             await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?", | ||||||
|                 [afterNote['note_pid'], afterNote['note_pos'] + 1, now, noteId]); |                 [afterNote.note_pid, afterNote.note_pos + 1, now, noteId]); | ||||||
|  |  | ||||||
|             await sync_table.addNoteTreeSync(noteId); |             await sync_table.addNoteTreeSync(noteId); | ||||||
|             await sync_table.addNoteReorderingSync(afterNote['note_pid']); |             await sync_table.addNoteReorderingSync(afterNote.note_pid); | ||||||
|             await sql.addAudit(audit_category.CHANGE_POSITION, utils.browserId(req), afterNote['note_pid']); |             await sql.addAudit(audit_category.CHANGE_POSITION, utils.browserId(req), afterNote.note_pid); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,7 +33,7 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => { | |||||||
|  |  | ||||||
|         note.children = []; |         note.children = []; | ||||||
|  |  | ||||||
|         if (!note.note_pid) { |         if (note.note_pid === "root") { | ||||||
|             root_notes.push(note); |             root_notes.push(note); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -41,7 +41,7 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (const note of notes) { |     for (const note of notes) { | ||||||
|         if (note.note_pid !== "") { |         if (note.note_pid !== "root") { | ||||||
|             const parent = notes_map[note.note_pid]; |             const parent = notes_map[note.note_pid]; | ||||||
|  |  | ||||||
|             if (!parent) { |             if (!parent) { | ||||||
|   | |||||||
| @@ -104,10 +104,6 @@ function decryptCbc(key, iv, cipherText) { | |||||||
|         return "[protected]"; |         return "[protected]"; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     console.log("key:", key); |  | ||||||
|     console.log("iv:", iv); |  | ||||||
|     console.log("cipherText:", cipherText); |  | ||||||
|  |  | ||||||
|     const decipher = crypto.createDecipheriv('aes-128-cbc', pad(key), pad(iv)); |     const decipher = crypto.createDecipheriv('aes-128-cbc', pad(key), pad(iv)); | ||||||
|  |  | ||||||
|     const cipherTextBuffer = Buffer.from(cipherText, 'base64'); |     const cipherTextBuffer = Buffer.from(cipherText, 'base64'); | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ const options = require('./options'); | |||||||
| const fs = require('fs-extra'); | const fs = require('fs-extra'); | ||||||
| const log = require('./log'); | const log = require('./log'); | ||||||
|  |  | ||||||
| const APP_DB_VERSION = 34; | const APP_DB_VERSION = 36; | ||||||
| const MIGRATIONS_DIR = "migrations"; | const MIGRATIONS_DIR = "migrations"; | ||||||
|  |  | ||||||
| async function migrate() { | async function migrate() { | ||||||
|   | |||||||
| @@ -9,10 +9,6 @@ const sync_table = require('./sync_table'); | |||||||
| async function createNewNote(parentNoteId, note, browserId) { | async function createNewNote(parentNoteId, note, browserId) { | ||||||
|     const noteId = utils.newNoteId(); |     const noteId = utils.newNoteId(); | ||||||
|  |  | ||||||
|     if (parentNoteId === "root") { |  | ||||||
|         parentNoteId = ""; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     let newNotePos = 0; |     let newNotePos = 0; | ||||||
|  |  | ||||||
|     if (note.target === 'into') { |     if (note.target === 'into') { | ||||||
|   | |||||||
| @@ -9,12 +9,15 @@ log.info("Using sourceId=" + currentSourceId); | |||||||
| let allSourceIds = []; | let allSourceIds = []; | ||||||
|  |  | ||||||
| sql.dbReady.then(async () => { | sql.dbReady.then(async () => { | ||||||
|     sql.insert("source_ids", { |     try { | ||||||
|         source_id: currentSourceId, |         sql.insert("source_ids", { | ||||||
|         date_created: utils.nowTimestamp() |             source_id: currentSourceId, | ||||||
|     }); |             date_created: utils.nowTimestamp() | ||||||
|  |         }); | ||||||
|  |  | ||||||
|     allSourceIds = await sql.getFlattenedResults("source_id", "SELECT source_id FROM source_ids"); |         allSourceIds = await sql.getFlattenedResults("source_id", "SELECT source_id FROM source_ids"); | ||||||
|  |     } | ||||||
|  |     catch (e) {} | ||||||
| }); | }); | ||||||
|  |  | ||||||
| function isLocalSourceId(srcId) { | function isLocalSourceId(srcId) { | ||||||
|   | |||||||
| @@ -113,6 +113,8 @@ async function pullSync(syncContext) { | |||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         console.log("Pulling ", sync); | ||||||
|  |  | ||||||
|         const resp = await syncRequest(syncContext, 'GET', "/api/sync/" + sync.entity_name + "/" + sync.entity_id); |         const resp = await syncRequest(syncContext, 'GET', "/api/sync/" + sync.entity_name + "/" + sync.entity_id); | ||||||
|  |  | ||||||
|         if (sync.entity_name === 'notes') { |         if (sync.entity_name === 'notes') { | ||||||
|   | |||||||
| @@ -10,8 +10,8 @@ async function addNoteTreeSync(noteId, sourceId) { | |||||||
|     await addEntitySync("notes_tree", noteId, sourceId) |     await addEntitySync("notes_tree", noteId, sourceId) | ||||||
| } | } | ||||||
|  |  | ||||||
| async function addNoteReorderingSync(noteId, sourceId) { | async function addNoteReorderingSync(parentNoteId, sourceId) { | ||||||
|     await addEntitySync("notes_reordering", noteId, sourceId) |     await addEntitySync("notes_reordering", parentNoteId, sourceId) | ||||||
| } | } | ||||||
|  |  | ||||||
| async function addNoteHistorySync(noteHistoryId, sourceId) { | async function addNoteHistorySync(noteHistoryId, sourceId) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user