refacts
This commit is contained in:
@ -17,26 +17,17 @@ namespace isnd.Controllers
|
||||
int skip = 0,
|
||||
int take = 25)
|
||||
{
|
||||
CheckParams(take, semVerLevel);
|
||||
if (ModelState.ErrorCount > 0) return BadRequest(ModelState);
|
||||
|
||||
return Ok(packageManager.AutoComplete(id,skip,take,prerelease,packageType));
|
||||
}
|
||||
protected void CheckParams(int maxTake)
|
||||
{
|
||||
if (maxTake > maxTake)
|
||||
if (take > maxTake)
|
||||
{
|
||||
ModelState.AddModelError("take", "Maximum exceeded");
|
||||
}
|
||||
}
|
||||
|
||||
protected void CheckParams(int take, string semVerLevel)
|
||||
{
|
||||
CheckParams(take);
|
||||
if (semVerLevel != PackageManager.BASE_API_LEVEL)
|
||||
{
|
||||
ModelState.AddModelError("semVerLevel", PackageManager.BASE_API_LEVEL + " expected");
|
||||
}
|
||||
if (ModelState.ErrorCount > 0) return BadRequest(ModelState);
|
||||
|
||||
return Ok(packageManager.AutoComplete(id,skip,take,prerelease,packageType));
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using isnd.Services;
|
||||
using isnd.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
@ -27,8 +28,8 @@ namespace isnd.Controllers
|
||||
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
|
||||
}
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{*lower}")]
|
||||
public async Task<IActionResult> CatalogLeafAsync(string id, string lower)
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Registration + "/{id}/{*lower}")]
|
||||
public async Task<IActionResult> CatalogRegistrationAsync(string id, string lower)
|
||||
{
|
||||
string pkgType = ParamHelpers.Optional(ref lower);
|
||||
var pkgVersion = await dbContext.PackageVersions
|
||||
@ -39,21 +40,35 @@ namespace isnd.Controllers
|
||||
v.Type == pkgType
|
||||
);
|
||||
if (pkgVersion == null) return NotFound();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{*lower}")]
|
||||
public async Task<IActionResult> CatalogLeafAsync(string id, string version, string lower)
|
||||
{
|
||||
var pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower)
|
||||
.ToArray();
|
||||
|
||||
if (pkgvs.Count()==0) return NotFound();
|
||||
|
||||
List <string> types = pkgvs.Select(
|
||||
v => v.Type ?? "Dependency"
|
||||
).Distinct().ToList();
|
||||
if (!types.Contains("PackageDelete"))
|
||||
types.Add("PackageDetails");
|
||||
var pub = pkgvs.Last().Package.CommitTimeStamp;
|
||||
var firstpub = pkgvs.First().Package.CommitTimeStamp;
|
||||
|
||||
var pub = await dbContext.Commits
|
||||
.Include(c => c.Versions)
|
||||
.OrderBy(c => c.CommitTimeStamp)
|
||||
.SingleOrDefaultAsync
|
||||
(
|
||||
c => c.Action == PackageAction.PublishPackage
|
||||
&& c.Versions.Contains(pkgVersion)
|
||||
);
|
||||
return Ok(new CatalogLeaf
|
||||
{
|
||||
CommitId = id,
|
||||
Id = pkgVersion.PackageId,
|
||||
CommitTimeStamp = pkgVersion.LatestCommit.CommitTimeStamp
|
||||
|
||||
Id = id,
|
||||
CommitTimeStamp = firstpub,
|
||||
Version = version,
|
||||
Published = pub,
|
||||
RefType = types.ToArray(),
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
38
src/isnd/Controllers/Packages/CatalogRegistration.cs
Normal file
38
src/isnd/Controllers/Packages/CatalogRegistration.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
public class CatalogRegistration
|
||||
{
|
||||
[JsonProperty("@id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
|
||||
/*
|
||||
"@id": "https://api.nuget.org/v3/registration3/nuget.versioning/4.3.0.json",
|
||||
"catalogEntry": "https://api.nuget.org/v3/catalog0/data/2017.08.11.18.24.22/nuget.versioning.4.3.0.json",
|
||||
"listed": true,
|
||||
"packageContent": "https://api.nuget.org/v3-flatcontainer/nuget.versioning/4.3.0/nuget.versioning.4.3.0.nupkg",
|
||||
"published": "2017-08-11T18:24:14.36+00:00",
|
||||
"registration": "https://api.nuget.org/v3/registration3/nuget.versioning/index.json"
|
||||
|
||||
|
||||
*/
|
||||
[JsonProperty("catalogEntry")]
|
||||
public string CatalogEntry { get; set; }
|
||||
|
||||
[JsonProperty("listed")]
|
||||
public bool Listed { get; set; } = true;
|
||||
|
||||
[JsonProperty("packageContent")]
|
||||
public string PackageContent { get; set; }
|
||||
|
||||
[JsonProperty("published")]
|
||||
public DateTime CommitTimeStamp { get; set; }
|
||||
|
||||
[JsonProperty("registration")]
|
||||
public string registration { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -3,20 +3,23 @@ using System.IO;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using isnd.Attributes;
|
||||
using isnd.Entities;
|
||||
using isn.abst;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
||||
public partial class PackagesController
|
||||
{
|
||||
// Web get nupkg
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")]
|
||||
// Web get the paquet
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.GetPackage + "/{id}/{lower}/{idf}-{lowerf}."
|
||||
+ Constants.PaquetFileEstension)]
|
||||
public IActionResult GetPackage(
|
||||
[FromRoute][SafeName][Required] string id,
|
||||
[FromRoute][SafeName][Required] string lower,
|
||||
[FromRoute] string idf, [FromRoute] string lowerf)
|
||||
{
|
||||
var pkgpath = Path.Combine(isndSettings.PackagesRootDir,
|
||||
id, lower, $"{id}-{lower}.nupkg"
|
||||
id, lower, $"{id}-{lower}." + Constants.PaquetFileEstension
|
||||
);
|
||||
|
||||
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||
@ -29,7 +32,8 @@ namespace isnd.Controllers
|
||||
}
|
||||
|
||||
// Web get spec
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")]
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.GetNuspec + "/{id}/{lower}/{idf}-{lowerf}."
|
||||
+ Constants.SpecFileEstension)]
|
||||
public IActionResult GetNuspec(
|
||||
[FromRoute][SafeName][Required] string id,
|
||||
[FromRoute][SafeName][Required] string lower,
|
||||
@ -37,7 +41,7 @@ namespace isnd.Controllers
|
||||
[FromRoute][SafeName][Required] string lowerf)
|
||||
{
|
||||
var pkgpath = Path.Combine(isndSettings.PackagesRootDir,
|
||||
id, lower, $"{id}.nuspec");
|
||||
id, lower, $"{id}." + Constants.SpecFileEstension);
|
||||
|
||||
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||
if (!pkgfi.Exists)
|
||||
|
@ -6,7 +6,7 @@ namespace isnd.Controllers
|
||||
{
|
||||
public partial class PackagesController
|
||||
{
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/index.json")]
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.GetVersion + "/{id}/{lower}/index.json")]
|
||||
public IActionResult GetVersions(
|
||||
string id,
|
||||
string lower,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user