isn/src/isnd/Controllers/Packages/PackagesController.GetPackage.cs

55 lines
1.9 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;
2026-07-05 17:22:57 +01:00
using Isn.Abstract;
2022-04-17 16:22:40 +01:00
using isnd.Entities;
2026-07-05 17:22:57 +01:00
using isnd.Attributes;
2022-07-03 14:50:57 +01:00
2021-09-05 15:44:47 +01:00
namespace isnd.Controllers
{
public partial class PackagesController
{
2022-07-03 14:50:57 +01:00
// Web get the paquet
2023-03-18 12:50:31 +00:00
[HttpGet(Constants.PackageRootServerPrefix + ApiConfig.GetPackage + "/{id}/{lower}/{idf}-{lowerf}."
2022-07-03 14:50:57 +01:00
+ Constants.PaquetFileEstension)]
2021-09-05 15:44:47 +01:00
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,
2022-07-03 14:50:57 +01:00
id, lower, $"{id}-{lower}." + Constants.PaquetFileEstension
2021-09-05 15:44:47 +01:00
);
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
2023-03-18 12:50:31 +00:00
[HttpGet(Constants.PackageRootServerPrefix + Constants.SpecFileEstension + "/{id}/{lower}/{idf}-{lowerf}."
2022-07-03 14:50:57 +01:00
+ Constants.SpecFileEstension)]
2021-09-05 15:44:47 +01:00
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,
2022-07-03 14:50:57 +01:00
id, lower, $"{id}." + Constants.SpecFileEstension);
2021-09-05 15:44:47 +01:00
FileInfo pkgfi = new FileInfo(pkgpath);
if (!pkgfi.Exists)
{
return BadRequest("!pkgfi.Exists");
}
return File(pkgfi.OpenRead(), "text/xml; charset=utf-8");
}
}
}