2021-09-05 15:44:47 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using isnd.Data.Catalog;
|
|
|
|
|
using isnd.Helpers;
|
|
|
|
|
using isnd.Services;
|
2022-04-17 16:22:40 +01:00
|
|
|
using isnd.Entities;
|
2021-09-05 15:44:47 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-07-03 14:50:57 +01:00
|
|
|
using System.Collections.Generic;
|
2021-09-05 15:44:47 +01:00
|
|
|
|
|
|
|
|
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)]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-03 14:50:57 +01:00
|
|
|
[HttpGet(_pkgRootPrefix + ApiConfig.Registration + "/{id}/{*lower}")]
|
|
|
|
|
public async Task<IActionResult> CatalogRegistrationAsync(string id, string lower)
|
2021-09-05 15:44:47 +01:00
|
|
|
{
|
|
|
|
|
string pkgType = ParamHelpers.Optional(ref lower);
|
2022-04-18 20:58:46 +01:00
|
|
|
var pkgVersion = await dbContext.PackageVersions
|
2022-06-16 17:03:38 +01:00
|
|
|
.Include(v => v.LatestCommit)
|
|
|
|
|
.SingleOrDefaultAsync(
|
2021-09-05 15:44:47 +01:00
|
|
|
v => v.PackageId == id &&
|
|
|
|
|
v.FullString == lower &&
|
|
|
|
|
v.Type == pkgType
|
|
|
|
|
);
|
|
|
|
|
if (pkgVersion == null) return NotFound();
|
2022-07-03 14:50:57 +01:00
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{*lower}")]
|
|
|
|
|
public async Task<IActionResult> CatalogLeafAsync(string id, string version, string lower)
|
|
|
|
|
{
|
|
|
|
|
var pkgvs = this.packageManager.GetCatalogLeaf(id, version, 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 pub = pkgvs.Last().Package.CommitTimeStamp;
|
|
|
|
|
var firstpub = pkgvs.First().Package.CommitTimeStamp;
|
2021-09-05 15:44:47 +01:00
|
|
|
|
|
|
|
|
return Ok(new CatalogLeaf
|
|
|
|
|
{
|
|
|
|
|
CommitId = id,
|
2022-07-03 14:50:57 +01:00
|
|
|
Id = id,
|
|
|
|
|
CommitTimeStamp = firstpub,
|
|
|
|
|
Version = version,
|
|
|
|
|
Published = pub,
|
|
|
|
|
RefType = types.ToArray(),
|
|
|
|
|
|
2021-09-05 15:44:47 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|