@@ -14,7 +14,7 @@ import (
1414 "code.gitea.io/gitea/modules/setting"
1515 api "code.gitea.io/gitea/modules/structs"
1616 "code.gitea.io/gitea/modules/web"
17- "code.gitea.io/gitea/services/attachment"
17+ attachment_service "code.gitea.io/gitea/services/attachment"
1818 "code.gitea.io/gitea/services/context"
1919 "code.gitea.io/gitea/services/context/upload"
2020 "code.gitea.io/gitea/services/convert"
@@ -189,7 +189,7 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
189189 filename = query
190190 }
191191
192- attachment , err := attachment .UploadAttachment (ctx , file , setting .Attachment .AllowedTypes , header .Size , & repo_model.Attachment {
192+ attachment , err := attachment_service .UploadAttachment (ctx , file , setting .Attachment .AllowedTypes , header .Size , & repo_model.Attachment {
193193 Name : filename ,
194194 UploaderID : ctx .Doer .ID ,
195195 RepoID : ctx .Repo .Repository .ID ,
@@ -263,6 +263,8 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
263263 // "$ref": "#/responses/Attachment"
264264 // "404":
265265 // "$ref": "#/responses/error"
266+ // "422":
267+ // "$ref": "#/responses/validationError"
266268 // "423":
267269 // "$ref": "#/responses/repoArchivedError"
268270 attach := getIssueCommentAttachmentSafeWrite (ctx )
@@ -275,8 +277,13 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
275277 attach .Name = form .Name
276278 }
277279
278- if err := repo_model .UpdateAttachment (ctx , attach ); err != nil {
280+ if err := attachment_service .UpdateAttachment (ctx , setting .Attachment .AllowedTypes , attach ); err != nil {
281+ if upload .IsErrFileTypeForbidden (err ) {
282+ ctx .Error (http .StatusUnprocessableEntity , "" , err )
283+ return
284+ }
279285 ctx .Error (http .StatusInternalServerError , "UpdateAttachment" , attach )
286+ return
280287 }
281288 ctx .JSON (http .StatusCreated , convert .ToAPIAttachment (ctx .Repo .Repository , attach ))
282289}
0 commit comments