REORG+histo
parent
459f8ea422
commit
6dd76ac1a5
@ -0,0 +1,62 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using isnd.Data.Catalog;
|
||||||
|
using isnd.Helpers;
|
||||||
|
using isnd.Services;
|
||||||
|
using isnd.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace isnd.Controllers
|
||||||
|
{
|
||||||
|
|
||||||
|
public partial class PackagesController
|
||||||
|
{
|
||||||
|
|
||||||
|
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
|
||||||
|
[HttpGet(_pkgRootPrefix + ApiConfig.Catalog)]
|
||||||
|
public IActionResult CatalogIndex()
|
||||||
|
{
|
||||||
|
return Ok(PackageManager.CurrentCatalogIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogPage + "-{id}")]
|
||||||
|
public IActionResult Index(string id)
|
||||||
|
{
|
||||||
|
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
|
||||||
|
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{*lower}")]
|
||||||
|
public async Task<IActionResult> CatalogLeafAsync(string id, string lower)
|
||||||
|
{
|
||||||
|
string pkgType = ParamHelpers.Optional(ref lower);
|
||||||
|
var pkgVersion = await _dbContext.PackageVersions
|
||||||
|
.Include(v => v.LatestCommit)
|
||||||
|
.Include(v => v.Package)
|
||||||
|
.SingleOrDefaultAsync(
|
||||||
|
v => v.PackageId == id &&
|
||||||
|
v.FullString == lower &&
|
||||||
|
v.Type == pkgType
|
||||||
|
);
|
||||||
|
if (pkgVersion == null) return NotFound();
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NuGet.Packaging.Core;
|
||||||
|
using NuGet.Versioning;
|
||||||
|
using isnd.Data;
|
||||||
|
using isnd.Helpers;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using isnd.Data.Catalog;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace isnd.Controllers
|
||||||
|
{
|
||||||
|
|
||||||
|
public partial class PackagesController
|
||||||
|
{
|
||||||
|
|
||||||
|
[HttpDelete(_pkgRootPrefix + ApiConfig.Delete + "/{id}/{*lower}")]
|
||||||
|
public async Task<IActionResult> Delete(
|
||||||
|
[FromRoute][SafeName][Required] string id,
|
||||||
|
[FromRoute][SafeName][Required] string lower)
|
||||||
|
{
|
||||||
|
string pkgtype = ParamHelpers.Optional(ref lower);
|
||||||
|
var report = await _packageManager.DeletePackageAsync(id, lower, pkgtype);
|
||||||
|
return Ok(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using isnd.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace isnd.Controllers
|
||||||
|
{
|
||||||
|
|
||||||
|
public partial class PackagesController
|
||||||
|
{
|
||||||
|
// TODO GET GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.{LOWER_VERSION}.nupkg
|
||||||
|
// LOWER_ID URL string yes The package ID, lowercase
|
||||||
|
// LOWER_VERSION URL string yes The package version, normalized and lowercased
|
||||||
|
// response 200 : the package
|
||||||
|
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")]
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
|
||||||
|
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||||
|
|
||||||
|
if (!pkgfi.Exists)
|
||||||
|
{
|
||||||
|
return BadRequest("!pkgfi.Exists");
|
||||||
|
}
|
||||||
|
return File(pkgfi.OpenRead(), "application/zip; charset=binary");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec
|
||||||
|
// response 200 : the nuspec
|
||||||
|
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")]
|
||||||
|
public IActionResult GetNuspec(
|
||||||
|
[FromRoute][SafeName][Required] string id,
|
||||||
|
[FromRoute][SafeName][Required] string lower,
|
||||||
|
[FromRoute][SafeName][Required] string idf,
|
||||||
|
[FromRoute][SafeName][Required] string lowerf)
|
||||||
|
{
|
||||||
|
var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
|
||||||
|
id, lower, $"{id}.nuspec");
|
||||||
|
|
||||||
|
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||||
|
if (!pkgfi.Exists)
|
||||||
|
{
|
||||||
|
return BadRequest("!pkgfi.Exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
return File(pkgfi.OpenRead(), "text/xml; charset=utf-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using isnd.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace isnd.Controllers
|
||||||
|
{
|
||||||
|
|
||||||
|
public partial class PackagesController
|
||||||
|
{
|
||||||
|
|
||||||
|
// GET: PackageVersion
|
||||||
|
public async Task<IActionResult> Index(PackageIndexViewModel model)
|
||||||
|
{
|
||||||
|
var applicationDbContext = _dbContext.Packages.Include(p => p.Versions).Where(
|
||||||
|
p => ( model.Prerelease || p.Versions.Any(v => !v.IsPrerelease))
|
||||||
|
&& ((model.query == null) || p.Id.StartsWith(model.query)));
|
||||||
|
model.data = await applicationDbContext.ToArrayAsync();
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> Details(string pkgid)
|
||||||
|
{
|
||||||
|
if (pkgid == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var packageVersion = _dbContext.PackageVersions
|
||||||
|
.Include(p => p.Package)
|
||||||
|
.Where(m => m.PackageId == pkgid)
|
||||||
|
.OrderByDescending(p => p)
|
||||||
|
;
|
||||||
|
|
||||||
|
if (packageVersion == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
bool results = await packageVersion.AnyAsync();
|
||||||
|
var latest = await packageVersion.FirstAsync();
|
||||||
|
|
||||||
|
return View("Details", new PackageDetailViewModel
|
||||||
|
{
|
||||||
|
latest = latest,
|
||||||
|
pkgid = pkgid,
|
||||||
|
totalHits = packageVersion.Count(),
|
||||||
|
data = packageVersion.Take(10).ToArray()
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace isnd.Data.Catalog
|
||||||
|
{
|
||||||
|
public class CatalogLeaf : IObject
|
||||||
|
{
|
||||||
|
|
||||||
|
[JsonProperty("@type")]
|
||||||
|
public List<string> RefType { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("commitId")]
|
||||||
|
public string CommitId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("commitTimeStamp")]
|
||||||
|
public DateTime CommitTimeStamp { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("published")]
|
||||||
|
public DateTime Published { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("version")]
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace isnd.Data.Catalog
|
||||||
|
{
|
||||||
|
public class PackageDetail : CatalogLeaf
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using isnd.Data.Catalog;
|
||||||
|
|
||||||
|
namespace isnd.Data.Historic
|
||||||
|
{
|
||||||
|
public class PackageVersionCommit
|
||||||
|
{
|
||||||
|
public long CommitId { get; set; }
|
||||||
|
|
||||||
|
[StringLength(1024)]
|
||||||
|
public string PackageId { get; set; }
|
||||||
|
|
||||||
|
[StringLength(256)]
|
||||||
|
public string FullString { get; set; }
|
||||||
|
|
||||||
|
[StringLength(256)]
|
||||||
|
|
||||||
|
public string PackageType { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("CommitId")]
|
||||||
|
public virtual Commit Commit { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("PackageId")]
|
||||||
|
public virtual Package Package { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("PackageId,FullString,PackageType")]
|
||||||
|
public virtual PackageVersion PackageVersion { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
namespace isnd.Helpers
|
||||||
|
{
|
||||||
|
public static class PackageIdHelpers
|
||||||
|
{
|
||||||
|
|
||||||
|
internal static bool SeparatedByMinusMatch(string id, string q)
|
||||||
|
{
|
||||||
|
foreach (var part in id.Split('-'))
|
||||||
|
{
|
||||||
|
if (part.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal static bool CamelCaseMatch(string id, string query)
|
||||||
|
{
|
||||||
|
// Assert.False (q==null);
|
||||||
|
if (string.IsNullOrEmpty(query)) return true;
|
||||||
|
|
||||||
|
while (id.Length > 0)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
while (id.Length > i && char.IsLower(id[i])) i++;
|
||||||
|
if (i == 0) break;
|
||||||
|
id = id.Substring(i);
|
||||||
|
if (id.StartsWith(query, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using isnd.Data;
|
||||||
|
|
||||||
|
namespace isnd.Helpers
|
||||||
|
{
|
||||||
|
public static class PackageVersionHelpers
|
||||||
|
{
|
||||||
|
|
||||||
|
public static bool IsOwner(this ClaimsPrincipal user, PackageVersion v)
|
||||||
|
{
|
||||||
|
var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
|
return v.Package.OwnerId == userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
namespace isnd.Helpers
|
||||||
|
{
|
||||||
|
public static class ParamHelpers
|
||||||
|
{
|
||||||
|
public static string Optional(ref string prm)
|
||||||
|
{
|
||||||
|
int sopt = prm.IndexOf('/');
|
||||||
|
if (sopt>0)
|
||||||
|
{
|
||||||
|
prm = prm.Substring(0,sopt);
|
||||||
|
return prm.Substring(sopt + 1);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace isnd.ViewModels
|
||||||
|
{
|
||||||
|
public class PackageDeletionReport
|
||||||
|
{
|
||||||
|
public bool Deleted { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue