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