mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-31 23:11:28 +01:00
Mimetype Quick Fixes (#359)
This commit is contained in:
parent
5fe0cae244
commit
04fb8e5aad
@ -44,16 +44,37 @@ const SpecializedViewMap: { [view: string]: ({ model }: SpecializedViewProps) =>
|
||||
directory: DirectoryPreview,
|
||||
};
|
||||
|
||||
const textApplicationMimetypes = [
|
||||
"application/sql",
|
||||
"application/pem-certificate-chain",
|
||||
"application/x-php",
|
||||
"application/x-httpd-php",
|
||||
"application/liquid",
|
||||
"application/graphql",
|
||||
"application/javascript",
|
||||
"application/typescript",
|
||||
"application/x-javascript",
|
||||
"application/x-typescript",
|
||||
"application/dart",
|
||||
"application/vnd.dart",
|
||||
"application/x-ruby",
|
||||
"application/sql",
|
||||
"application/wasm",
|
||||
"application/x-latex",
|
||||
"application/x-sh",
|
||||
"application/x-python",
|
||||
];
|
||||
|
||||
function isTextFile(mimeType: string): boolean {
|
||||
if (mimeType == null) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
mimeType.startsWith("text/") ||
|
||||
mimeType == "application/sql" ||
|
||||
textApplicationMimetypes.includes(mimeType) ||
|
||||
(mimeType.startsWith("application/") &&
|
||||
(mimeType.includes("json") || mimeType.includes("yaml") || mimeType.includes("toml"))) ||
|
||||
mimeType == "application/pem-certificate-chain"
|
||||
mimeType.includes("xml")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,8 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".gpkg": "application/geopackage+sqlite3",
|
||||
".glbin": "application/gltf-buffer",
|
||||
".gml": "application/gml+xml",
|
||||
".gql": "application/graphql",
|
||||
".graphql": "application/graphql",
|
||||
".gz": "application/gzip",
|
||||
".hta": "application/hta",
|
||||
".stk": "application/hyperstudio",
|
||||
@ -86,6 +88,7 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".jsonld": "application/ld+json",
|
||||
".lgr": "application/lgr+xml",
|
||||
".wlnk": "application/link-format",
|
||||
".liquid": "application/liquid",
|
||||
".lostxml": "application/lost+xml",
|
||||
".lostsyncxml": "application/lostsync+xml",
|
||||
".lpf": "application/lpf+zip",
|
||||
@ -183,7 +186,6 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".soc": "application/sgml-open-catalog",
|
||||
".shf": "application/shf+xml",
|
||||
".siv": "application/sieve",
|
||||
".cl": "application/simple-filter+xml",
|
||||
".smil": "application/smil+xml",
|
||||
".rq": "application/sparql-query",
|
||||
".srx": "application/sparql-results+xml",
|
||||
@ -310,7 +312,6 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".cryptomator": "application/vnd.cryptomator.vault",
|
||||
".pml": "application/vnd.ctc-posml",
|
||||
".ppd": "application/vnd.cups-ppd",
|
||||
".dart": "application/vnd.dart",
|
||||
".rdz": "application/vnd.data-vision.rdz",
|
||||
".dl": "application/vnd.datalog",
|
||||
".dbf": "application/vnd.dbf",
|
||||
@ -413,7 +414,6 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".emm": "application/vnd.ibm.electronic-media",
|
||||
".mpy": "application/vnd.ibm.MiniPay",
|
||||
".irm": "application/vnd.ibm.rights-management",
|
||||
".sc": "application/vnd.ibm.secure-container",
|
||||
".icc": "application/vnd.iccprofile",
|
||||
".1905.1": "application/vnd.ieee.1905",
|
||||
".igl": "application/vnd.igloader",
|
||||
@ -463,7 +463,6 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".prz": "application/vnd.lotus-freelance",
|
||||
".nsf": "application/vnd.lotus-notes",
|
||||
".or3": "application/vnd.lotus-organizer",
|
||||
".scm": "application/vnd.lotus-screencam",
|
||||
".lwp": "application/vnd.lotus-wordpro",
|
||||
".portpkg": "application/vnd.macports.portpkg",
|
||||
".mvt": "application/vnd.mapbox-vector-tile",
|
||||
@ -717,7 +716,6 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".wsc": "application/vnd.wfa.wsc",
|
||||
".wmc": "application/vnd.wmc",
|
||||
".nb": "application/vnd.wolfram.mathematica",
|
||||
".m": "application/vnd.wolfram.mathematica.package",
|
||||
".nbp": "application/vnd.wolfram.player",
|
||||
".wpd": "application/vnd.wordperfect",
|
||||
".wqd": "application/vnd.wqd",
|
||||
@ -769,6 +767,7 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".gtar": "application/x-gtar",
|
||||
".tgz": "application/x-gtar-compressed",
|
||||
".hdf": "application/x-hdf",
|
||||
".php": "application/x-php",
|
||||
".hwp": "application/x-hwp",
|
||||
".ica": "application/x-ica",
|
||||
".info": "application/x-info",
|
||||
@ -801,8 +800,10 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".rpm": "application/x-redhat-package-manager",
|
||||
".rss": "application/x-rss+xml",
|
||||
".rb": "application/x-ruby",
|
||||
".erb": "application/x-ruby",
|
||||
".sci": "application/x-scilab",
|
||||
".xcos": "application/x-scilab-xcos",
|
||||
".sh": "application/x-sh",
|
||||
".shar": "application/x-shar",
|
||||
".scr": "application/x-silverlight",
|
||||
".sit": "application/x-stuffit",
|
||||
@ -839,7 +840,7 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".xsl": "application/xslt+xml",
|
||||
".xspf": "application/xspf+xml",
|
||||
".mxml": "application/xv+xml",
|
||||
".yaml": "application/yaml",
|
||||
".yaml": "application/x-yaml",
|
||||
".yang": "application/yang",
|
||||
".yin": "application/yin+xml",
|
||||
".zip": "application/zip",
|
||||
@ -1085,28 +1086,36 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".x3dv": "model/x3d-vrml",
|
||||
".bmed": "multipart/vnd.bint.med-plus",
|
||||
".vpm": "multipart/voice-message",
|
||||
"ahk": "text/autohotkey",
|
||||
"au3": "text/autohotkey",
|
||||
".appcache": "text/cache-manifest",
|
||||
".ics": "text/calendar",
|
||||
"cof": "text/coffeescript",
|
||||
"coffee": "text/coffeescript",
|
||||
"coffeescript": "text/coffeescript",
|
||||
".CQL": "text/cql",
|
||||
".css": "text/css",
|
||||
".csv": "text/csv",
|
||||
".csvs": "text/csv-schema",
|
||||
".soa": "text/dns",
|
||||
".gff3": "text/gff3",
|
||||
".go": "text/golang",
|
||||
".htm": "text/html",
|
||||
".html": "text/html",
|
||||
".cjs": "text/javascript",
|
||||
".js": "text/javascript",
|
||||
".mjs": "text/javascript",
|
||||
".cnd": "text/jcr-cnd",
|
||||
".jsx": "text/jsx",
|
||||
".less": "text/less",
|
||||
".md": "text/markdown",
|
||||
".m": "text/mips",
|
||||
".miz": "text/mizar",
|
||||
".n3": "text/n3",
|
||||
".txt": "text/plain",
|
||||
".provn": "text/provenance-notation",
|
||||
".rst": "text/prs.fallenstein.rst",
|
||||
".tag": "text/prs.lines.tag",
|
||||
".rs": "text/rust",
|
||||
".rs": "text/x-rust",
|
||||
".sass": "text/scss",
|
||||
".scss": "text/scss",
|
||||
".sgml": "text/SGML",
|
||||
@ -1116,6 +1125,7 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".tsv": "text/tab-separated-values",
|
||||
".tm": "text/texmacs",
|
||||
".t": "text/troff",
|
||||
".tsx": "text/typescript-jsx",
|
||||
".ttl": "text/turtle",
|
||||
".ts": "text/typescript",
|
||||
".uris": "text/uri-list",
|
||||
@ -1148,31 +1158,61 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".wmls": "text/vnd.wap.wmlscript",
|
||||
".vtt": "text/vtt",
|
||||
".wgsl": "text/wgsl",
|
||||
".cls": "text/x-apex",
|
||||
".asp": "text/x-aspx",
|
||||
".aspx": "text/x-aspx",
|
||||
".bib": "text/x-bibtex",
|
||||
".boo": "text/x-boo",
|
||||
".h++": "text/x-c++hdr",
|
||||
".cc": "text/x-c++src",
|
||||
".cpp": "text/x-c++src",
|
||||
".c++": "text/x-c++src",
|
||||
".h": "text/x-chdr",
|
||||
".clojure": "text/x-clojure",
|
||||
".htc": "text/x-component",
|
||||
".csh": "text/x-csh",
|
||||
".cshtml": "text/x-cshtml",
|
||||
".c": "text/x-csrc",
|
||||
".dart": "text/x-dart",
|
||||
".diff": "text/x-diff",
|
||||
".d": "text/x-dsrc",
|
||||
".ex": "text/x-elixir",
|
||||
".elm": "text/x-elm",
|
||||
".erl": "text/x-erlang",
|
||||
".go": "text/x-go",
|
||||
".handlebars": "text/x-handlebars-template",
|
||||
".hbs": "text/x-handlebars-template",
|
||||
".hs": "text/x-haskell",
|
||||
".java": "text/x-java",
|
||||
".jl": "text/x-julia",
|
||||
".kt": "text/x-kotlin",
|
||||
".kts": "text/x-kotlin",
|
||||
".ly": "text/x-lilypond",
|
||||
".cl": "text/x-common-lisp",
|
||||
".cs": "text/x-c#src",
|
||||
".l": "text/x-common-lisp",
|
||||
".lisp": "text/x-common-lisp",
|
||||
".lsp": "text/x-common-lisp",
|
||||
".lua": "text/x-lua",
|
||||
".lhs": "text/x-literate-haskell",
|
||||
".moc": "text/x-moc",
|
||||
".p": "text/x-pascal",
|
||||
".pas": "text/x-pascal",
|
||||
".pp": "text/x-pascal",
|
||||
".gcd": "text/x-pcs-gcd",
|
||||
".pl": "text/x-perl",
|
||||
".py": "text/x-python",
|
||||
".r": "text/x-r",
|
||||
".sbt": "text/x-scala",
|
||||
".sc": "text/x-scala",
|
||||
".scala": "text/x-scala",
|
||||
".scm": "text/x-scheme",
|
||||
".etx": "text/x-setext",
|
||||
".sfv": "text/x-sfv",
|
||||
".sh": "text/x-sh",
|
||||
".swift": "text/swift",
|
||||
".tcl": "text/x-tcl",
|
||||
".tex": "text/x-tex",
|
||||
".twig": "text/x-twig",
|
||||
".vcs": "text/x-vcalendar",
|
||||
".axv": "video/annodex",
|
||||
".dif": "video/dv",
|
||||
|
@ -630,13 +630,6 @@ func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error {
|
||||
// does not return "application/octet-stream" as this is considered a detection failure
|
||||
// can pass an existing fileInfo to avoid re-statting the file
|
||||
func DetectMimeType(path string, fileInfo fs.FileInfo) string {
|
||||
ext := filepath.Ext(path)
|
||||
if mimeType, ok := StaticMimeTypeMap[ext]; ok {
|
||||
return mimeType
|
||||
}
|
||||
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
|
||||
return mimeType
|
||||
}
|
||||
if fileInfo == nil {
|
||||
statRtn, err := os.Stat(path)
|
||||
if err != nil {
|
||||
@ -657,6 +650,13 @@ func DetectMimeType(path string, fileInfo fs.FileInfo) string {
|
||||
if fileInfo.Mode()&os.ModeDevice == os.ModeDevice {
|
||||
return "block-special"
|
||||
}
|
||||
ext := filepath.Ext(path)
|
||||
if mimeType, ok := StaticMimeTypeMap[ext]; ok {
|
||||
return mimeType
|
||||
}
|
||||
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
|
||||
return mimeType
|
||||
}
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
|
@ -5,6 +5,12 @@
|
||||
"application/pdf": {
|
||||
"icon": "file-pdf"
|
||||
},
|
||||
"application/javascript": {
|
||||
"icon": "js fa-brands"
|
||||
},
|
||||
"application/typescript": {
|
||||
"icon": "js fa-brands"
|
||||
},
|
||||
"application/json": {
|
||||
"icon": "file-lines"
|
||||
},
|
||||
@ -53,5 +59,14 @@
|
||||
},
|
||||
"text/csv": {
|
||||
"icon": "file-csv"
|
||||
},
|
||||
"text/x-dart": {
|
||||
"icon": "dart-lang fa-brands"
|
||||
},
|
||||
"text/x-go": {
|
||||
"icon": "golang fa-brands"
|
||||
},
|
||||
"text/x-rust": {
|
||||
"icon": "rust fa-brands"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user