mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-13 04:13:19 +08:00
refactor(import/mime): simplify getMime
This commit is contained in:
parent
6a0edb68de
commit
4e59f58ce6
@ -48,39 +48,38 @@ const CODE_MIME_TYPES_OVERRIDE = new Map<string, string>([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// extensions missing in mime-db
|
// extensions missing in mime-db
|
||||||
const EXTENSION_TO_MIME: Record<string, string> = {
|
const EXTENSION_TO_MIME = new Map<string, string>([
|
||||||
".c": "text/x-csrc",
|
[".c", "text/x-csrc"],
|
||||||
".cs": "text/x-csharp",
|
[".cs", "text/x-csharp"],
|
||||||
".clj": "text/x-clojure",
|
[".clj", "text/x-clojure"],
|
||||||
".erl": "text/x-erlang",
|
[".erl", "text/x-erlang"],
|
||||||
".hrl": "text/x-erlang",
|
[".hrl", "text/x-erlang"],
|
||||||
".feature": "text/x-feature",
|
[".feature", "text/x-feature"],
|
||||||
".go": "text/x-go",
|
[".go", "text/x-go"],
|
||||||
".groovy": "text/x-groovy",
|
[".groovy", "text/x-groovy"],
|
||||||
".hs": "text/x-haskell",
|
[".hs", "text/x-haskell"],
|
||||||
".lhs": "text/x-haskell",
|
[".lhs", "text/x-haskell"],
|
||||||
".http": "message/http",
|
[".http", "message/http"],
|
||||||
".kt": "text/x-kotlin",
|
[".kt", "text/x-kotlin"],
|
||||||
".m": "text/x-objectivec",
|
[".m", "text/x-objectivec"],
|
||||||
".py": "text/x-python",
|
[".py", "text/x-python"],
|
||||||
".rb": "text/x-ruby",
|
[".rb", "text/x-ruby"],
|
||||||
".scala": "text/x-scala",
|
[".scala", "text/x-scala"],
|
||||||
".swift": "text/x-swift"
|
[".swift", "text/x-swift"]
|
||||||
};
|
]);
|
||||||
|
|
||||||
/** @returns false if MIME is not detected */
|
/** @returns false if MIME is not detected */
|
||||||
function getMime(fileName: string) {
|
function getMime(fileName: string) {
|
||||||
if (fileName.toLowerCase() === "dockerfile") {
|
const fileNameLc = fileName?.toLowerCase();
|
||||||
|
|
||||||
|
if (fileNameLc === "dockerfile") {
|
||||||
return "text/x-dockerfile";
|
return "text/x-dockerfile";
|
||||||
}
|
}
|
||||||
|
|
||||||
const ext = path.extname(fileName).toLowerCase();
|
const ext = path.extname(fileNameLc);
|
||||||
|
const mimeFromExt = EXTENSION_TO_MIME.get(ext);
|
||||||
|
|
||||||
if (ext in EXTENSION_TO_MIME) {
|
return mimeFromExt || mimeTypes.lookup(fileNameLc);
|
||||||
return EXTENSION_TO_MIME[ext];
|
|
||||||
}
|
|
||||||
|
|
||||||
return mimeTypes.lookup(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getType(options: TaskData, mime: string) {
|
function getType(options: TaskData, mime: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user