Files
isn/src/isnd/Controllers/Packages/PackagesController.GetVersions.cs
2025-07-08 17:46:11 +01:00

48 lines
1.3 KiB
C#

using Microsoft.AspNetCore.Mvc;
using NuGet.Versioning;
using isnd.Entities;
using isn.abst;
namespace isnd.Controllers
{
public partial class PackagesController
{
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.ContentBase + "/{id}/{version}.json")]
public IActionResult GetVersions(
string id,
string version,
bool prerelease = true,
string packageType = null,
int skip = 0,
int take = 50)
{
NuGetVersion parsedVersion=null;
if (take > maxTake)
{
ModelState.AddModelError("take", "Maximum exceeded");
}
if ("index"==version)
{
version=null;
}
if (version!=null)
{
if (!NuGetVersion.TryParse(version, out parsedVersion))
{
ModelState.AddModelError("version", "invalid version string");
}
}
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok(new
{
versions = packageManager.GetVersions(
id, parsedVersion, prerelease, packageType, skip, take)
});
}
}
}