2021-09-05 15:44:47 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
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;
|
2022-07-03 14:50:57 +01:00
|
|
|
using System.Collections.Generic;
|
2022-09-23 20:34:51 +01:00
|
|
|
using NuGet.Versioning;
|
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);
|
|
|
|
|
}
|
2022-07-10 17:05:05 +01:00
|
|
|
|
2021-09-05 15:44:47 +01:00
|
|
|
[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-10-15 18:26:55 +01:00
|
|
|
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{lower}.json")]
|
|
|
|
|
public IActionResult CatalogRegistration(string apiVersion, string id, string lower)
|
2021-09-05 15:44:47 +01:00
|
|
|
{
|
2022-10-15 18:26:55 +01:00
|
|
|
if (lower.Equals("index", System.StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var query = new Data.Catalog.RegistrationPageIndexQuery
|
|
|
|
|
{
|
|
|
|
|
Query = id,
|
|
|
|
|
Prerelease = true
|
|
|
|
|
};
|
|
|
|
|
var index = packageManager.GetPackageRegistrationIndex(query);
|
|
|
|
|
if (index == null) return NotFound();
|
|
|
|
|
// query.TotalHits = result.Items.Select(i=>i.Items.Length).Aggregate((a,b)=>a+b);
|
|
|
|
|
return Ok(index);
|
|
|
|
|
}
|
|
|
|
|
var leaf = packageManager.SearchById(id,lower,null);
|
|
|
|
|
if (leaf.Count()==0) return NotFound(new { id, lower });
|
|
|
|
|
return Ok(leaf.First());
|
2022-09-24 12:32:00 +01:00
|
|
|
}
|
|
|
|
|
|
2022-10-15 18:26:55 +01:00
|
|
|
|
2022-09-24 12:32:00 +01:00
|
|
|
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")]
|
2022-10-15 18:26:55 +01:00
|
|
|
public IActionResult CatalogLeaf(string id, string pversion, string lower)
|
2022-09-24 12:32:00 +01:00
|
|
|
{
|
|
|
|
|
|
2022-09-23 20:34:51 +01:00
|
|
|
bool askForindex = lower == null;
|
2022-09-24 12:32:00 +01:00
|
|
|
var pkgvs = this.packageManager.GetCatalogLeaf(id, pversion, lower).ToArray();
|
2022-07-10 17:05:05 +01:00
|
|
|
if (pkgvs.Count() == 0) return NotFound();
|
2022-09-23 20:34:51 +01:00
|
|
|
List<string> types = pkgvs.Select(
|
2022-07-03 14:50:57 +01:00
|
|
|
v => v.Type ?? "Dependency"
|
2022-09-23 20:34:51 +01:00
|
|
|
).Distinct().ToList();
|
2022-07-03 14:50:57 +01:00
|
|
|
if (!types.Contains("PackageDelete"))
|
2022-07-10 17:05:05 +01:00
|
|
|
types.Add("PackageDetails");
|
|
|
|
|
var last = pkgvs.Last();
|
2022-07-29 09:06:59 +01:00
|
|
|
var pub = last.LatestCommit.CommitTimeStamp;
|
2022-07-10 17:05:05 +01:00
|
|
|
return Ok(new Data.Packages.Catalog.CatalogLeaf
|
2021-09-05 15:44:47 +01:00
|
|
|
{
|
2022-07-10 17:05:05 +01:00
|
|
|
CommitId = last.CommitId,
|
2022-07-03 14:50:57 +01:00
|
|
|
Id = id,
|
2022-07-10 17:05:05 +01:00
|
|
|
CommitTimeStamp = pub,
|
|
|
|
|
Version = last.FullString,
|
2022-07-03 14:50:57 +01:00
|
|
|
Published = pub,
|
2022-09-23 20:34:51 +01:00
|
|
|
RefType = types.ToArray()
|
2021-09-05 15:44:47 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|