Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/zip): improve geomap compatibility

Elian Dorana563330136e4
diff --git a/apps/server/src/services/import/samples/geomap.zip b/apps/server/src/services/import/samples/geomap.zip
new file mode 100644
index 0000000000..6443c19971
Binary files /dev/null and b/apps/server/src/services/import/samples/geomap.zip differ
diff --git a/apps/server/src/services/import/zip.spec.ts b/apps/server/src/services/import/zip.spec.ts
index 4860f7b94c..db2c7ba76e 100644
--- a/apps/server/src/services/import/zip.spec.ts
+++ b/apps/server/src/services/import/zip.spec.ts
@@ -70,6 +70,19 @@ describe("processNoteContent", () => {
expect(content).toContain(`<a class="reference-link" href="#root/${shopNote.noteId}`);
expect(content).toContain(`<img src="api/images/${bananaNote!.noteId}/banana.jpeg`);
});
+
+ it("can import old geomap notes", async () => {
+ const { importedNote } = await testImport("geomap.zip");
+ expect(importedNote.type).toBe("book");
+ expect(importedNote.mime).toBe("");
+ expect(importedNote.getRelationValue("template")).toBe("_template_geo_map");
+
+ const attachment = importedNote.getAttachmentsByRole("viewConfig")[0];
+ expect(attachment.title).toBe("geoMap.json");
+ expect(attachment.mime).toBe("application/json");
+ const content = attachment.getContent();
+ expect(content).toStrictEqual(`{"view":{"center":{"lat":49.19598332223546,"lng":-2.1414576506668808},"zoom":12}}`);
+ });
});
function getNoteByTitlePath(parentNote: BNote, ...titlePath: string[]) {
diff --git a/apps/server/src/services/import/zip.ts b/apps/server/src/services/import/zip.ts
index 67deb10562..b2d83bdc69 100644
--- a/apps/server/src/services/import/zip.ts
+++ b/apps/server/src/services/import/zip.ts
@@ -502,6 +502,28 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo
firstNote = firstNote || note;
}
} else {
+ if (detectedType as string === "geoMap") {
+ attributes.push({
+ noteId,
+ type: "relation",
+ name: "template",
+ value: "_template_geo_map"
+ });
+
+ const attachment = new BAttachment({
+ attachmentId: getNewAttachmentId(newEntityId()),
+ ownerId: noteId,
+ title: "geoMap.json",
+ role: "viewConfig",
+ mime: "application/json",
+ position: 0
+ });
+
+ attachment.setContent(content, { forceSave: true });
+ content = "";
+ mime = "";
+ }
+
({ note } = noteService.createNewNote({
parentNoteId: parentNoteId,
title: noteTitle || "",