From 4355dae491ba251ce99826ad8833a47ed8cbdad5 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Mon, 6 Nov 2023 18:20:25 +0800 Subject: [PATCH] fix: incorrect content-type of apk files (close #5385) --- pkg/utils/file.go | 7 +++++++ server/common/proxy.go | 1 + 2 files changed, 8 insertions(+) diff --git a/pkg/utils/file.go b/pkg/utils/file.go index 31803a95..7ae07158 100644 --- a/pkg/utils/file.go +++ b/pkg/utils/file.go @@ -163,8 +163,15 @@ func GetObjType(filename string, isDir bool) int { return GetFileType(filename) } +var extraMimeTypes = map[string]string{ + ".apk": "application/vnd.android.package-archive", +} + func GetMimeType(name string) string { ext := path.Ext(name) + if m, ok := extraMimeTypes[ext]; ok { + return m + } m := mime.TypeByExtension(ext) if m != "" { return m diff --git a/server/common/proxy.go b/server/common/proxy.go index 370e46eb..8156dc88 100644 --- a/server/common/proxy.go +++ b/server/common/proxy.go @@ -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) { 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-Type", utils.GetMimeType(fileName)) }