Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): download what "open externally" cannot preview
Elian Doran327ef2b1daed
diff --git a/apps/client/src/services/open.spec.ts b/apps/client/src/services/open.spec.tsindex ba856d9eb2..820e47488d 100644--- a/apps/client/src/services/open.spec.ts+++ b/apps/client/src/services/open.spec.ts@@ -192,6 +192,18 @@ describe("open service", () => {expect(window.location.href).toContain("api/attachments/a3/download");});+ it("routes a non-previewable open through the mobile share sheet", async () => {+ // Navigating to the attachment response would be dropped there, like any download.+ const saveUrl = vi.fn(async () => ({ status: "saved" as const, fileName: "a.zip" }));+ realWindow.standaloneApi = { save: { saveUrl } };++ await open.openAttachmentExternally("a5", "application/zip");++ await vi.waitFor(() => expect(saveUrl).toHaveBeenCalledWith(+ expect.stringContaining("api/attachments/a5/download")+ ));+ });+it("covers all canOpenInBrowser branches (image/audio/video)", async () => {await openNoteExternally("img", "image/jpeg");expect(window.open).toHaveBeenLastCalledWith("api/notes/img/open");diff --git a/apps/client/src/services/open.ts b/apps/client/src/services/open.tsindex 3506a70b1a..0a94bc6c4d 100644--- a/apps/client/src/services/open.ts+++ b/apps/client/src/services/open.ts@@ -112,7 +112,9 @@ async function openExternally(type: string, entityId: string, mime: string) {if (canOpenInBrowser(mime)) {window.open(getOpenFileUrl(type, entityId));} else {- window.location.href = getFileUrl(type, entityId);+ // What cannot be previewed is downloaded, which on mobile means the share sheet:+ // navigating to the attachment response would be dropped there (see download()).+ download(getFileUrl(type, entityId));}}}