mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	fix saving history for encrypted notes
This commit is contained in:
		
							parent
							
								
									6fad30e9af
								
							
						
					
					
						commit
						b81f1ed93a
					
				| @ -81,6 +81,12 @@ async function protectNoteRecursively(noteId, dataKey, protect) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function decryptNote(note, dataKey) { | ||||
|     note.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(note.note_id), note.note_title); | ||||
|     note.note_text = data_encryption.decryptString(dataKey, data_encryption.noteTextIv(note.note_id), note.note_text); | ||||
|     note.is_protected = false; | ||||
| } | ||||
| 
 | ||||
| async function protectNote(note, dataKey, protect) { | ||||
|     let changed = false; | ||||
| 
 | ||||
| @ -92,9 +98,7 @@ async function protectNote(note, dataKey, protect) { | ||||
|         changed = true; | ||||
|     } | ||||
|     else if (!protect && note.is_protected) { | ||||
|         note.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(note.note_id), note.note_title); | ||||
|         note.note_text = data_encryption.decryptString(dataKey, data_encryption.noteTextIv(note.note_id), note.note_text); | ||||
|         note.is_protected = false; | ||||
|         decryptNote(note, dataKey); | ||||
| 
 | ||||
|         changed = true; | ||||
|     } | ||||
| @ -150,14 +154,19 @@ async function updateNote(noteId, newNote, ctx) { | ||||
|         if (!existingNoteHistoryId && (now - newNote.detail.date_created) >= historySnapshotTimeInterval) { | ||||
|             const oldNote = await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]); | ||||
| 
 | ||||
|             if (oldNote.is_protected) { | ||||
|                 decryptNote(oldNote, ctx.getDataKey()); | ||||
|             } | ||||
| 
 | ||||
|             const newNoteHistoryId = utils.newNoteHistoryId(); | ||||
| 
 | ||||
|             await sql.insert('notes_history', { | ||||
|                 note_history_id: newNoteHistoryId, | ||||
|                 note_id: noteId, | ||||
|                 // title and text should be decrypted now
 | ||||
|                 note_title: oldNote.note_title, | ||||
|                 note_text: oldNote.note_text, | ||||
|                 is_protected: oldNote.is_protected, | ||||
|                 is_protected: 0, // will be fixed in the protectNoteHistory() call
 | ||||
|                 date_modified_from: oldNote.date_modified, | ||||
|                 date_modified_to: now | ||||
|             }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner