|
|
using System.ComponentModel.DataAnnotations;
|
|
|
using System.IO;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using isnd.Attributes;
|
|
|
using isnd.Entities;
|
|
|
using isn.abst;
|
|
|
using System.Linq;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
namespace isnd.Controllers
|
|
|
{
|
|
|
public partial class PackagesController
|
|
|
{
|
|
|
|
|
|
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.ContentBase + "/{id}/{version}/{idf}.{versionFromName}."
|
|
|
+ Constants.PacketFileExtension)]
|
|
|
public IActionResult GetPackage(
|
|
|
[FromRoute][SafeName][Required] string id,
|
|
|
[FromRoute][SafeName][Required] string version,
|
|
|
[FromRoute] string idf,
|
|
|
[FromRoute] string versionFromName)
|
|
|
{
|
|
|
DirectoryInfo pkgsDirInfo = new DirectoryInfo(isndSettings.PackagesRootDir);
|
|
|
|
|
|
var pkgDirInfo = pkgsDirInfo.GetDirectories().FirstOrDefault(
|
|
|
s=>string.Compare(s.Name,id, System.StringComparison.InvariantCultureIgnoreCase)==0);
|
|
|
if (pkgDirInfo==null)
|
|
|
return BadRequest("Package does´nt exist in the file system.");
|
|
|
var pkgVersionDirInfo = pkgDirInfo.GetDirectories().FirstOrDefault(
|
|
|
s=>s.Name==version);
|
|
|
if (pkgVersionDirInfo==null)
|
|
|
return BadRequest("Package does´nt exist in the specified version.");
|
|
|
|
|
|
var pkgNameSpec=$"{id}-{version}.{Constants.PacketFileExtension}";
|
|
|
|
|
|
FileInfo pkgFileInfo = pkgVersionDirInfo.GetFiles()
|
|
|
.FirstOrDefault(p=>string.Compare(p.Name,pkgNameSpec,
|
|
|
System.StringComparison.InvariantCultureIgnoreCase)==0);
|
|
|
|
|
|
if (pkgFileInfo==null || !pkgFileInfo.Exists)
|
|
|
{
|
|
|
logger.LogError($"Not found in {pkgVersionDirInfo.FullName} : {pkgNameSpec}");
|
|
|
return BadRequest("Package version does´nt exist in the file system.");
|
|
|
}
|
|
|
return File(pkgFileInfo.OpenRead(), "application/zip; charset=binary");
|
|
|
}
|
|
|
|
|
|
// Web get spec
|
|
|
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.ContentBase + "/{id}/{lower}/{idf}-{lowerFromName}."
|
|
|
+ Constants.SpecFileExtension)]
|
|
|
public IActionResult GetNuspec(
|
|
|
[FromRoute][SafeName][Required] string id,
|
|
|
[FromRoute][SafeName][Required] string lower,
|
|
|
[FromRoute][SafeName][Required] string idf,
|
|
|
[FromRoute][SafeName][Required] string lowerFromName)
|
|
|
{
|
|
|
var pkgPath = Path.Combine(isndSettings.PackagesRootDir,
|
|
|
id, lower, $"{id}." + Constants.SpecFileExtension);
|
|
|
|
|
|
FileInfo pkgFileInfo = new FileInfo(pkgPath);
|
|
|
if (!pkgFileInfo.Exists)
|
|
|
{
|
|
|
return BadRequest("Package info does´nt exist in the file system.");
|
|
|
}
|
|
|
|
|
|
return File(pkgFileInfo.OpenRead(), "text/xml; charset=utf-8");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |