REORG+histo

This commit is contained in:
Paul Schneider 2021-09-05 15:44:47 +01:00
commit 6dd76ac1a5
28 changed files with 948 additions and 159 deletions

View file

@ -18,7 +18,6 @@ using isnd.Interfaces;
namespace isnd.Controllers
{
[AllowAnonymous]
public partial class PackagesController : Controller
{
@ -33,6 +32,7 @@ namespace isnd.Controllers
readonly ApplicationDbContext _dbContext;
private readonly IPackageManager _packageManager;
private readonly IUnleash _unleashĈlient;
const string _pkgRootPrefix = "~/";
public PackagesController(
ILoggerFactory loggerFactory,
@ -51,72 +51,12 @@ namespace isnd.Controllers
_ressources = _packageManager.GetResources(_unleashĈlient).ToArray();
}
// dotnet add . package -s http://localhost:5000/packages isn
// packages/FindPackagesById()?id='isn'&semVerLevel=2.0.0
// Search
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
// GET: PackageVersion
public async Task<IActionResult> Index(PackageIndexViewModel model)
{
var applicationDbContext = _dbContext.Packages.Include(p => p.Versions).Where(
p => ( model.Prerelease || p.Versions.Any(v => !v.IsPrerelease))
&& ((model.query == null) || p.Id.StartsWith(model.query)));
model.data = await applicationDbContext.ToArrayAsync();
return View(model);
}
// GET: PackageVersion/Details/5
public async Task<IActionResult> Details(string pkgid)
{
if (pkgid == null)
{
return NotFound();
}
var packageVersion = _dbContext.PackageVersions
.Include(p => p.Package)
.Where(m => m.PackageId == pkgid)
.OrderByDescending(p => p)
;
if (packageVersion == null)
{
return NotFound();
}
bool results = await packageVersion.AnyAsync();
var latest = await packageVersion.FirstAsync();
return View("Details", new PackageDetailViewModel { latest = latest, pkgid = pkgid, totalHits = packageVersion.Count(), data = packageVersion.Take(10).ToArray() } );
}
const string _pkgRootPrefix = "~/" + ApiConfig.BaseApiPath ;
[HttpGet(_pkgRootPrefix + ApiConfig.Base)]
public IActionResult ApiIndex()
{
return Ok(_ressources);
}
//
[HttpGet(_pkgRootPrefix + ApiConfig.Catalog)]
public IActionResult CatalogIndex()
{
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
return Ok(PackageManager.CurrentCatalogIndex);
}
[HttpGet(_pkgRootPrefix + ApiConfig.Catalog + "-{id}")]
public IActionResult Index(string id)
{
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
}
// GET /autocomplete?id=isn.protocol&prerelease=true
[HttpGet(_pkgRootPrefix + ApiConfig.AutoComplete)]
public IActionResult AutoComplete(
@ -170,48 +110,5 @@ namespace isnd.Controllers
id, parsedVersion, prerelease, packageType, skip, take)
});
}
// TODO GET GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.{LOWER_VERSION}.nupkg
// LOWER_ID URL string yes The package ID, lowercase
// LOWER_VERSION URL string yes The package version, normalized and lowercased
// response 200 : the package
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")]
public IActionResult GetPackage(
[FromRoute] string id, [FromRoute] string lower,
[FromRoute] string idf, [FromRoute] string lowerf)
{
var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
id, lower, $"{id}-{lower}.nupkg"
);
FileInfo pkgfi = new FileInfo(pkgpath);
if (!pkgfi.Exists)
{
return BadRequest("!pkgfi.Exists");
}
return File(pkgfi.OpenRead(), "application/zip; charset=binary");
}
// TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec
// response 200 : the nuspec
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")]
public IActionResult GetNuspec(
[FromRoute][SafeName][Required] string id,
[FromRoute][SafeName][Required] string lower,
[FromRoute][SafeName][Required] string idf,
[FromRoute][SafeName][Required] string lowerf)
{
var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
id, lower, $"{id}.nuspec");
FileInfo pkgfi = new FileInfo(pkgpath);
if (!pkgfi.Exists)
{
return BadRequest("!pkgfi.Exists");
}
return File(pkgfi.OpenRead(), "text/xml; charset=utf-8");
}
}
}