diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2023-08-16 08:01:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-16 06:01:20 +0000 |
commit | 762d4245fb22a927861d30c6314d81e27eb1a06a (patch) | |
tree | 7f9ba64a7e12b2da5f06edb3db58c6eab7ae61ce /routers | |
parent | 3571cbba343b7a249c408cc7e6fc4d4f7efffa2a (diff) | |
download | gitea-762d4245fb22a927861d30c6314d81e27eb1a06a.tar.gz gitea-762d4245fb22a927861d30c6314d81e27eb1a06a.zip |
Fix NuGet search endpoints (#25613) (#26499)
Backport of #25613
Fixes #25564
Fixes #23191
- Api v2 search endpoint should return only the latest version matching
the query
- Api v3 search endpoint should return `take` packages not package
versions
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/packages/nuget/api_v3.go | 13 | ||||
-rw-r--r-- | routers/api/packages/nuget/nuget.go | 9 |
2 files changed, 15 insertions, 7 deletions
diff --git a/routers/api/packages/nuget/api_v3.go b/routers/api/packages/nuget/api_v3.go index af52125e2e..2fe25dc0f8 100644 --- a/routers/api/packages/nuget/api_v3.go +++ b/routers/api/packages/nuget/api_v3.go @@ -9,6 +9,9 @@ import ( packages_model "code.gitea.io/gitea/models/packages" nuget_module "code.gitea.io/gitea/modules/packages/nuget" + + "golang.org/x/text/collate" + "golang.org/x/text/language" ) // https://docs.microsoft.com/en-us/nuget/api/service-index#resources @@ -207,9 +210,15 @@ func createSearchResultResponse(l *linkBuilder, totalHits int64, pds []*packages grouped[pd.Package.Name] = append(grouped[pd.Package.Name], pd) } + keys := make([]string, 0, len(grouped)) + for key := range grouped { + keys = append(keys, key) + } + collate.New(language.English, collate.IgnoreCase).SortStrings(keys) + data := make([]*SearchResult, 0, len(pds)) - for _, group := range grouped { - data = append(data, createSearchResult(l, group)) + for _, key := range keys { + data = append(data, createSearchResult(l, grouped[key])) } return &SearchResultResponse{ diff --git a/routers/api/packages/nuget/nuget.go b/routers/api/packages/nuget/nuget.go index f79292dd20..b05e3518e0 100644 --- a/routers/api/packages/nuget/nuget.go +++ b/routers/api/packages/nuget/nuget.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/models/db" packages_model "code.gitea.io/gitea/models/packages" + nuget_model "code.gitea.io/gitea/models/packages/nuget" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" packages_module "code.gitea.io/gitea/modules/packages" @@ -115,7 +116,7 @@ func SearchServiceV2(ctx *context.Context) { skip, take := ctx.FormInt("$skip"), ctx.FormInt("$top") paginator := db.NewAbsoluteListOptions(skip, take) - pvs, total, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ + pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{ OwnerID: ctx.Package.Owner.ID, Type: packages_model.TypeNuGet, Name: packages_model.SearchValue{ @@ -166,9 +167,8 @@ func SearchServiceV2(ctx *context.Context) { // http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752351 func SearchServiceV2Count(ctx *context.Context) { - count, err := packages_model.CountVersions(ctx, &packages_model.PackageSearchOptions{ + count, err := nuget_model.CountPackages(ctx, &packages_model.PackageSearchOptions{ OwnerID: ctx.Package.Owner.ID, - Type: packages_model.TypeNuGet, Name: packages_model.SearchValue{ Value: getSearchTerm(ctx), }, @@ -184,9 +184,8 @@ func SearchServiceV2Count(ctx *context.Context) { // https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-for-packages func SearchServiceV3(ctx *context.Context) { - pvs, count, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ + pvs, count, err := nuget_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ OwnerID: ctx.Package.Owner.ID, - Type: packages_model.TypeNuGet, Name: packages_model.SearchValue{Value: ctx.FormTrim("q")}, IsInternal: util.OptionalBoolFalse, Paginator: db.NewAbsoluteListOptions( |