diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-19 21:39:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 21:39:57 +0800 |
commit | fc3d0826096943b979717ed46c9a4cfd86e06106 (patch) | |
tree | 3143882ccf4dea3a8bf2a0de9c8da9a4efec26ce /routers/web | |
parent | 7a0347315995b25bcb2dca4786504fb699b5f004 (diff) | |
download | gitea-fc3d0826096943b979717ed46c9a4cfd86e06106.tar.gz gitea-fc3d0826096943b979717ed46c9a4cfd86e06106.zip |
Move attachment into models/repo/ (#17650)
* Move attachment into models/repo/
* Fix test
* Fix bug
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/repo/attachment.go | 11 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 11 | ||||
-rw-r--r-- | routers/web/repo/repo.go | 5 |
3 files changed, 15 insertions, 12 deletions
diff --git a/routers/web/repo/attachment.go b/routers/web/repo/attachment.go index 3968d27652..303eee24d1 100644 --- a/routers/web/repo/attachment.go +++ b/routers/web/repo/attachment.go @@ -9,6 +9,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/log" @@ -62,7 +63,7 @@ func uploadAttachment(ctx *context.Context, repoID int64, allowedTypes string) { // DeleteAttachment response for deleting issue's attachment func DeleteAttachment(ctx *context.Context) { file := ctx.FormString("file") - attach, err := models.GetAttachmentByUUID(file) + attach, err := repo_model.GetAttachmentByUUID(file) if err != nil { ctx.Error(http.StatusBadRequest, err.Error()) return @@ -71,7 +72,7 @@ func DeleteAttachment(ctx *context.Context) { ctx.Error(http.StatusForbidden) return } - err = models.DeleteAttachment(attach, true) + err = repo_model.DeleteAttachment(attach, true) if err != nil { ctx.Error(http.StatusInternalServerError, fmt.Sprintf("DeleteAttachment: %v", err)) return @@ -83,9 +84,9 @@ func DeleteAttachment(ctx *context.Context) { // GetAttachment serve attachements func GetAttachment(ctx *context.Context) { - attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid")) + attach, err := repo_model.GetAttachmentByUUID(ctx.Params(":uuid")) if err != nil { - if models.IsErrAttachmentNotExist(err) { + if repo_model.IsErrAttachmentNotExist(err) { ctx.Error(http.StatusNotFound) } else { ctx.ServerError("GetAttachmentByUUID", err) @@ -93,7 +94,7 @@ func GetAttachment(ctx *context.Context) { return } - repository, unitType, err := attach.LinkedRepository() + repository, unitType, err := models.LinkedRepository(attach) if err != nil { ctx.ServerError("LinkedRepository", err) return diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 129287b96a..6cc9419763 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -2516,7 +2517,7 @@ func GetCommentAttachments(ctx *context.Context) { } func updateAttachments(item interface{}, files []string) error { - var attachments []*models.Attachment + var attachments []*repo_model.Attachment switch content := item.(type) { case *models.Issue: attachments = content.Attachments @@ -2529,7 +2530,7 @@ func updateAttachments(item interface{}, files []string) error { if util.IsStringInSlice(attachments[i].UUID, files) { continue } - if err := models.DeleteAttachment(attachments[i], true); err != nil { + if err := repo_model.DeleteAttachment(attachments[i], true); err != nil { return err } } @@ -2549,16 +2550,16 @@ func updateAttachments(item interface{}, files []string) error { } switch content := item.(type) { case *models.Issue: - content.Attachments, err = models.GetAttachmentsByIssueID(content.ID) + content.Attachments, err = repo_model.GetAttachmentsByIssueID(content.ID) case *models.Comment: - content.Attachments, err = models.GetAttachmentsByCommentID(content.ID) + content.Attachments, err = repo_model.GetAttachmentsByCommentID(content.ID) default: return fmt.Errorf("Unknown Type: %T", content) } return err } -func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment, content string) string { +func attachmentsHTML(ctx *context.Context, attachments []*repo_model.Attachment, content string) string { attachHTML, err := ctx.HTMLString(string(tplAttachment), map[string]interface{}{ "ctx": ctx.Data, "Attachments": attachments, diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 2d6189824d..e8fdb99ff4 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -346,7 +347,7 @@ func RedirectDownload(ctx *context.Context) { curRepo := ctx.Repo.Repository releases, err := models.GetReleasesByRepoIDAndNames(db.DefaultContext, curRepo.ID, tagNames) if err != nil { - if models.IsErrAttachmentNotExist(err) { + if repo_model.IsErrAttachmentNotExist(err) { ctx.Error(http.StatusNotFound) return } @@ -355,7 +356,7 @@ func RedirectDownload(ctx *context.Context) { } if len(releases) == 1 { release := releases[0] - att, err := models.GetAttachmentByReleaseIDFileName(release.ID, fileName) + att, err := repo_model.GetAttachmentByReleaseIDFileName(release.ID, fileName) if err != nil { ctx.Error(http.StatusNotFound) return |