mirror of https://github.com/Xhofe/alist
fix: incorrect content-type of apk files (close #5385)
parent
da1c7a4c23
commit
4355dae491
|
@ -163,8 +163,15 @@ func GetObjType(filename string, isDir bool) int {
|
||||||
return GetFileType(filename)
|
return GetFileType(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var extraMimeTypes = map[string]string{
|
||||||
|
".apk": "application/vnd.android.package-archive",
|
||||||
|
}
|
||||||
|
|
||||||
func GetMimeType(name string) string {
|
func GetMimeType(name string) string {
|
||||||
ext := path.Ext(name)
|
ext := path.Ext(name)
|
||||||
|
if m, ok := extraMimeTypes[ext]; ok {
|
||||||
|
return m
|
||||||
|
}
|
||||||
m := mime.TypeByExtension(ext)
|
m := mime.TypeByExtension(ext)
|
||||||
if m != "" {
|
if m != "" {
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -76,4 +76,5 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
|
||||||
func attachFileName(w http.ResponseWriter, file model.Obj) {
|
func attachFileName(w http.ResponseWriter, file model.Obj) {
|
||||||
fileName := file.GetName()
|
fileName := file.GetName()
|
||||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, fileName, url.PathEscape(fileName)))
|
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, fileName, url.PathEscape(fileName)))
|
||||||
|
w.Header().Set("Content-Type", utils.GetMimeType(fileName))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue