...
This commit is contained in:
parent
a8c9b7619f
commit
c2f38800aa
6 changed files with 75 additions and 58 deletions
|
|
@ -47,6 +47,8 @@ namespace nuget_host.Controllers
|
|||
var clientVersionId = Request.Headers["X-NuGet-Client-Version"];
|
||||
var apiKey = Request.Headers["X-NuGet-ApiKey"];
|
||||
ViewData["nuget client"] = "nuget {clientVersionId}";
|
||||
var files = new List<string>();
|
||||
ViewData["files"] = files;
|
||||
|
||||
var clearkey = protector.Unprotect(apiKey);
|
||||
var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey);
|
||||
|
|
@ -55,45 +57,55 @@ namespace nuget_host.Controllers
|
|||
|
||||
foreach (var file in Request.Form.Files)
|
||||
{
|
||||
string initpath = "package.nupkg";
|
||||
using (FileStream fw = new FileStream(initpath, FileMode.Create))
|
||||
try
|
||||
{
|
||||
file.CopyTo(fw);
|
||||
}
|
||||
|
||||
using (FileStream fw = new FileStream(initpath, FileMode.Open))
|
||||
{
|
||||
var archive = new System.IO.Compression.ZipArchive(fw);
|
||||
|
||||
foreach (var entry in archive.Entries)
|
||||
files.Add(file.Name);
|
||||
string initpath = "package.nupkg";
|
||||
using (FileStream fw = new FileStream(initpath, FileMode.Create))
|
||||
{
|
||||
if (entry.FullName.EndsWith(".nuspec"))
|
||||
file.CopyTo(fw);
|
||||
}
|
||||
|
||||
using (FileStream fw = new FileStream(initpath, FileMode.Open))
|
||||
{
|
||||
var archive = new System.IO.Compression.ZipArchive(fw);
|
||||
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
// var entry = archive.GetEntry(filename);
|
||||
var specstr = entry.Open();
|
||||
NuGet.Packaging.Core.NuspecCoreReader reader = new NuspecCoreReader(specstr);
|
||||
if (entry.FullName.EndsWith(".nuspec"))
|
||||
{
|
||||
// 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" });
|
||||
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}");
|
||||
}
|
||||
|
||||
if (!destdir.Exists) destdir.Create();
|
||||
source.MoveTo(path);
|
||||
logger.LogWarning($"200: {entry.Name}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"400: {file.Name}");
|
||||
logger.LogError(ex.Message);
|
||||
return new BadRequestObjectResult(ViewData);
|
||||
}
|
||||
}
|
||||
return Ok(ViewData);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue