feat(edit-docs): preserve IDs when importing

This commit is contained in:
Elian Doran
2025-03-10 19:14:46 +02:00
parent 966ad36919
commit 841bc54f78
2 changed files with 11 additions and 5 deletions

View File

@@ -26,7 +26,11 @@ interface MetaFile {
files: NoteMeta[];
}
async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRootNote: BNote): Promise<BNote> {
interface ImportZipOpts {
preserveIds?: boolean;
}
async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRootNote: BNote, opts?: ImportZipOpts): Promise<BNote> {
/** maps from original noteId (in ZIP file) to newly generated noteId */
const noteIdMap: Record<string, string> = {};
/** type maps from original attachmentId (in ZIP file) to newly generated attachmentId */
@@ -45,7 +49,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo
return "empty_note_id";
}
if (origNoteId === "root" || origNoteId.startsWith("_")) {
if (origNoteId === "root" || origNoteId.startsWith("_") || opts?.preserveIds) {
// these "named" noteIds don't differ between Trilium instances
return origNoteId;
}
@@ -490,6 +494,10 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo
notePosition: noteMeta?.notePosition
}).save();
}
if (opts?.preserveIds) {
firstNote = firstNote || note;
}
} else {
({ note } = noteService.createNewNote({
parentNoteId: parentNoteId,