WIP reg page
This commit is contained in:
@ -1,18 +1,15 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Helpers;
|
||||
using isnd.Services;
|
||||
using isnd.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using NuGet.Versioning;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
||||
public partial class PackagesController
|
||||
{
|
||||
|
||||
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Catalog)]
|
||||
public IActionResult CatalogIndex()
|
||||
@ -27,40 +24,46 @@ namespace isnd.Controllers
|
||||
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
|
||||
}
|
||||
|
||||
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{*lower}")]
|
||||
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration
|
||||
+ "/{id}/index.json")]
|
||||
public async Task<IActionResult> CatalogRegistrationAsync(string apiVersion, string id, string lower)
|
||||
{
|
||||
bool askForindex = lower != null && lower.EndsWith(ApiConfig.Base);
|
||||
bool askForindex = lower == null;
|
||||
if (askForindex)
|
||||
{
|
||||
lower = lower.Substring(0, lower.Length - ApiConfig.Base.Length);
|
||||
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 (!NuGetVersion.TryParse(lower, out NuGetVersion version))
|
||||
return BadRequest(lower);
|
||||
|
||||
var pkgFromname = packageManager.GetVersions(id, version, true);
|
||||
if (pkgFromname == null) return NotFound();
|
||||
return Ok(pkgFromname);
|
||||
}
|
||||
string pkgType = ParamHelpers.Optional(ref lower);
|
||||
var pkgFromname = packageManager.SearchByName(id, 0, 1);
|
||||
if (pkgFromname == null) return NotFound();
|
||||
return Ok(pkgFromname);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{*lower}")]
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")]
|
||||
public async Task<IActionResult> CatalogLeafAsync(string id, string version, string lower)
|
||||
{
|
||||
var pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower)
|
||||
.ToArray();
|
||||
|
||||
var pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower).ToArray();
|
||||
if (pkgvs.Count() == 0) return NotFound();
|
||||
|
||||
List<string> types = pkgvs
|
||||
.Select(
|
||||
List<string> types = pkgvs.Select(
|
||||
v => v.Type ?? "Dependency"
|
||||
)
|
||||
.Distinct().ToList();
|
||||
).Distinct().ToList();
|
||||
if (!types.Contains("PackageDelete"))
|
||||
types.Add("PackageDetails");
|
||||
|
||||
var last = pkgvs.Last();
|
||||
var pub = last.LatestCommit.CommitTimeStamp;
|
||||
|
||||
return Ok(new Data.Packages.Catalog.CatalogLeaf
|
||||
{
|
||||
CommitId = last.CommitId,
|
||||
@ -68,10 +71,8 @@ namespace isnd.Controllers
|
||||
CommitTimeStamp = pub,
|
||||
Version = last.FullString,
|
||||
Published = pub,
|
||||
RefType = types.ToArray(),
|
||||
|
||||
RefType = types.ToArray()
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user