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
refactor(import/mime): simplify getMime
Panagiotis Papadopoulos4e59f58ce683
diff --git a/src/services/import/mime.ts b/src/services/import/mime.tsindex a1b0925564..9930c9010d 100644--- a/src/services/import/mime.ts+++ b/src/services/import/mime.ts@@ -48,39 +48,38 @@ const CODE_MIME_TYPES_OVERRIDE = new Map<string, string>([]);// extensions missing in mime-db-const EXTENSION_TO_MIME: Record<string, string> = {- ".c": "text/x-csrc",- ".cs": "text/x-csharp",- ".clj": "text/x-clojure",- ".erl": "text/x-erlang",- ".hrl": "text/x-erlang",- ".feature": "text/x-feature",- ".go": "text/x-go",- ".groovy": "text/x-groovy",- ".hs": "text/x-haskell",- ".lhs": "text/x-haskell",- ".http": "message/http",- ".kt": "text/x-kotlin",- ".m": "text/x-objectivec",- ".py": "text/x-python",- ".rb": "text/x-ruby",- ".scala": "text/x-scala",- ".swift": "text/x-swift"-};+const EXTENSION_TO_MIME = new Map<string, string>([+ [".c", "text/x-csrc"],+ [".cs", "text/x-csharp"],+ [".clj", "text/x-clojure"],+ [".erl", "text/x-erlang"],+ [".hrl", "text/x-erlang"],+ [".feature", "text/x-feature"],+ [".go", "text/x-go"],+ [".groovy", "text/x-groovy"],+ [".hs", "text/x-haskell"],+ [".lhs", "text/x-haskell"],+ [".http", "message/http"],+ [".kt", "text/x-kotlin"],+ [".m", "text/x-objectivec"],+ [".py", "text/x-python"],+ [".rb", "text/x-ruby"],+ [".scala", "text/x-scala"],+ [".swift", "text/x-swift"]+]);/** @returns false if MIME is not detected */function getMime(fileName: string) {- if (fileName.toLowerCase() === "dockerfile") {+ const fileNameLc = fileName?.toLowerCase();++ if (fileNameLc === "dockerfile") {return "text/x-dockerfile";}- const ext = path.extname(fileName).toLowerCase();-- if (ext in EXTENSION_TO_MIME) {- return EXTENSION_TO_MIME[ext];- }+ const ext = path.extname(fileNameLc);+ const mimeFromExt = EXTENSION_TO_MIME.get(ext);- return mimeTypes.lookup(fileName);+ return mimeFromExt || mimeTypes.lookup(fileNameLc);}function getType(options: TaskData, mime: string) {