isn/src/isnd/Controllers/Packages/Files.cs

51 lines
1.7 KiB
C#
Raw Normal View History

2021-09-05 15:44:47 +01:00
using System.ComponentModel.DataAnnotations;
using System.IO;
using Microsoft.AspNetCore.Mvc;
2021-09-05 19:33:39 +01:00
using isnd.Attributes;
2022-04-17 16:22:40 +01:00
using isnd.Entities;
2021-09-05 15:44:47 +01:00
namespace isnd.Controllers
{
public partial class PackagesController
{
2022-04-17 16:22:40 +01:00
// Web get nupkg
2021-09-05 15:44:47 +01:00
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")]
public IActionResult GetPackage(
[FromRoute][SafeName][Required] string id,
[FromRoute][SafeName][Required] string lower,
[FromRoute] string idf, [FromRoute] string lowerf)
{
2022-04-18 20:58:46 +01:00
var pkgpath = Path.Combine(isndSettings.PackagesRootDir,
2021-09-05 15:44:47 +01:00
id, lower, $"{id}-{lower}.nupkg"
);
FileInfo pkgfi = new FileInfo(pkgpath);
if (!pkgfi.Exists)
{
return BadRequest("!pkgfi.Exists");
}
return File(pkgfi.OpenRead(), "application/zip; charset=binary");
}
2022-04-17 16:22:40 +01:00
// Web get spec
2021-09-05 15:44:47 +01:00
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")]
public IActionResult GetNuspec(
[FromRoute][SafeName][Required] string id,
[FromRoute][SafeName][Required] string lower,
[FromRoute][SafeName][Required] string idf,
[FromRoute][SafeName][Required] string lowerf)
{
2022-04-18 20:58:46 +01:00
var pkgpath = Path.Combine(isndSettings.PackagesRootDir,
2021-09-05 15:44:47 +01:00
id, lower, $"{id}.nuspec");
FileInfo pkgfi = new FileInfo(pkgpath);
if (!pkgfi.Exists)
{
return BadRequest("!pkgfi.Exists");
}
return File(pkgfi.OpenRead(), "text/xml; charset=utf-8");
}
}
}