commit 946a8cd3761d8df7bea6f34ee22dd0b977be0d98
parent 1f49421c908cc8b78dd0fea801fe2ef5762d7d1e
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 22 Dec 2022 17:15:38 -0800
cleanup
Diffstat:
1 file changed, 36 insertions(+), 27 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -3899,6 +3899,39 @@ func PublicUserProfilePGPHandler(c echo.Context) error {
return c.String(http.StatusOK, user.GPGPublicKey)
}
+func isImageMimeType(mimeType string) bool {
+ return mimeType == "image/jpeg" ||
+ mimeType == "image/png" ||
+ mimeType == "image/gif" ||
+ mimeType == "image/bmp" ||
+ mimeType == "image/x-icon" ||
+ mimeType == "image/webp"
+}
+
+func isAttachmentMimeType(mimeType string) bool {
+ return mimeType == "application/x-gzip" ||
+ mimeType == "application/zip" ||
+ mimeType == "application/x-rar-compressed" ||
+ mimeType == "application/pdf" ||
+ mimeType == "audio/basic" ||
+ mimeType == "audio/aiff" ||
+ mimeType == "audio/mpeg" ||
+ mimeType == "application/ogg" ||
+ mimeType == "audio/midi" ||
+ mimeType == "video/avi" ||
+ mimeType == "audio/wave" ||
+ mimeType == "video/webm" ||
+ mimeType == "font/ttf" ||
+ mimeType == "font/otf" ||
+ mimeType == "font/collection" ||
+ mimeType == "font/woff" ||
+ mimeType == "font/woff2" ||
+ mimeType == "application/wasm" ||
+ mimeType == "application/postscript" ||
+ mimeType == "application/vnd.ms-fontobject" ||
+ mimeType == "application/octet-stream"
+}
+
func UploadsDownloadHandler(c echo.Context) error {
authUser := c.Get("authUser").(*database.User)
filename := c.Param("filename")
@@ -3926,12 +3959,7 @@ func UploadsDownloadHandler(c echo.Context) error {
}
// Serve images
- if mimeType == "image/jpeg" ||
- mimeType == "image/png" ||
- mimeType == "image/gif" ||
- mimeType == "image/bmp" ||
- mimeType == "image/x-icon" ||
- mimeType == "image/webp" {
+ if isImageMimeType(mimeType) {
http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), buf)
return nil
}
@@ -3940,27 +3968,8 @@ func UploadsDownloadHandler(c echo.Context) error {
mimeType = "text/plain; charset=utf-8"
}
- if mimeType == "application/x-gzip" ||
- mimeType == "application/zip" ||
- mimeType == "application/x-rar-compressed" ||
- mimeType == "application/pdf" ||
- mimeType == "audio/basic" ||
- mimeType == "audio/aiff" ||
- mimeType == "audio/mpeg" ||
- mimeType == "application/ogg" ||
- mimeType == "audio/midi" ||
- mimeType == "video/avi" ||
- mimeType == "audio/wave" ||
- mimeType == "video/webm" ||
- mimeType == "font/ttf" ||
- mimeType == "font/otf" ||
- mimeType == "font/collection" ||
- mimeType == "font/woff" ||
- mimeType == "font/woff2" ||
- mimeType == "application/wasm" ||
- mimeType == "application/postscript" ||
- mimeType == "application/vnd.ms-fontobject" ||
- mimeType == "application/octet-stream" {
+ // MimeType that always trigger a file "download"
+ if isAttachmentMimeType(mimeType) {
// Keep track of user downloads
if _, err := database.CreateDownload(authUser.ID, filename); err != nil {
logrus.Error(err)