broken/ef
Paul Schneider 3 years ago
parent 7a835c5c95
commit a92bee32e1
5 changed files with 81 additions and 67 deletions

@ -81,12 +81,7 @@ sudo chmod +x /usr/local/lib/isn/isn.exe
## TODO ## TODO
````bash ````bash
nuget list
The V2 feed at 'http://isn.pschneider.fr/package/Search()?$filter=IsLatestVersion&$orderby=Id&searchTerm=''&targetFramework=''&includePrerelease=false&$skip=0&$top=30&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'.
Failed to retrieve information about 'Yavsc.Abstract' from remote source 'http://isn.pschneider.fr/package/FindPackagesById()?id='Yavsc.Abstract'&semVerLevel=2.0.0'.
Response status code does not indicate success: 404 (Not Found).
isn set-api-key
isn add
isn sources
```` ````

@ -0,0 +1,14 @@
namespace isnd
{
public static class ApiConfig
{
public const string BaseApiPath = "/";
public const string Publish = "put";
public const string Base = "index";
public const string Catalog = "catalog";
public const string Get = "get";
public const string Search = "search";
public const string AutoComplete = "autocomplete";
}
}

@ -22,7 +22,7 @@ namespace isnd.Controllers
public partial class PackagesController public partial class PackagesController
{ {
[HttpPut(_pkgRootPrefix)] [HttpPut(_pkgRootPrefix + ApiConfig.Publish)]
public async Task<IActionResult> Put() public async Task<IActionResult> Put()
{ {
try try

@ -24,7 +24,6 @@ namespace isnd.Controllers
{ {
const int maxTake = 100; const int maxTake = 100;
const string _pkgRootPrefix = "~/package";
const string defaultSemVer = "2.0.0"; const string defaultSemVer = "2.0.0";
private readonly Resource[] _ressources; private readonly Resource[] _ressources;
private readonly ILogger<PackagesController> _logger; private readonly ILogger<PackagesController> _logger;
@ -94,22 +93,24 @@ namespace isnd.Controllers
} }
const string _pkgRootPrefix = "~" + ApiConfig.BaseApiPath;
[HttpGet("~/index.json")]
[HttpGet(_pkgRootPrefix + ApiConfig.Base)]
public IActionResult ApiIndex() public IActionResult ApiIndex()
{ {
return Ok(_ressources); return Ok(_ressources);
} }
// //
[HttpGet(_pkgRootPrefix)] [HttpGet(_pkgRootPrefix + ApiConfig.Catalog)]
public IActionResult Index() public IActionResult CatalogIndex()
{ {
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
return Ok(PackageManager.CurrentCatalogIndex); return Ok(PackageManager.CurrentCatalogIndex);
} }
[HttpGet(_pkgRootPrefix + "/index-{id}")] [HttpGet(_pkgRootPrefix + ApiConfig.Catalog + "-{id}")]
public IActionResult Index(string id) public IActionResult Index(string id)
{ {
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
@ -117,7 +118,7 @@ namespace isnd.Controllers
} }
// GET /autocomplete?id=isn.protocol&prerelease=true // GET /autocomplete?id=isn.protocol&prerelease=true
[HttpGet(_pkgRootPrefix + "/autocomplete")] [HttpGet(_pkgRootPrefix + ApiConfig.AutoComplete)]
public IActionResult AutoComplete( public IActionResult AutoComplete(
string id, string id,
string semVerLevel, string semVerLevel,
@ -141,7 +142,7 @@ namespace isnd.Controllers
// TODO GET {@id}/{LOWER_ID}/index.json // TODO GET {@id}/{LOWER_ID}/index.json
// LOWER_ID URL string yes The package ID, lowercased // LOWER_ID URL string yes The package ID, lowercased
// response : versions array of strings yes The versions available // response : versions array of strings yes The versions available
[HttpGet(_pkgRootPrefix + "/{id}/{lower}/index.json")] [HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/index.json")]
public IActionResult GetVersions( public IActionResult GetVersions(
string id, string id,
string lower, string lower,
@ -174,7 +175,7 @@ namespace isnd.Controllers
// LOWER_ID URL string yes The package ID, lowercase // LOWER_ID URL string yes The package ID, lowercase
// LOWER_VERSION URL string yes The package version, normalized and lowercased // LOWER_VERSION URL string yes The package version, normalized and lowercased
// response 200 : the package // response 200 : the package
[HttpGet(_pkgRootPrefix + "/{id}/{lower}/{idf}-{lowerf}.nupkg")] [HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")]
public IActionResult GetPackage( public IActionResult GetPackage(
[FromRoute] string id, [FromRoute] string lower, [FromRoute] string id, [FromRoute] string lower,
[FromRoute] string idf, [FromRoute] string lowerf) [FromRoute] string idf, [FromRoute] string lowerf)
@ -194,7 +195,7 @@ namespace isnd.Controllers
// TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec // TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec
// response 200 : the nuspec // response 200 : the nuspec
[HttpGet(_pkgRootPrefix + "/{id}/{lower}/{idf}-{lowerf}.nuspec")] [HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")]
public IActionResult GetNuspec( public IActionResult GetNuspec(
[FromRoute][SafeName][Required] string id, [FromRoute][SafeName][Required] string id,
[FromRoute][SafeName][Required] string lower, [FromRoute][SafeName][Required] string lower,

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using isnd.Controllers; using isnd.Controllers;
@ -14,20 +13,65 @@ using Unleash;
namespace isnd.Services namespace isnd.Services
{ {
public class PackageManager : IPackageManager public class PackageManager : IPackageManager
{ {
ApplicationDbContext dbContext; ApplicationDbContext dbContext;
public PackageManager(ApplicationDbContext dbContext, public PackageManager(ApplicationDbContext dbContext,
IOptions<IsndSettings> siteConfigOptionsOptions) IOptions<IsndSettings> siteConfigOptionsOptions)
{ {
this.dbContext = dbContext; this.dbContext = dbContext;
isndSettings = siteConfigOptionsOptions.Value; isndSettings = siteConfigOptionsOptions.Value;
extApiUrl = isndSettings.ExternalUrl + "/package"; extUrl = isndSettings.ExternalUrl ;
CurrentCatalogIndex = GetCatalogIndex(); CurrentCatalogIndex = GetCatalogIndex();
} }
public IEnumerable<Resource> GetResources(IUnleash unleashClient)
{
bool defaultActivation = false;
#if DEBUG
defaultActivation = true;
#endif
var res = new List<Resource>();
// stable
if (unleashClient.IsEnabled("pkg-push", true))
res.Add(
new Resource
{
id = extUrl + ApiConfig.Publish,
type = "PackagePublish/2.0.0",
comment = "Package Publish service"
});
// under dev, only leash in release mode
if (defaultActivation || unleashClient.IsEnabled("pkg-get", false))
res.Add(
new Resource
{
id = extUrl + ApiConfig.Base,
type = "PackageBaseAddress/3.0.0",
comment = "Package Base Address service"
});
if (defaultActivation || unleashClient.IsEnabled("pkg-autocomplete", false))
res.Add(
new Resource
{
id = extUrl + ApiConfig.AutoComplete,
type = "SearchAutocompleteService/3.5.0",
comment = "Auto complete service"
});
if (defaultActivation || unleashClient.IsEnabled("pkg-search", false))
res.Add(
new Resource
{
id = extUrl + ApiConfig.Search,
type = "SearchQueryService/3.5.0",
comment = "Search Query service"
});
return res;
}
public PackageIndexViewModel SearchByName(string query, public PackageIndexViewModel SearchByName(string query,
int skip, int take, bool prerelease = false, int skip, int take, bool prerelease = false,
@ -51,9 +95,6 @@ namespace isnd.Services
data = pkgs data = pkgs
}; };
} }
const int maxPageLen = 512;
public AutoCompleteResult AutoComplete(string id, public AutoCompleteResult AutoComplete(string id,
int skip, int take, bool prerelease = false, int skip, int take, bool prerelease = false,
string packageType = null) string packageType = null)
@ -96,7 +137,7 @@ namespace isnd.Services
public static CatalogIndex CurrentCatalogIndex { get; protected set; } public static CatalogIndex CurrentCatalogIndex { get; protected set; }
public static List<Page> CurrentCatalogPages { get; protected set; } public static List<Page> CurrentCatalogPages { get; protected set; }
private IsndSettings isndSettings; private IsndSettings isndSettings;
private string extApiUrl; private string extUrl;
public virtual CatalogIndex GetCatalogIndex() public virtual CatalogIndex GetCatalogIndex()
{ {
@ -114,7 +155,7 @@ namespace isnd.Services
var oldPages = CurrentCatalogPages; var oldPages = CurrentCatalogPages;
CurrentCatalogIndex = new CatalogIndex CurrentCatalogIndex = new CatalogIndex
{ {
Id = extApiUrl, Id = extUrl,
Items = new List<PageRef>() Items = new List<PageRef>()
}; };
CurrentCatalogPages = new List<Page>(); CurrentCatalogPages = new List<Page>();
@ -148,12 +189,14 @@ namespace isnd.Services
.Include(pkg => pkg.Versions) .Include(pkg => pkg.Versions)
.Include(pkg => pkg.LatestVersion) .Include(pkg => pkg.LatestVersion)
.Where( .Where(
pkg => pkg.Versions.Count() > 0 && pkg.CommitId == commit.CommitId pkg => pkg.Versions.Count(v => v.CommitId == commit.CommitId) > 0
); );
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString // pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
foreach (var pkg in validPkgs) foreach (var pkg in validPkgs)
{ {
var v = pkg.Versions.OrderByDescending(vc => vc.CommitNId).First(); var v = pkg.Versions.
Where (cv => cv.CommitId == commit.CommitId)
.OrderByDescending(vc => vc.CommitNId).First();
var pkgref = new PackageRef var pkgref = new PackageRef
{ {
@ -204,44 +247,5 @@ namespace isnd.Services
return false; return false;
} }
public IEnumerable<Resource> GetResources(IUnleash unleashClient)
{
var res = new List<Resource>();
if (unleashClient.IsEnabled("pkg-push", true))
res.Add(
new Resource
{
id = extApiUrl,
type = "PackagePublish/2.0.0",
comment = "Package Publish service"
});
if (unleashClient.IsEnabled("pkg-get", false))
res.Add(
new Resource
{
id = extApiUrl,
type = "PackageBaseAddress/3.0.0",
comment = "Package Base Address service"
});
if (unleashClient.IsEnabled("pkg-autocomplete", false))
res.Add(
new Resource
{
id = extApiUrl,
type = "SearchAutocompleteService/3.5.0",
comment = "Auto complete service"
});
if (unleashClient.IsEnabled("pkg-search", false))
res.Add(
new Resource
{
id = extApiUrl,
type = "SearchQueryService/3.5.0",
comment = "Search Query service"
});
return res;
}
} }
} }
Loading…