mirror of
https://github.com/zadam/trilium.git
synced 2026-05-06 10:46:57 +02:00
fix(import/mime): importing a Markdown file with conversion to text disabled is treated as file instead of code
This commit is contained in:
@@ -123,6 +123,16 @@ describe("#getType", () => {
|
||||
[{textImportedAsText: false}, "text/x-markdown"], "file"
|
||||
],
|
||||
|
||||
[
|
||||
"w/ codeImportedAsCode: true and 'text/markdown' mime type (override) – it should return 'code'",
|
||||
[{codeImportedAsCode: true}, "text/markdown"], "code"
|
||||
],
|
||||
|
||||
[
|
||||
"w/ codeImportedAsCode: true and 'application/javascript' mime type (override) – it should return 'code'",
|
||||
[{codeImportedAsCode: true}, "application/javascript"], "code"
|
||||
],
|
||||
|
||||
[
|
||||
"w/ textImportedAsText: false and 'text/html' mime type – it should return 'file'",
|
||||
[{textImportedAsText: false}, "text/html"], "file"
|
||||
|
||||
@@ -97,7 +97,7 @@ function getType(options: TaskData<"importNotes">, mime: string): NoteType {
|
||||
case options?.textImportedAsText && ["text/html", "text/markdown", "text/x-markdown", "text/mdx"].includes(mimeLc):
|
||||
return "text";
|
||||
|
||||
case options?.codeImportedAsCode && CODE_MIME_TYPES.has(mimeLc):
|
||||
case options?.codeImportedAsCode && (CODE_MIME_TYPES.has(mimeLc) || CODE_MIME_TYPES_OVERRIDE.has(mimeLc)):
|
||||
return "code";
|
||||
|
||||
case mime.startsWith("image/"):
|
||||
|
||||
@@ -175,8 +175,12 @@ async function importZip(taskContext: TaskContext<"importNotes">, fileBuffer: Bu
|
||||
}
|
||||
|
||||
function detectFileTypeAndMime(taskContext: TaskContext<"importNotes">, filePath: string) {
|
||||
const mime = mimeService.getMime(filePath) || "application/octet-stream";
|
||||
const type = mimeService.getType(taskContext.data || {}, mime);
|
||||
const rawMime = mimeService.getMime(filePath) || "application/octet-stream";
|
||||
const type = mimeService.getType(taskContext.data || {}, rawMime);
|
||||
// Normalize aliased code MIMEs (e.g. `text/markdown` → `text/x-markdown`,
|
||||
// `application/javascript` → `application/javascript;env=frontend`) so the
|
||||
// stored MIME matches what the rest of the app expects.
|
||||
const mime = (type === "code" && mimeService.normalizeMimeType(rawMime)) || rawMime;
|
||||
|
||||
return { mime, type };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user