diff options
author | Antoine GIRARD <sapk@users.noreply.github.com> | 2019-07-07 04:25:05 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-07-06 22:25:05 -0400 |
commit | f369788347167a47a8fc162e086b92048ff0a43f (patch) | |
tree | f959bd40d1a33761b0fa8a25bb956b4e24d3b044 /routers/repo/editor.go | |
parent | 75d44143863e90a7aeff30a3f40128f144df94dd (diff) | |
download | gitea-f369788347167a47a8fc162e086b92048ff0a43f.tar.gz gitea-f369788347167a47a8fc162e086b92048ff0a43f.zip |
Refactor filetype is not allowed errors (#7309)
Diffstat (limited to 'routers/repo/editor.go')
-rw-r--r-- | routers/repo/editor.go | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 062ecfebf7..f3327017e5 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -7,7 +7,6 @@ package repo import ( "fmt" "io/ioutil" - "net/http" "path" "strings" @@ -20,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/repofiles" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/modules/upload" "code.gitea.io/gitea/modules/util" ) @@ -594,20 +594,11 @@ func UploadFileToServer(ctx *context.Context) { if n > 0 { buf = buf[:n] } - fileType := http.DetectContentType(buf) if len(setting.Repository.Upload.AllowedTypes) > 0 { - allowed := false - for _, t := range setting.Repository.Upload.AllowedTypes { - t := strings.Trim(t, " ") - if t == "*/*" || t == fileType { - allowed = true - break - } - } - - if !allowed { - ctx.Error(400, ErrFileTypeForbidden.Error()) + err = upload.VerifyAllowedContentType(buf, setting.Repository.Upload.AllowedTypes) + if err != nil { + ctx.Error(400, err.Error()) return } } |