mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	feat(edit-docs): preserve IDs when importing
This commit is contained in:
		@@ -42,8 +42,6 @@ async function importData(input: Buffer) {
 | 
				
			|||||||
    const notes = ((await import("./src/services/notes.js")).default);
 | 
					    const notes = ((await import("./src/services/notes.js")).default);
 | 
				
			||||||
    beccaLoader.load();
 | 
					    beccaLoader.load();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const becca = ((await import("./src/becca/becca.js")).default);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const { note } = notes.createNewNoteWithTarget("into", "none_root", {
 | 
					    const { note } = notes.createNewNoteWithTarget("into", "none_root", {
 | 
				
			||||||
        parentNoteId: "root",
 | 
					        parentNoteId: "root",
 | 
				
			||||||
        noteId: NOTE_ID_USER_GUIDE,
 | 
					        noteId: NOTE_ID_USER_GUIDE,
 | 
				
			||||||
@@ -55,7 +53,7 @@ async function importData(input: Buffer) {
 | 
				
			|||||||
    const TaskContext = (await import("./src/services/task_context.js")).default;
 | 
					    const TaskContext = (await import("./src/services/task_context.js")).default;
 | 
				
			||||||
    const { importZip } = ((await import("./src/services/import/zip.js")).default);
 | 
					    const { importZip } = ((await import("./src/services/import/zip.js")).default);
 | 
				
			||||||
    const context = new TaskContext("no-report");
 | 
					    const context = new TaskContext("no-report");
 | 
				
			||||||
    await importZip(context, input, note);
 | 
					    await importZip(context, input, note, { preserveIds: true });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function createImportZip() {
 | 
					async function createImportZip() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,11 @@ interface MetaFile {
 | 
				
			|||||||
    files: NoteMeta[];
 | 
					    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 */
 | 
					    /** maps from original noteId (in ZIP file) to newly generated noteId */
 | 
				
			||||||
    const noteIdMap: Record<string, string> = {};
 | 
					    const noteIdMap: Record<string, string> = {};
 | 
				
			||||||
    /** type maps from original attachmentId (in ZIP file) to newly generated attachmentId */
 | 
					    /** 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";
 | 
					            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
 | 
					            // these "named" noteIds don't differ between Trilium instances
 | 
				
			||||||
            return origNoteId;
 | 
					            return origNoteId;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -490,6 +494,10 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo
 | 
				
			|||||||
                    notePosition: noteMeta?.notePosition
 | 
					                    notePosition: noteMeta?.notePosition
 | 
				
			||||||
                }).save();
 | 
					                }).save();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (opts?.preserveIds) {
 | 
				
			||||||
 | 
					                firstNote = firstNote || note;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            ({ note } = noteService.createNewNote({
 | 
					            ({ note } = noteService.createNewNote({
 | 
				
			||||||
                parentNoteId: parentNoteId,
 | 
					                parentNoteId: parentNoteId,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user