1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-03 09:07:19 +00:00

Refactor filetype is not allowed errors (#7309)

This commit is contained in:
Antoine GIRARD
2019-07-07 04:25:05 +02:00
committed by techknowlogick
parent 75d4414386
commit f369788347
5 changed files with 61 additions and 46 deletions

View File

@ -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
}
}