69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using isnd.Services;
|
|
using isnd.Entities;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
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()
|
|
{
|
|
return Ok(PackageManager.CurrentCatalogIndex);
|
|
}
|
|
|
|
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogPage + "-{id}")]
|
|
public IActionResult Index(string id)
|
|
{
|
|
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
|
|
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
|
|
}
|
|
|
|
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/index.json")]
|
|
public async Task<IActionResult> 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<IActionResult> CatalogLeafAsync(string id, string pversion, string lower)
|
|
{
|
|
|
|
bool askForindex = lower == null;
|
|
if (false)
|
|
{
|
|
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);
|
|
}
|
|
var pkgvs = this.packageManager.GetCatalogLeaf(id, pversion, lower).ToArray();
|
|
if (pkgvs.Count() == 0) return NotFound();
|
|
List<string> types = pkgvs.Select(
|
|
v => v.Type ?? "Dependency"
|
|
).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,
|
|
Id = id,
|
|
CommitTimeStamp = pub,
|
|
Version = last.FullString,
|
|
Published = pub,
|
|
RefType = types.ToArray()
|
|
});
|
|
}
|
|
}
|
|
} |