mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 15:55:52 +01:00
restore revision with attachments
This commit is contained in:
@@ -95,11 +95,27 @@ function restoreNoteRevision(req) {
|
||||
if (noteRevision) {
|
||||
const note = noteRevision.getNote();
|
||||
|
||||
note.saveNoteRevision();
|
||||
sql.transactional(() => {
|
||||
note.saveNoteRevision();
|
||||
|
||||
note.title = noteRevision.title;
|
||||
note.setContent(noteRevision.getContent());
|
||||
note.save();
|
||||
for (const oldNoteAttachment of note.getAttachments()) {
|
||||
oldNoteAttachment.markAsDeleted();
|
||||
}
|
||||
|
||||
let revisionContent = noteRevision.getContent();
|
||||
|
||||
for (const revisionAttachment of noteRevision.getAttachments()) {
|
||||
const noteAttachment = revisionAttachment.copy();
|
||||
noteAttachment.parentId = note.noteId;
|
||||
noteAttachment.setContent(revisionAttachment.getContent(), { forceSave: true });
|
||||
|
||||
// content is rewritten to point to the restored revision attachments
|
||||
revisionContent = revisionContent.replaceAll(`attachments/${revisionAttachment.attachmentId}`, `attachments/${noteAttachment.attachmentId}`);
|
||||
}
|
||||
|
||||
note.title = noteRevision.title;
|
||||
note.setContent(revisionContent, { forceSave: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user