From bc1464db7fac86074a1b923db43049b806f39d8a Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 1 Feb 2025 19:44:31 +0000 Subject: [PATCH] Web search result fixed --- Makefile | 2 +- src/.vscode/launch.json | 35 ++++++++++++++++ src/.vscode/tasks.json | 41 +++++++++++++++++++ src/isn.abst/ApiConfig.cs | 1 - .../Packages/PackagesController.WebViews.cs | 16 ++++++-- src/isnd/Data/Catalog/RegistratioinLeave.cs | 2 +- src/isnd/Data/Packages/Package.cs | 2 +- src/isnd/Data/Packages/PackageVersion.cs | 4 +- src/isnd/Services/PackageManager.cs | 14 +++++-- src/isnd/ViewModels/PackageHit.cs | 9 +++- src/isnd/ViewModels/PackageSearchResult.cs | 29 +++++++++---- src/isnd/Views/Packages/Delete.cshtml | 24 +++++------ test/data/test-isn/test-isn.csproj | 2 + 13 files changed, 146 insertions(+), 35 deletions(-) create mode 100644 src/.vscode/launch.json create mode 100644 src/.vscode/tasks.json diff --git a/Makefile b/Makefile index cf34578..2597883 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CONFIGURATION=Debug -TARGETFV=net7.0 +TARGETFV=net8.0 all: build-isn build-isnd diff --git a/src/.vscode/launch.json b/src/.vscode/launch.json new file mode 100644 index 0000000..f19eaba --- /dev/null +++ b/src/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md. + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/isnd/bin/Debug/net8.0/isnd.dll", + "args": [], + "cwd": "${workspaceFolder}/isnd", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/src/.vscode/tasks.json b/src/.vscode/tasks.json new file mode 100644 index 0000000..bf1a328 --- /dev/null +++ b/src/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/isnd/isnd.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/isnd/isnd.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/isnd/isnd.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/src/isn.abst/ApiConfig.cs b/src/isn.abst/ApiConfig.cs index 7c943df..4b8affa 100644 --- a/src/isn.abst/ApiConfig.cs +++ b/src/isn.abst/ApiConfig.cs @@ -12,7 +12,6 @@ namespace isnd.Entities public const string AutoComplete = "/autocomplete"; public const string Registration = "/registration"; - public const string Nuspec = "/nuspec"; public const string ContentBase = "/content"; public const string Nuget = "/nuget"; diff --git a/src/isnd/Controllers/Packages/PackagesController.WebViews.cs b/src/isnd/Controllers/Packages/PackagesController.WebViews.cs index 979377f..fdc4441 100644 --- a/src/isnd/Controllers/Packages/PackagesController.WebViews.cs +++ b/src/isnd/Controllers/Packages/PackagesController.WebViews.cs @@ -28,11 +28,19 @@ namespace isnd.Controllers Query = model }; List registrations = new List(); - foreach (var pk in pkgs.data.GroupBy(x => x.PackageId)) + if (pkgs.data!=null) + if (pkgs.data.Length>0) { - registrations.Add(new Catalog(apiBase, pk.Key, pkgs.GetResults().Single(p=>p.Id == pk.Key).Versions)); + var grouped = pkgs.data.GroupBy(x => x.PackageId); + if (grouped!=null) if (grouped.Count()>0) + { + foreach (var pk in grouped.ToArray()) + { + registrations.Add(new Catalog(apiBase, pk.Key, pkgs.GetResults().Single(p=>p.Id == pk.Key).Versions)); + } + } } - + return View(new RegistrationPageIndexQueryAndResult { Source = packageManager.CatalogBaseUrl+ApiConfig.Index, @@ -80,7 +88,7 @@ namespace isnd.Controllers .FirstOrDefaultAsync(m => m.PackageId == pkgid && m.FullString == version && (pkgtype!=null && m.Type == pkgtype || m.Type != "Delete" )); if (packageVersion == null) return NotFound(); - if (!User.IsOwner(packageVersion)) return Unauthorized(); + if (!User.IsOwner(packageVersion)) return Challenge(); var pkg = await packageManager.GetPackageDetailsAsync(pkgid, version, pkgtype); return View(pkg); } diff --git a/src/isnd/Data/Catalog/RegistratioinLeave.cs b/src/isnd/Data/Catalog/RegistratioinLeave.cs index 4fc9793..ff4c4b2 100644 --- a/src/isnd/Data/Catalog/RegistratioinLeave.cs +++ b/src/isnd/Data/Catalog/RegistratioinLeave.cs @@ -16,7 +16,7 @@ namespace isnd.Data.Catalog this.registration = apiBase + ApiConfig.Registration + "/" + pkgId + "/" + fullVersionString + ".json"; Id = registration; - this.PackageContent = apiBase + ApiConfig.Nuget + "/" + pkgId + "/" + fullVersionString + this.PackageContent = apiBase + ApiConfig.ContentBase + "/" + pkgId + "/" + fullVersionString + "/" + pkgId + "-" + fullVersionString + "." + Constants.PacketFileExtension; Entry = entry; } diff --git a/src/isnd/Data/Packages/Package.cs b/src/isnd/Data/Packages/Package.cs index 8035c3c..920a225 100644 --- a/src/isnd/Data/Packages/Package.cs +++ b/src/isnd/Data/Packages/Package.cs @@ -52,7 +52,7 @@ namespace isnd.Data.Packages public PackageVersion GetLatestVersion() { var latest = Versions.Max(v => v.NugetVersion); - return Versions.First(v=> v.NugetVersion == latest); + return Versions.FirstOrDefault(v=> v.NugetVersion == latest); } } } \ No newline at end of file diff --git a/src/isnd/Data/Packages/PackageVersion.cs b/src/isnd/Data/Packages/PackageVersion.cs index 7f84f4d..d02e76f 100644 --- a/src/isnd/Data/Packages/PackageVersion.cs +++ b/src/isnd/Data/Packages/PackageVersion.cs @@ -66,9 +66,9 @@ namespace isnd.Data public virtual Commit LatestCommit { get; set; } public virtual List DependencyGroups { get; set; } - public string NugetLink => $"{ApiConfig.Nuget}/{PackageId}/{FullString}/{PackageId}-{FullString}." + public string NugetLink => $"{ApiConfig.ContentBase}/{PackageId}/{FullString}/{PackageId}-{FullString}." + Constants.PacketFileExtension; - public string NuspecLink => $"{ApiConfig.Nuspec}/{PackageId}/{FullString}/{PackageId}-{FullString}." + public string NuspecLink => $"{ApiConfig.ContentBase}/{PackageId}/{FullString}/{PackageId}-{FullString}." + Constants.SpecFileExtension; public string SementicVersionString { get => $"{Major}.{Minor}.{Patch}"; } diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index b731a17..26e5d85 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -348,13 +348,20 @@ namespace isnd.Services { string bid = $"{apiBase}{ApiConfig.Registration}"; if (string.IsNullOrWhiteSpace(query.Query)) + { query.Query = ""; + return new PackageSearchResult(apiBase); + } - var packages = await dbContext.Packages + var allPackages = dbContext.Packages .Include(g => g.Versions).OrderBy(v => v.CommitNId) .Where(d => d.Id.StartsWith(query.Query) && (query.Prerelease || d.Versions.Any(v => !v.IsPrerelease))) - .Where(p => p.Versions.Count >= 0) + .Where(p => p.Versions.Count >= 0); + + var count = await allPackages.CountAsync(); + + var packages = await allPackages .Skip(query.Skip).Take(query.Take).ToArrayAsync(); foreach (var package in packages) foreach (var version in package.Versions) @@ -364,7 +371,8 @@ namespace isnd.Services .ToList(); } - return new PackageSearchResult(packages, apiBase, packages.Count()); + + return new PackageSearchResult(packages, apiBase, count); } public async Task PutPackageAsync(Stream packageStream, string ownerId) diff --git a/src/isnd/ViewModels/PackageHit.cs b/src/isnd/ViewModels/PackageHit.cs index cfea0f9..267edeb 100644 --- a/src/isnd/ViewModels/PackageHit.cs +++ b/src/isnd/ViewModels/PackageHit.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using System.Diagnostics; using isnd.Data.Catalog; using Newtonsoft.Json; using NuGet.Packaging.Core; @@ -8,10 +9,16 @@ namespace isnd.ViewModels { public class PackageHit : Permalink { - public PackageHit(string registrationId, string packageId) : base(registrationId, "Package") + public PackageHit(string registrationId, string packageId, + + string version, string description + ) : base(registrationId, "Package") { PackageId = packageId; registration = registrationId; + this.verified = verified; + this.description = description; + Debug.Assert(version!=null); } /// diff --git a/src/isnd/ViewModels/PackageSearchResult.cs b/src/isnd/ViewModels/PackageSearchResult.cs index 04c27d0..c3ddddb 100644 --- a/src/isnd/ViewModels/PackageSearchResult.cs +++ b/src/isnd/ViewModels/PackageSearchResult.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; using System.Linq; using System.Reflection.Metadata.Ecma335; using System.Text.Json.Serialization; +using System.Threading; using isnd.Data; using isnd.Data.Packages; using isnd.Entities; @@ -18,16 +20,26 @@ namespace isnd.ViewModels return result; } - private IEnumerable result; + private IEnumerable result=null; [JsonIgnore] public string ApiBase{get; private set;} + public PackageSearchResult(string apiBase) + { + // empty result + this.ApiBase = apiBase; + + } + public PackageSearchResult(IEnumerable result, string apiBase, int totalHit) { + this.result = result; this.ApiBase = apiBase; - data=result.Select(p=> NewPackageHit(apiBase, p)).ToArray(); + + data = (totalHit>0) ? result.Select(p=> NewPackageHit(apiBase, p)).ToArray() + : new PackageHit[0]; this.totalHits = totalHit; } @@ -37,11 +49,10 @@ namespace isnd.ViewModels var latest = package.GetLatestVersion(); if (latest==null) return null; - var pkgHit = new PackageHit(regId, package.Id) - { - version = latest.NugetVersion.ToString(), - description = latest.Description, - }; + var pkgHit = new PackageHit(regId, package.Id, + latest.NugetVersion.ToString(), + latest.Description); + if (package.Versions!=null) { pkgHit.versions = package.Versions @@ -52,8 +63,8 @@ namespace isnd.ViewModels return pkgHit; } - public PackageHit[] data { get; protected set; } + public PackageHit[] data { get; protected set; } = []; - public int totalHits { get; set; } + public int totalHits { get; set; } = 0; } } \ No newline at end of file diff --git a/src/isnd/Views/Packages/Delete.cshtml b/src/isnd/Views/Packages/Delete.cshtml index bb006ef..d298c81 100644 --- a/src/isnd/Views/Packages/Delete.cshtml +++ b/src/isnd/Views/Packages/Delete.cshtml @@ -1,4 +1,4 @@ -@model isnd.Data.PackageVersion +@model PackageDetails @{ ViewData["Title"] = "Delete"; @@ -12,40 +12,40 @@
- @Html.DisplayNameFor(model => model.Major) + @Html.DisplayNameFor(model => model.Title)
- @Html.DisplayFor(model => model.Major) + @Html.DisplayFor(model => model.Title)
- @Html.DisplayNameFor(model => model.Minor) + @Html.DisplayNameFor(model => model.Id)
- @Html.DisplayFor(model => model.Minor) + @Html.DisplayFor(model => model.Id)
- @Html.DisplayNameFor(model => model.Patch) + @Html.DisplayNameFor(model => model.Version)
- @Html.DisplayFor(model => model.Patch) + @Html.DisplayFor(model => model.Version)
- @Html.DisplayNameFor(model => model.IsPrerelease) + @Html.DisplayNameFor(model => model.Description)
- @Html.DisplayFor(model => model.IsPrerelease) + @Html.DisplayFor(model => model.Description)
- @Html.DisplayNameFor(model => model.Package) + @Html.DisplayNameFor(model => model.DownloadCount)
- @Html.DisplayFor(model => model.Package.Id) + @Html.DisplayFor(model => model.DownloadCount)
@if (Model!=null) {
- + | Back to List diff --git a/test/data/test-isn/test-isn.csproj b/test/data/test-isn/test-isn.csproj index e1b387e..fd00bd2 100644 --- a/test/data/test-isn/test-isn.csproj +++ b/test/data/test-isn/test-isn.csproj @@ -13,6 +13,8 @@ + +