From e3004c488c30a40e85a46839baf6c359df47017b Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 9 Mar 2022 17:04:12 +0800 Subject: [PATCH 1/2] fix-bug --- models/attachment.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/models/attachment.go b/models/attachment.go index 5179c0170..6214567ef 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "path" + "strings" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/obs" @@ -70,6 +71,7 @@ type AttachmentsOptions struct { NeedIsPrivate bool IsPrivate bool NeedRepoInfo bool + Keyword string } func (a *Attachment) AfterUpdate() { @@ -554,8 +556,14 @@ func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { var count int64 var err error - if (opts.Type) >= 0 { + if len(opts.Keyword) == 0 { count, err = sess.Where(cond).Count(new(Attachment)) + } else { + lowerKeyWord := strings.ToLower(opts.Keyword) + + cond = cond.And(builder.Or(builder.Like{"LOWER(attachment.name)", lowerKeyWord})) + count, err = sess.Table(&Attachment{}).Where(cond).Count(new(AttachmentInfo)) + } if err != nil { From 8497e5b0591350eae0e5c7ab1a3274aa805f0abb Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 10 Mar 2022 09:31:53 +0800 Subject: [PATCH 2/2] fix-bug --- routers/repo/dataset.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index d4e12ab8f..e73a942f8 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -6,6 +6,7 @@ import ( "regexp" "sort" "strconv" + "strings" "unicode/utf8" "code.gitea.io/gitea/models" @@ -286,6 +287,8 @@ func DatasetAction(ctx *context.Context) { func CurrentRepoDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") + repo := ctx.Repo.Repository var datasetIDs []int64 dataset, err := models.GetDatasetByRepo(repo) @@ -299,6 +302,7 @@ func CurrentRepoDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, DatasetIDs: datasetIDs, UploaderID: uploaderID, Type: cloudbrainType, @@ -329,6 +333,7 @@ func CurrentRepoDataset(ctx *context.Context) { func MyDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") uploaderID := ctx.User.ID datasets, count, err := models.Attachments(&models.AttachmentsOptions{ @@ -336,6 +341,7 @@ func MyDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, UploaderID: uploaderID, Type: cloudbrainType, NeedIsPrivate: false, @@ -365,12 +371,14 @@ func MyDataset(ctx *context.Context) { func PublicDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") datasets, count, err := models.Attachments(&models.AttachmentsOptions{ ListOptions: models.ListOptions{ Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, NeedIsPrivate: true, IsPrivate: false, Type: cloudbrainType, @@ -400,6 +408,7 @@ func PublicDataset(ctx *context.Context) { func MyFavoriteDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") var datasetIDs []int64 @@ -416,6 +425,7 @@ func MyFavoriteDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, DatasetIDs: datasetIDs, NeedIsPrivate: true, IsPrivate: false,