Web search result fixed

This commit is contained in:
2025-02-01 19:44:31 +00:00
parent 913f2ae5dd
commit bc1464db7f
13 changed files with 146 additions and 35 deletions

View File

@ -1,6 +1,6 @@
CONFIGURATION=Debug
TARGETFV=net7.0
TARGETFV=net8.0
all: build-isn build-isnd

35
src/.vscode/launch.json vendored Normal file
View File

@ -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"
}
]
}

41
src/.vscode/tasks.json vendored Normal file
View File

@ -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"
}
]
}

View File

@ -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";

View File

@ -28,11 +28,19 @@ namespace isnd.Controllers
Query = model
};
List<Catalog> registrations = new List<Catalog>();
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);
}

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -66,9 +66,9 @@ namespace isnd.Data
public virtual Commit LatestCommit { get; set; }
public virtual List<PackageDependencyGroup> 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}"; }

View File

@ -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<PackageVersion> PutPackageAsync(Stream packageStream, string ownerId)

View File

@ -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);
}
/// <summary>

View File

@ -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<Package> result;
private IEnumerable<Package> result=null;
[JsonIgnore]
public string ApiBase{get; private set;}
public PackageSearchResult(string apiBase)
{
// empty result
this.ApiBase = apiBase;
}
public PackageSearchResult(IEnumerable<Package> 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;
}
}

View File

@ -1,4 +1,4 @@
@model isnd.Data.PackageVersion
@model PackageDetails
@{
ViewData["Title"] = "Delete";
@ -12,40 +12,40 @@
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Major)
@Html.DisplayNameFor(model => model.Title)
</dt>
<dd>
@Html.DisplayFor(model => model.Major)
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Minor)
@Html.DisplayNameFor(model => model.Id)
</dt>
<dd>
@Html.DisplayFor(model => model.Minor)
@Html.DisplayFor(model => model.Id)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Patch)
@Html.DisplayNameFor(model => model.Version)
</dt>
<dd>
@Html.DisplayFor(model => model.Patch)
@Html.DisplayFor(model => model.Version)
</dd>
<dt>
@Html.DisplayNameFor(model => model.IsPrerelease)
@Html.DisplayNameFor(model => model.Description)
</dt>
<dd>
@Html.DisplayFor(model => model.IsPrerelease)
@Html.DisplayFor(model => model.Description)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Package)
@Html.DisplayNameFor(model => model.DownloadCount)
</dt>
<dd>
@Html.DisplayFor(model => model.Package.Id)
@Html.DisplayFor(model => model.DownloadCount)
</dd>
</dl>
@if (Model!=null) {
<form asp-action="DeleteConfirmed">
<input type="hidden" name="pkgid" value="@Model.PackageId" />
<input type="hidden" name="version" value="@Model.FullString" />
<input type="hidden" name="version" value="@Model.Version" />
<input type="hidden" name="type" value="@Model.Type" />
<input type="submit" value="Delete" class="btn btn-default" /> |
<a asp-action="Index">Back to List</a>

View File

@ -13,6 +13,8 @@
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="isn.abst" Version="1.0.24" />
</ItemGroup>