aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/release_attachment.go24
-rw-r--r--routers/web/repo/attachment.go28
-rw-r--r--routers/web/repo/setting.go3
3 files changed, 17 insertions, 38 deletions
diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go
index 0834667657..d1533e2b5a 100644
--- a/routers/api/v1/repo/release_attachment.go
+++ b/routers/api/v1/repo/release_attachment.go
@@ -15,6 +15,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/upload"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/attachment"
)
// GetReleaseAttachment gets a single attachment of the release
@@ -176,31 +177,18 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
}
defer file.Close()
- buf := make([]byte, 1024)
- n, _ := file.Read(buf)
- if n > 0 {
- buf = buf[:n]
- }
-
- // Check if the filetype is allowed by the settings
- err = upload.Verify(buf, header.Filename, setting.Repository.Release.AllowedTypes)
- if err != nil {
- ctx.Error(http.StatusBadRequest, "DetectContentType", err)
- return
- }
-
var filename = header.Filename
if query := ctx.FormString("name"); query != "" {
filename = query
}
// Create a new attachment and save the file
- attach, err := models.NewAttachment(&models.Attachment{
- UploaderID: ctx.User.ID,
- Name: filename,
- ReleaseID: release.ID,
- }, buf, file)
+ attach, err := attachment.UploadAttachment(file, ctx.User.ID, release.RepoID, releaseID, filename, setting.Repository.Release.AllowedTypes)
if err != nil {
+ if upload.IsErrFileTypeForbidden(err) {
+ ctx.Error(http.StatusBadRequest, "DetectContentType", err)
+ return
+ }
ctx.Error(http.StatusInternalServerError, "NewAttachment", err)
return
}
diff --git a/routers/web/repo/attachment.go b/routers/web/repo/attachment.go
index 1a25384792..3968d27652 100644
--- a/routers/web/repo/attachment.go
+++ b/routers/web/repo/attachment.go
@@ -16,20 +16,21 @@ import (
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/upload"
"code.gitea.io/gitea/routers/common"
+ "code.gitea.io/gitea/services/attachment"
)
// UploadIssueAttachment response for Issue/PR attachments
func UploadIssueAttachment(ctx *context.Context) {
- uploadAttachment(ctx, setting.Attachment.AllowedTypes)
+ uploadAttachment(ctx, ctx.Repo.Repository.ID, setting.Attachment.AllowedTypes)
}
// UploadReleaseAttachment response for uploading release attachments
func UploadReleaseAttachment(ctx *context.Context) {
- uploadAttachment(ctx, setting.Repository.Release.AllowedTypes)
+ uploadAttachment(ctx, ctx.Repo.Repository.ID, setting.Repository.Release.AllowedTypes)
}
// UploadAttachment response for uploading attachments
-func uploadAttachment(ctx *context.Context, allowedTypes string) {
+func uploadAttachment(ctx *context.Context, repoID int64, allowedTypes string) {
if !setting.Attachment.Enabled {
ctx.Error(http.StatusNotFound, "attachment is not enabled")
return
@@ -42,23 +43,12 @@ func uploadAttachment(ctx *context.Context, allowedTypes string) {
}
defer file.Close()
- buf := make([]byte, 1024)
- n, _ := file.Read(buf)
- if n > 0 {
- buf = buf[:n]
- }
-
- err = upload.Verify(buf, header.Filename, allowedTypes)
- if err != nil {
- ctx.Error(http.StatusBadRequest, err.Error())
- return
- }
-
- attach, err := models.NewAttachment(&models.Attachment{
- UploaderID: ctx.User.ID,
- Name: header.Filename,
- }, buf, file)
+ attach, err := attachment.UploadAttachment(file, ctx.User.ID, repoID, 0, header.Filename, allowedTypes)
if err != nil {
+ if upload.IsErrFileTypeForbidden(err) {
+ ctx.Error(http.StatusBadRequest, err.Error())
+ return
+ }
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("NewAttachment: %v", err))
return
}
diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go
index 624c01814e..72bacebd27 100644
--- a/routers/web/repo/setting.go
+++ b/routers/web/repo/setting.go
@@ -34,6 +34,7 @@ import (
"code.gitea.io/gitea/services/mailer"
mirror_service "code.gitea.io/gitea/services/mirror"
repo_service "code.gitea.io/gitea/services/repository"
+ wiki_service "code.gitea.io/gitea/services/wiki"
)
const (
@@ -682,7 +683,7 @@ func SettingsPost(ctx *context.Context) {
return
}
- err := repo.DeleteWiki()
+ err := wiki_service.DeleteWiki(repo)
if err != nil {
log.Error("Delete Wiki: %v", err.Error())
}