This commit is contained in:
Paul Schneider 2021-05-11 23:01:11 +01:00
commit 97dec15153
5 changed files with 75 additions and 78 deletions

View file

@ -39,75 +39,63 @@ namespace nuget_host.Controllers
this.dbContext = dbContext;
}
[HttpPut("packages/{*spec}")]
public IActionResult Put(string spec)
[HttpPut("packages")]
public IActionResult Put()
{
string path = null;
if (string.IsNullOrEmpty(spec))
var clientVersionId = Request.Headers["X-NuGet-Client-Version"];
var apiKey = Request.Headers["X-NuGet-ApiKey"];
ViewData["nuget client"] = "nuget {clientVersionId}";
var clearkey = protector.Unprotect(apiKey);
var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey);
if (apikey == null)
return new BadRequestObjectResult(new { error = "api-key" });
foreach (var file in Request.Form.Files)
{
var clientVersionId = Request.Headers["X-NuGet-Client-Version"];
var apiKey = Request.Headers["X-NuGet-ApiKey"];
ViewData["nuget client"] = "nuget {clientVersionId}";
var clearkey = protector.Unprotect(apiKey);
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey);
if (apikey == null)
return new BadRequestObjectResult(new {error = "api-key"});
foreach (var file in Request.Form.Files)
string initpath = "package.nupkg";
using (FileStream fw = new FileStream(initpath, FileMode.Create))
{
string initpath = "package.nupkg";
using (FileStream fw = new FileStream(initpath, FileMode.Create))
{
file.CopyTo(fw);
}
file.CopyTo(fw);
}
using (FileStream fw = new FileStream(initpath, FileMode.Open))
using (FileStream fw = new FileStream(initpath, FileMode.Open))
{
var archive = new System.IO.Compression.ZipArchive(fw);
foreach (var entry in archive.Entries)
{
var archive = new System.IO.Compression.ZipArchive(fw);
foreach (var entry in archive.Entries)
if (entry.FullName.EndsWith(".nuspec"))
{
if (entry.FullName.EndsWith(".nuspec"))
{
// var entry = archive.GetEntry(filename);
var specstr = entry.Open();
NuGet.Packaging.Core.NuspecCoreReader reader = new NuspecCoreReader(specstr);
// var entry = archive.GetEntry(filename);
var specstr = entry.Open();
NuGet.Packaging.Core.NuspecCoreReader reader = new NuspecCoreReader(specstr);
string pkgdesc = reader.GetDescription();
string pkgid = reader.GetId();
var version = reader.GetVersion();
string pkgdesc = reader.GetDescription();
string pkgid = reader.GetId();
var version = reader.GetVersion();
path = Path.Combine(nugetSettings.PackagesRootDir,
Path.Combine(pkgid,
Path.Combine(version.Version.ToString()),
$"{pkgid}-{version}.nupkg"));
var source = new FileInfo(initpath);
var dest = new FileInfo(path);
var destdir = new DirectoryInfo(dest.DirectoryName);
if (dest.Exists)
return BadRequest(new {error = "existant"});
if (!destdir.Exists) destdir.Create();
source.MoveTo(path);
logger.LogWarning($"200: {entry.Name}");
}
path = Path.Combine(nugetSettings.PackagesRootDir,
Path.Combine(pkgid,
Path.Combine(version.Version.ToString()),
$"{pkgid}-{version}.nupkg"));
var source = new FileInfo(initpath);
var dest = new FileInfo(path);
var destdir = new DirectoryInfo(dest.DirectoryName);
if (dest.Exists)
return BadRequest(new { error = "existant" });
if (!destdir.Exists) destdir.Create();
source.MoveTo(path);
logger.LogWarning($"200: {entry.Name}");
}
}
}
}
else
{
logger.LogWarning("400");
return new BadRequestObjectResult(ViewData);
}
return Ok(ViewData);
}