refacts
This commit is contained in:
parent
a84e1d9750
commit
2dcf1a2806
18 changed files with 166 additions and 98 deletions
|
|
@ -16,6 +16,7 @@ using isnd.Helpers;
|
|||
using isnd.Entities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using isnd.Data.Catalog;
|
||||
using isn.abst;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
|
@ -52,7 +53,7 @@ namespace isnd.Controllers
|
|||
{
|
||||
string initpath = Path.Combine(Environment.GetEnvironmentVariable("TEMP") ??
|
||||
Environment.GetEnvironmentVariable("TMP") ?? "/tmp",
|
||||
$"isn-{Guid.NewGuid()}.nupkg");
|
||||
$"isn-{Guid.NewGuid()}."+Constants.PaquetFileEstension);
|
||||
|
||||
using (FileStream fw = new FileStream(initpath, FileMode.Create))
|
||||
{
|
||||
|
|
@ -63,14 +64,14 @@ namespace isnd.Controllers
|
|||
{
|
||||
var archive = new ZipArchive(fw);
|
||||
|
||||
var nuspec = archive.Entries.FirstOrDefault(e => e.FullName.EndsWith(".nuspec"));
|
||||
if (nuspec == null) return BadRequest(new { error = "no nuspec from archive" });
|
||||
var spec = archive.Entries.FirstOrDefault(e => e.FullName.EndsWith("." + Constants.SpecFileEstension));
|
||||
if (spec == null) return BadRequest(new { error = "no " + Constants.SpecFileEstension + " from archive" });
|
||||
string pkgpath;
|
||||
NuGetVersion version;
|
||||
string pkgid;
|
||||
string fullpath;
|
||||
|
||||
using (var specstr = nuspec.Open())
|
||||
using (var specstr = spec.Open())
|
||||
{
|
||||
NuspecCoreReader reader = new NuspecCoreReader(specstr);
|
||||
|
||||
|
|
@ -82,29 +83,29 @@ namespace isnd.Controllers
|
|||
string pkgidpath = Path.Combine(isndSettings.PackagesRootDir,
|
||||
pkgid);
|
||||
pkgpath = Path.Combine(pkgidpath, version.ToFullString());
|
||||
string name = $"{pkgid}-{version}.nupkg";
|
||||
string name = $"{pkgid}-{version}."+Constants.PaquetFileEstension;
|
||||
fullpath = Path.Combine(pkgpath, name);
|
||||
|
||||
var destpkgiddir = new DirectoryInfo(pkgidpath);
|
||||
Package package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
|
||||
if (package != null)
|
||||
Package pkg = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
|
||||
if (pkg != null)
|
||||
{
|
||||
if (package.OwnerId != apikey.UserId)
|
||||
if (pkg.OwnerId != apikey.UserId)
|
||||
{
|
||||
return new ForbidResult();
|
||||
}
|
||||
package.Description = pkgdesc;
|
||||
pkg.Description = pkgdesc;
|
||||
}
|
||||
else
|
||||
{
|
||||
package = new Package
|
||||
pkg = new Package
|
||||
{
|
||||
Id = pkgid,
|
||||
Description = pkgdesc,
|
||||
OwnerId = apikey.UserId,
|
||||
LatestVersion = commit
|
||||
};
|
||||
dbContext.Packages.Add(package);
|
||||
dbContext.Packages.Add(pkg);
|
||||
}
|
||||
if (!destpkgiddir.Exists) destpkgiddir.Create();
|
||||
|
||||
|
|
@ -117,7 +118,7 @@ namespace isnd.Controllers
|
|||
// mais si elle ne l'est pas en base de donnéés,
|
||||
// on remplace la version sur disque.
|
||||
var pkgv = dbContext.PackageVersions.Where(
|
||||
v => v.PackageId == package.Id
|
||||
v => v.PackageId == pkg.Id
|
||||
);
|
||||
|
||||
if (pkgv !=null && pkgv.Count()==0)
|
||||
|
|
@ -136,7 +137,7 @@ namespace isnd.Controllers
|
|||
files.Add(name);
|
||||
string fullstringversion = version.ToFullString();
|
||||
var pkgvers = dbContext.PackageVersions.Where
|
||||
(v => v.PackageId == package.Id && v.FullString == fullstringversion);
|
||||
(v => v.PackageId == pkg.Id && v.FullString == fullstringversion);
|
||||
if (pkgvers.Count() > 0)
|
||||
{
|
||||
foreach (var v in pkgvers.ToArray())
|
||||
|
|
@ -147,7 +148,7 @@ namespace isnd.Controllers
|
|||
dbContext.PackageVersions.Add
|
||||
(new PackageVersion{
|
||||
|
||||
Package = package,
|
||||
Package = pkg,
|
||||
Major = version.Major,
|
||||
Minor = version.Minor,
|
||||
Patch = version.Patch,
|
||||
|
|
@ -161,7 +162,7 @@ namespace isnd.Controllers
|
|||
{
|
||||
var pkgver = new PackageVersion
|
||||
{
|
||||
Package = package,
|
||||
Package = pkg,
|
||||
Major = version.Major,
|
||||
Minor = version.Minor,
|
||||
Patch = version.Patch,
|
||||
|
|
@ -176,7 +177,7 @@ namespace isnd.Controllers
|
|||
await dbContext.SaveChangesAsync();
|
||||
packageManager.ÛpdateCatalogFor(commit);
|
||||
|
||||
logger.LogInformation($"new package : {nuspec.Name}");
|
||||
logger.LogInformation($"new paquet : {spec.Name}");
|
||||
}
|
||||
}
|
||||
using (var shacrypto = System.Security.Cryptography.SHA512.Create())
|
||||
|
|
@ -194,12 +195,12 @@ namespace isnd.Controllers
|
|||
}
|
||||
}
|
||||
}
|
||||
string nuspecfullpath = Path.Combine(pkgpath, pkgid + ".nuspec");
|
||||
string nuspecfullpath = Path.Combine(pkgpath, pkgid + "." + Constants.SpecFileEstension);
|
||||
FileInfo nfpi = new FileInfo(nuspecfullpath);
|
||||
|
||||
if (nfpi.Exists)
|
||||
nfpi.Delete();
|
||||
nuspec.ExtractToFile(nuspecfullpath);
|
||||
spec.ExtractToFile(nuspecfullpath);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue