From fcea41f8c1ea41341c634ce5993520746b39b7b4 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 24 Sep 2022 12:32:00 +0100 Subject: [PATCH] Catalog++ --- src/isnd/Controllers/Packages/Catalog.cs | 35 +++++++----------- src/isnd/Data/Packages/Package.cs | 2 +- src/isnd/Data/Packages/PackageVersion.cs | 1 + src/isnd/Helpers/SiteHelpers.cs | 4 +++ src/isnd/Interfaces/IPackageManager.cs | 5 +-- src/isnd/Services/PackageManager.cs | 26 ++++++++++++-- src/isnd/ViewModels/RegistrationLeaf.cs | 45 ------------------------ src/isnd/isnd.csproj | 6 ++-- 8 files changed, 48 insertions(+), 76 deletions(-) delete mode 100644 src/isnd/ViewModels/RegistrationLeaf.cs diff --git a/src/isnd/Controllers/Packages/Catalog.cs b/src/isnd/Controllers/Packages/Catalog.cs index fc4d9b3..587abfc 100644 --- a/src/isnd/Controllers/Packages/Catalog.cs +++ b/src/isnd/Controllers/Packages/Catalog.cs @@ -24,24 +24,20 @@ namespace isnd.Controllers return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]); } - [HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration - + "/{id}/index.json")] - public async Task CatalogRegistrationAsync(string apiVersion, string id, string lower) + [HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/index.json")] + public async Task CatalogRegistrationAsync(string apiVersion, string id) { + var pkgs = packageManager.SearchById(id, null, null); + if (pkgs == null) return NotFound(); + return Ok(pkgs); + } + + [HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")] + public async Task CatalogLeafAsync(string id, string pversion, string lower) + { + bool askForindex = lower == null; - if (askForindex) - { - string sublower = lower.Substring(0, lower.Length - ApiConfig.IndexDotJson.Length); - - var pkgFromname = packageManager.SearchByName(id, 0, 1); - if (pkgFromname == null) return NotFound(); - foreach (var item in pkgFromname.Items) - { - item.Id = this.Url.Action(); - } - return Ok(pkgFromname); - } - else + if (false) { if (!NuGetVersion.TryParse(lower, out NuGetVersion version)) return BadRequest(lower); @@ -50,12 +46,7 @@ namespace isnd.Controllers if (pkgFromname == null) return NotFound(); return Ok(pkgFromname); } - } - - [HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")] - public async Task CatalogLeafAsync(string id, string version, string lower) - { - var pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower).ToArray(); + var pkgvs = this.packageManager.GetCatalogLeaf(id, pversion, lower).ToArray(); if (pkgvs.Count() == 0) return NotFound(); List types = pkgvs.Select( v => v.Type ?? "Dependency" diff --git a/src/isnd/Data/Packages/Package.cs b/src/isnd/Data/Packages/Package.cs index c3a02e0..a3f15fd 100644 --- a/src/isnd/Data/Packages/Package.cs +++ b/src/isnd/Data/Packages/Package.cs @@ -51,7 +51,7 @@ namespace isnd.Data.Packages /// /// base url tu use for building the id property /// - internal RegistrationLeaf ToLeave(string bid) + public RegistrationLeaf ToLeave(string bid) { if (Versions.Count == 0) throw new Exception("NO VERSION"); var v = Versions.First(); diff --git a/src/isnd/Data/Packages/PackageVersion.cs b/src/isnd/Data/Packages/PackageVersion.cs index 37a9ce6..a448261 100644 --- a/src/isnd/Data/Packages/PackageVersion.cs +++ b/src/isnd/Data/Packages/PackageVersion.cs @@ -49,5 +49,6 @@ namespace isnd.Data public string NuspecLink => $"/{Constants.SpecFileEstension}/{PackageId}/{FullString}/{PackageId}-{FullString}." + Constants.SpecFileEstension; + public string SementicVersionString { get => $"{Major}.{Minor}.{Patch}"; } } } \ No newline at end of file diff --git a/src/isnd/Helpers/SiteHelpers.cs b/src/isnd/Helpers/SiteHelpers.cs index d9cb317..cb5f5c5 100644 --- a/src/isnd/Helpers/SiteHelpers.cs +++ b/src/isnd/Helpers/SiteHelpers.cs @@ -2,6 +2,10 @@ namespace isnd.Helpers { public static class SiteHelpers { + /// + /// The Git Sementic version (from GitVersion.MsBuild)[published] + /// + /// public static string SemVer { get => GitVersionInformation.SemVer; } diff --git a/src/isnd/Interfaces/IPackageManager.cs b/src/isnd/Interfaces/IPackageManager.cs index ab30b95..d5de83f 100644 --- a/src/isnd/Interfaces/IPackageManager.cs +++ b/src/isnd/Interfaces/IPackageManager.cs @@ -24,9 +24,10 @@ namespace isnd.Interfaces IEnumerable GetResources(IUnleash unleashĈlient); void ÛpdateCatalogFor(Commit commit); Task DeletePackageAsync(string pkgid, string version, string type); - Task UserAskForPackageDeletionAsync(string uid, string id, string lower, string type); + Task UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type); Task GetPackageAsync(string pkgid, string version, string type); - IEnumerable GetCatalogLeaf(string id, string version, string lower); + IEnumerable GetCatalogLeaf(string pkgId, string semver, string pkgType); + IEnumerable SearchById(string pkgId, string semver, string pkgType); } } \ No newline at end of file diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index 59bf859..aae083b 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -323,13 +323,15 @@ namespace isnd.Services ); } - public IEnumerable GetCatalogLeaf(string id, string version, string lower) + public IEnumerable GetCatalogLeaf(string pkgId, string semver, string pkgType) { return dbContext.PackageVersions .Include(v => v.Package) .Include(v => v.LatestCommit) - .Where(v => v.PackageId == id && v.FullString == version - && (lower == null || lower == v.Type)); + .Where(v => v.PackageId == pkgId + && (semver == null || + semver.StartsWith(v.SementicVersionString)) + && (pkgType == null || pkgType == v.Type)); } @@ -344,5 +346,23 @@ namespace isnd.Services if (packageVersion.Package.OwnerId != uid) return null; return new PackageDeletionReport { Deleted = true, DeletedVersion = packageVersion }; } + + public IEnumerable SearchById(string pkgId, string semver, string pkgType) + { + string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}/"; + return dbContext.PackageVersions + .Include(v => v.Package) + .Include(v => v.LatestCommit) + .Where(v => v.PackageId == pkgId && semver.StartsWith(v.SementicVersionString) + && (pkgType == null || pkgType == v.Type)).Select(p => p.Package.ToLeave(bid)); + } + public PackageVersion GetPackage(string pkgId, string semver, string pkgType) + { + return dbContext.PackageVersions + .Include(v => v.Package) + .Include(v => v.LatestCommit) + .Single(v => v.PackageId == pkgId && semver == v.FullString + && (pkgType == null || pkgType == v.Type)); + } } } \ No newline at end of file diff --git a/src/isnd/ViewModels/RegistrationLeaf.cs b/src/isnd/ViewModels/RegistrationLeaf.cs deleted file mode 100644 index 7f410e8..0000000 --- a/src/isnd/ViewModels/RegistrationLeaf.cs +++ /dev/null @@ -1,45 +0,0 @@ -using isnd.Data.Packages; - -namespace isnd.ViewModels -{ - public class RegistrationLeaf - { - /* -@id string yes The URL to the registration leaf -catalogEntry object yes The catalog entry containing the package metadata -packageContent string yes The URL to the package content (.nupkg) - */ - public static RegistrationLeaf FromPackage(Package p) - { - RegistrationLeaf v = new RegistrationLeaf - { - - }; - return v; - } - } - public class CatalogEntry - { - /* - @id string yes The URL to the document used to produce this object -authors string or array of strings no -dependencyGroups array of objects no The dependencies of the package, grouped by target framework -deprecation object no The deprecation associated with the package -description string no -iconUrl string no -id string yes The ID of the package -licenseUrl string no -licenseExpression string no -listed boolean no Should be considered as listed if absent -minClientVersion string no -projectUrl string no -published string no A string containing a ISO 8601 timestamp of when the package was published -requireLicenseAcceptance boolean no -summary string no -tags string or array of string no -title string no -version string yes The full version string after normalization -vulnerabilities array of objects no The security vulnerabilities of the package - */ - } -} \ No newline at end of file diff --git a/src/isnd/isnd.csproj b/src/isnd/isnd.csproj index 1e4bae4..21e2d71 100644 --- a/src/isnd/isnd.csproj +++ b/src/isnd/isnd.csproj @@ -17,9 +17,9 @@ - + - + @@ -28,7 +28,7 @@ All - +