mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
add more extensions to mimetype database. (#1417)
fallback to text/plain for 0 byte files
This commit is contained in:
parent
74bb5c7317
commit
9f10be5629
@ -572,6 +572,8 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".oeb": "application/vnd.openeye.oeb",
|
||||
".oxt": "application/vnd.openofficeorg.extension",
|
||||
".osm": "application/vnd.openstreetmap.data+xml",
|
||||
".exe": "application/vnd.microsoft.portable-executable",
|
||||
".dll": "application/vnd.microsoft.portable-executable",
|
||||
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
".sldx": "application/vnd.openxmlformats-officedocument.presentationml.slide",
|
||||
".ppsx": "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
|
||||
@ -1108,14 +1110,18 @@ var StaticMimeTypeMap = map[string]string{
|
||||
".jsx": "text/jsx",
|
||||
".less": "text/less",
|
||||
".md": "text/markdown",
|
||||
".mdx": "text/mdx",
|
||||
".m": "text/mips",
|
||||
".miz": "text/mizar",
|
||||
".n3": "text/n3",
|
||||
".txt": "text/plain",
|
||||
".conf": "text/plain",
|
||||
".awk": "text/x-awk",
|
||||
".provn": "text/provenance-notation",
|
||||
".rst": "text/prs.fallenstein.rst",
|
||||
".tag": "text/prs.lines.tag",
|
||||
".rs": "text/x-rust",
|
||||
".ini": "text/x-ini",
|
||||
".sass": "text/scss",
|
||||
".scss": "text/scss",
|
||||
".sgml": "text/SGML",
|
||||
|
@ -620,6 +620,7 @@ func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error {
|
||||
// on error just returns ""
|
||||
// does not return "application/octet-stream" as this is considered a detection failure
|
||||
// can pass an existing fileInfo to avoid re-statting the file
|
||||
// falls back to text/plain for 0 byte files
|
||||
func DetectMimeType(path string, fileInfo fs.FileInfo, extended bool) string {
|
||||
if fileInfo == nil {
|
||||
statRtn, err := os.Stat(path)
|
||||
@ -648,6 +649,9 @@ func DetectMimeType(path string, fileInfo fs.FileInfo, extended bool) string {
|
||||
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
|
||||
return mimeType
|
||||
}
|
||||
if fileInfo.Size() == 0 {
|
||||
return "text/plain"
|
||||
}
|
||||
if !extended {
|
||||
return ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user