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(export/share): use right extension for images
Elian Doranfded714f18ff
diff --git a/apps/server/src/services/export/zip.ts b/apps/server/src/services/export/zip.tsindex 1bfc1e8423..10b84abce8 100644--- a/apps/server/src/services/export/zip.ts+++ b/apps/server/src/services/export/zip.ts@@ -23,6 +23,7 @@ import { AdvancedExportOptions, type ExportFormat, ZipExportProviderData } fromimport MarkdownExportProvider from "./zip/markdown.js";import ShareThemeExportProvider from "./zip/share_theme.js";import type BNote from "../../becca/entities/bnote.js";+import { NoteType } from "@triliumnext/commons";async function exportToZip(taskContext: TaskContext, branch: BBranch, format: ExportFormat, res: Response | fs.WriteStream, setHeaders = true, zipExportOptions?: AdvancedExportOptions) {if (!["html", "markdown", "share"].includes(format)) {@@ -77,7 +78,7 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: Ex}}- function getDataFileName(type: string | null, mime: string, baseFileName: string, existingFileNames: Record<string, number>): string {+ function getDataFileName(type: NoteType | null, mime: string, baseFileName: string, existingFileNames: Record<string, number>): string {let fileName = baseFileName.trim();// Crop fileName to avoid its length exceeding 30 and prevent cutting into the extension.diff --git a/apps/server/src/services/export/zip/abstract_provider.ts b/apps/server/src/services/export/zip/abstract_provider.tsindex f777ed1cbb..c9645a8437 100644--- a/apps/server/src/services/export/zip/abstract_provider.ts+++ b/apps/server/src/services/export/zip/abstract_provider.ts@@ -3,6 +3,7 @@ import type { default as NoteMeta, NoteMetaFile } from "../../meta/note_meta.js"import type BNote from "../../../becca/entities/bnote.js";import type BBranch from "../../../becca/entities/bbranch.js";import mimeTypes from "mime-types";+import { NoteType } from "@triliumnext/commons";type RewriteLinksFn = (content: string, noteMeta: NoteMeta) => string;@@ -51,7 +52,16 @@ export abstract class ZipExportProvider {abstract prepareContent(title: string, content: string | Buffer, noteMeta: NoteMeta, note: BNote | undefined, branch: BBranch): string | Buffer;abstract afterDone(rootMeta: NoteMeta): void;- mapExtension(type: string | null, mime: string, existingExtension: string, format: ExportFormat) {+ /**+ * Determines the extension of the resulting file for a specific note type.+ *+ * @param type the type of the note.+ * @param mime the mime type of the note.+ * @param existingExtension the existing extension, including the leading period character.+ * @param format the format requested for export (e.g. HTML, Markdown).+ * @returns an extension *without* the leading period character, or `null` to preserve the existing extension instead.+ */+ mapExtension(type: NoteType | null, mime: string, existingExtension: string, format: ExportFormat) {// the following two are handled specifically since we always want to have these extensions no matter the automatic detection// and/or existing detected extensions in the note nameif (type === "text" && format === "markdown") {diff --git a/apps/server/src/services/export/zip/share_theme.ts b/apps/server/src/services/export/zip/share_theme.tsindex 03bdb68b4d..06609b0313 100644--- a/apps/server/src/services/export/zip/share_theme.ts+++ b/apps/server/src/services/export/zip/share_theme.ts@@ -1,6 +1,6 @@import { join } from "path";import NoteMeta, { NoteMetaFile } from "../../meta/note_meta";-import { ZipExportProvider } from "./abstract_provider.js";+import { ExportFormat, ZipExportProvider } from "./abstract_provider.js";import { RESOURCE_DIR } from "../../resource_dir";import { getResourceDir, isDev } from "../../utils";import fs from "fs";@@ -65,6 +65,14 @@ export default class ShareThemeExportProvider extends ZipExportProvider {this.#saveIndex(rootMeta);}+ mapExtension(type: string | null, mime: string, existingExtension: string, format: ExportFormat): string | null {+ if (mime.startsWith("image/")) {+ return null;+ }++ return "html";+ }+#saveIndex(rootMeta: NoteMeta) {if (!this.indexMeta?.dataFileName) {return;