summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-07-07 04:25:05 +0200
committertechknowlogick <techknowlogick@gitea.io>2019-07-06 22:25:05 -0400
commitf369788347167a47a8fc162e086b92048ff0a43f (patch)
treef959bd40d1a33761b0fa8a25bb956b4e24d3b044 /routers/api
parent75d44143863e90a7aeff30a3f40128f144df94dd (diff)
downloadgitea-f369788347167a47a8fc162e086b92048ff0a43f.tar.gz
gitea-f369788347167a47a8fc162e086b92048ff0a43f.zip
Refactor filetype is not allowed errors (#7309)
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/repo/release_attachment.go20
1 files changed, 4 insertions, 16 deletions
diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go
index f85787bc59..d0eb3d4ae1 100644
--- a/routers/api/v1/repo/release_attachment.go
+++ b/routers/api/v1/repo/release_attachment.go
@@ -5,13 +5,12 @@
package repo
import (
- "errors"
- "net/http"
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/upload"
api "code.gitea.io/gitea/modules/structs"
)
@@ -177,20 +176,9 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
}
// Check if the filetype is allowed by the settings
- fileType := http.DetectContentType(buf)
-
- allowedTypes := strings.Split(setting.AttachmentAllowedTypes, ",")
- allowed := false
- for _, t := range allowedTypes {
- t := strings.Trim(t, " ")
- if t == "*/*" || t == fileType {
- allowed = true
- break
- }
- }
-
- if !allowed {
- ctx.Error(400, "DetectContentType", errors.New("File type is not allowed"))
+ err = upload.VerifyAllowedContentType(buf, strings.Split(setting.AttachmentAllowedTypes, ","))
+ if err != nil {
+ ctx.Error(400, "DetectContentType", err)
return
}