This commit is contained in:
Paul Schneider 2023-03-18 12:50:31 +00:00
commit 34d0c3c4fe
16 changed files with 241 additions and 37 deletions

View file

@ -5,5 +5,6 @@ namespace isn.abst
public const string PaquetFileEstension = "nupkg";
public const string SpecFileEstension = "nuspec";
public const string JsonFileEstension = "json";
public const string PackageRootServerPrefix = "~/pkgs/";
}
}

View file

@ -1,35 +1,39 @@
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NuGet.Versioning;
using isnd.Data;
using isnd.Entities;
using Unleash;
using isnd.Services;
using isnd.ViewModels;
using System.Threading.Tasks;
using isnd.Interfaces;
using isn.Abstract;
using isn.abst;
using isnd.Interfaces;
using Unleash;
using System.Linq;
namespace isnd.Controllers
{
/// <summary>
/// Packages Controller
/// Api Controller
/// </summary>
public partial class PackagesController : Controller
public class ApiController : Controller
{
private readonly IPackageManager packageManager;
private readonly Resource[] resources;
/// <summary>
/// Api Controller Constructor
/// </summary>
/// <param name="pm"></param>
/// <param name="unleashĈlient"></param>
public ApiController(IPackageManager pm, IUnleash unleashĈlient)
{
packageManager = pm;
resources = packageManager.GetResources(unleashĈlient).ToArray();
}
/// <summary>
/// API index
/// </summary>
/// <returns></returns>
[HttpGet(_pkgRootPrefix + ApiConfig.IndexDotJson)]
[HttpGet(Constants.PackageRootServerPrefix + ApiConfig.IndexDotJson)]
public IActionResult ApiIndex()
{
return Ok(new ApiIndexViewModel(packageManager.CatalogBaseUrl + ApiConfig.IndexDotJson){ Version = PackageManager.BASE_API_LEVEL, Resources = resources });

View file

@ -1,14 +1,15 @@
using isnd.Services;
using isnd.Entities;
using Microsoft.AspNetCore.Mvc;
using isn.abst;
namespace isnd.Controllers
{
public partial class PackagesController
public partial class PackagesController
{
// GET /autocomplete?id=isn.protocol&prerelease=true
[HttpGet(_pkgRootPrefix + ApiConfig.AutoComplete)]
[HttpGet(Constants.PackageRootServerPrefix + ApiConfig.AutoComplete)]
public IActionResult AutoComplete(
string id,
string semVerLevel,

View file

@ -8,6 +8,7 @@ using System.Collections.Generic;
using NuGet.Versioning;
using isnd.Data.Packages.Catalog;
using isnd.Data.Catalog;
using isn.abst;
namespace isnd.Controllers
{
@ -15,14 +16,14 @@ namespace isnd.Controllers
{
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
[HttpGet(_pkgRootPrefix + ApiConfig.Catalog)]
[HttpGet(Constants.PackageRootServerPrefix + ApiConfig.Catalog)]
public async Task<IActionResult> CatalogIndex()
{
return Ok(await packageManager.GetCatalogIndexAsync());
}
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{lower}.json")]
[HttpGet(Constants.PackageRootServerPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{lower}.json")]
public async Task<IActionResult> CatalogRegistration(string apiVersion, string id, string lower)
{
if (lower.Equals("index", System.StringComparison.InvariantCultureIgnoreCase))
@ -38,7 +39,7 @@ namespace isnd.Controllers
return Ok(index);
}
// return a Package
var leaf = await packageManager.GetCatalogLeafAsync(id, lower, null);
var leaf = await packageManager.GetCatalogEntryAsync(id, lower, null);
if (null == leaf) return NotFound(new { id, lower });
return Ok(leaf);

View file

@ -5,12 +5,13 @@ using isnd.Entities;
using System.ComponentModel.DataAnnotations;
using isnd.Attributes;
using System.Security.Claims;
using isn.abst;
namespace isnd.Controllers
{
public partial class PackagesController
{
[HttpDelete(_pkgRootPrefix + ApiConfig.Delete + "/{id}/{lower?}/{type?}")]
[HttpDelete(Constants.PackageRootServerPrefix + ApiConfig.Delete + "/{id}/{lower?}/{type?}")]
public async Task<IActionResult> ApiDelete(
[FromRoute][SafeName][Required] string id,
[FromRoute][SafeName][Required] string lower,

View file

@ -11,7 +11,7 @@ namespace isnd.Controllers
public partial class PackagesController
{
// Web get the paquet
[HttpGet(_pkgRootPrefix + ApiConfig.GetPackage + "/{id}/{lower}/{idf}-{lowerf}."
[HttpGet(Constants.PackageRootServerPrefix + ApiConfig.GetPackage + "/{id}/{lower}/{idf}-{lowerf}."
+ Constants.PaquetFileEstension)]
public IActionResult GetPackage(
[FromRoute][SafeName][Required] string id,
@ -32,7 +32,7 @@ namespace isnd.Controllers
}
// Web get spec
[HttpGet(_pkgRootPrefix + Constants.SpecFileEstension + "/{id}/{lower}/{idf}-{lowerf}."
[HttpGet(Constants.PackageRootServerPrefix + Constants.SpecFileEstension + "/{id}/{lower}/{idf}-{lowerf}."
+ Constants.SpecFileEstension)]
public IActionResult GetNuspec(
[FromRoute][SafeName][Required] string id,

View file

@ -7,7 +7,7 @@ namespace isnd.Controllers
{
public partial class PackagesController
{
[HttpGet(_pkgRootPrefix + ApiConfig.GetVersion + "/{id}/{lower}/" + ApiConfig.IndexDotJson)]
[HttpGet(Constants.PackageRootServerPrefix + ApiConfig.GetVersion + "/{id}/{lower}/" + ApiConfig.IndexDotJson)]
public IActionResult GetVersions(
string id,
string lower,

View file

@ -25,7 +25,7 @@ namespace isnd.Controllers
public partial class PackagesController
{
// TODO [Authorize(Policy = IsndConstants.RequireValidApiKey)]
[HttpPut(_pkgRootPrefix + ApiConfig.Publish)]
[HttpPut(Constants.PackageRootServerPrefix + ApiConfig.Publish)]
public async Task<IActionResult> Put()
{
try

View file

@ -3,6 +3,7 @@ using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using isnd.Entities;
using isn.abst;
namespace isnd.Controllers
{
@ -10,7 +11,7 @@ namespace isnd.Controllers
public partial class PackagesController
{
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
[HttpGet(_pkgRootPrefix + ApiConfig.Search)]
[HttpGet(Constants.PackageRootServerPrefix + ApiConfig.Search)]
public IActionResult Search(
string q,
int skip = 0,

View file

@ -31,7 +31,6 @@ namespace isnd.Controllers
readonly ApplicationDbContext dbContext;
private readonly IPackageManager packageManager;
private readonly IUnleash unleashĈlient;
const string _pkgRootPrefix = "~/";
public PackagesController(
ILoggerFactory loggerFactory,

View file

@ -38,7 +38,7 @@ namespace isnd.Data.Catalog
[JsonProperty("@type")]
public string[] RefType { get; set; }
public string[] RefType { get; protected set; } = new string[] { "PackageDetail" };
[JsonProperty("commitId")]
public string CommitId { get; set; }

View file

@ -24,8 +24,8 @@ namespace isnd.Interfaces
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type);
Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type);
Task<CatalogEntry> GetCatalogLeafAsync(string pkgId, string version, string pkgType);
IEnumerable<CatalogEntry> SearchById(string pkgId, string semver, string pkgType);
Task<CatalogEntry> GetCatalogEntryAsync(string pkgId, string version, string pkgType);
IEnumerable<CatalogEntry> SearchCatalogEntriesById(string pkgId, string semver, string pkgType);
Task<RegistrationPageIndex> GetCatalogIndexAsync();
Task<RegistrationPageIndex> GetPackageRegistrationIndexAsync(RegistrationPageIndexQuery query);

View file

@ -234,7 +234,7 @@ namespace isnd.Services
);
}
public async Task<CatalogEntry> GetCatalogLeafAsync(string pkgId, string semver = null, string pkgType = null)
public async Task<CatalogEntry> GetCatalogEntryAsync(string pkgId, string semver = null, string pkgType = null)
{
return (await dbContext.PackageVersions
.Include(v => v.Package)
@ -258,7 +258,7 @@ namespace isnd.Services
public string BID { get => $"{extUrl}v3.4.0/{ApiConfig.Registration}"; }
public IEnumerable<CatalogEntry> SearchById(string pkgId, string semver, string pkgType)
public IEnumerable<CatalogEntry> SearchCatalogEntriesById(string pkgId, string semver, string pkgType)
{
return dbContext.PackageVersions