Skip to content

Commit

Permalink
解决源搜索错误
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Nov 9, 2024
1 parent cb4cf18 commit ee57593
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 159 deletions.
2 changes: 1 addition & 1 deletion src/NuGet.Next.Core/PackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<IReadOnlyList<NuGetVersion>> FindPackageVersionsAsync(
public async Task<IReadOnlyList<Package>> FindPackagesAsync(string id, CancellationToken cancellationToken)
{
var upstreamPackages = await _upstream.ListPackagesAsync(id, cancellationToken);
var localPackages = await _db.FindAsync(id, includeUnlisted: true, cancellationToken);
var localPackages = await _db.FindAsync(id, includeUnlisted: true, cancellationToken);

if (!upstreamPackages.Any()) return localPackages;
if (!localPackages.Any()) return upstreamPackages;
Expand Down
4 changes: 3 additions & 1 deletion src/NuGet.Next.Core/ServiceIndex/BaGetServiceIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public Task<ServiceIndexResponse> GetAsync(CancellationToken cancellationToken =
{
var resources = new List<ServiceIndexItem>();

resources.AddRange(BuildResource("PackagePublish", _url.GetPackagePublishResourceUrl(), "2.0.0"));
var publishResourceUrl = _url.GetPackagePublishResourceUrl();

resources.AddRange(BuildResource("PackagePublish", publishResourceUrl, "2.0.0"));
resources.AddRange(BuildResource("SymbolPackagePublish", _url.GetSymbolPublishResourceUrl(), "4.9.0"));
resources.AddRange(BuildResource("SearchQueryService", _url.GetSearchResourceUrl(), "", "3.0.0-beta",
"3.0.0-rc"));
Expand Down
125 changes: 125 additions & 0 deletions src/NuGet.Next/NuGetNextEndpointBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using Microsoft.AspNetCore.Routing.Constraints;
using NuGet.Next.Web;

namespace NuGet.Next;

public class NuGetNextEndpointBuilder
{
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
MapServiceIndexRoutes(endpoints);
MapPackagePublishRoutes(endpoints);
MapSymbolRoutes(endpoints);
MapSearchRoutes(endpoints);
MapPackageMetadataRoutes(endpoints);
MapPackageContentRoutes(endpoints);
}

public void MapServiceIndexRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.IndexRouteName,
pattern: "v3/index.json",
defaults: new { controller = "ServiceIndex", action = "Get" });
}

public void MapPackagePublishRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.UploadPackageRouteName,
pattern: "api/v2/package",
defaults: new { controller = "PackagePublish", action = "Upload" },
constraints: new { httpMethod = new HttpMethodRouteConstraint("PUT") });

endpoints.MapControllerRoute(
name: Routes.DeleteRouteName,
pattern: "api/v2/package/{id}/{version}",
defaults: new { controller = "PackagePublish", action = "Delete" },
constraints: new { httpMethod = new HttpMethodRouteConstraint("DELETE") });

endpoints.MapControllerRoute(
name: Routes.RelistRouteName,
pattern: "api/v2/package/{id}/{version}",
defaults: new { controller = "PackagePublish", action = "Relist" },
constraints: new { httpMethod = new HttpMethodRouteConstraint("POST") });
}

public void MapSymbolRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.UploadSymbolRouteName,
pattern: "api/v2/symbol",
defaults: new { controller = "Symbol", action = "Upload" },
constraints: new { httpMethod = new HttpMethodRouteConstraint("PUT") });

endpoints.MapControllerRoute(
name: Routes.SymbolDownloadRouteName,
pattern: "api/download/symbols/{file}/{key}/{file2}",
defaults: new { controller = "Symbol", action = "Get" });

endpoints.MapControllerRoute(
name: Routes.PrefixedSymbolDownloadRouteName,
pattern: "api/download/symbols/{prefix}/{file}/{key}/{file2}",
defaults: new { controller = "Symbol", action = "Get" });
}

public void MapSearchRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.SearchRouteName,
pattern: "v3/search",
defaults: new { controller = "Search", action = "Search" });

endpoints.MapControllerRoute(
name: Routes.AutocompleteRouteName,
pattern: "v3/autocomplete",
defaults: new { controller = "Search", action = "Autocomplete" });

// This is an unofficial API to find packages that depend on a given package.
endpoints.MapControllerRoute(
name: Routes.DependentsRouteName,
pattern: "v3/dependents",
defaults: new { controller = "Search", action = "Dependents" });
}

public void MapPackageMetadataRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.RegistrationIndexRouteName,
pattern: "v3/registration/{id}/index.json",
defaults: new { controller = "PackageMetadata", action = "RegistrationIndex" });

endpoints.MapControllerRoute(
name: Routes.RegistrationLeafRouteName,
pattern: "v3/registration/{id}/{version}.json",
defaults: new { controller = "PackageMetadata", action = "RegistrationLeaf" });
}

public void MapPackageContentRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.PackageVersionsRouteName,
pattern: "v3/package/{id}/index.json",
defaults: new { controller = "PackageContent", action = "GetPackageVersions" });

endpoints.MapControllerRoute(
name: Routes.PackageDownloadRouteName,
pattern: "v3/package/{id}/{version}/{idVersion}.nupkg",
defaults: new { controller = "PackageContent", action = "DownloadPackage" });

endpoints.MapControllerRoute(
name: Routes.PackageDownloadManifestRouteName,
pattern: "v3/package/{id}/{version}/{id2}.nuspec",
defaults: new { controller = "PackageContent", action = "DownloadNuspec" });

endpoints.MapControllerRoute(
name: Routes.PackageDownloadReadmeRouteName,
pattern: "v3/package/{id}/{version}/readme",
defaults: new { controller = "PackageContent", action = "DownloadReadme" });

endpoints.MapControllerRoute(
name: Routes.PackageDownloadIconRouteName,
pattern: "v3/package/{id}/{version}/icon",
defaults: new { controller = "PackageContent", action = "DownloadIcon" });
}
}
Loading

0 comments on commit ee57593

Please sign in to comment.