fix(import/mime): importing a Markdown file with conversion to text disabled is treated as file instead of code

This commit is contained in:
Elian Doran
2026-04-17 21:35:14 +03:00
parent 9ff466c9f5
commit 75b4877c87
3 changed files with 17 additions and 3 deletions

View File

@@ -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"

View 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/"):

View File

@@ -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 };
}