This commit is contained in:
2021-09-02 23:37:28 +01:00
parent 7a835c5c95
commit a92bee32e1
5 changed files with 81 additions and 67 deletions

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using isnd.Controllers;
@ -14,20 +13,65 @@ using Unleash;
namespace isnd.Services
{
public class PackageManager : IPackageManager
{
ApplicationDbContext dbContext;
public PackageManager(ApplicationDbContext dbContext,
IOptions<IsndSettings> siteConfigOptionsOptions)
{
this.dbContext = dbContext;
isndSettings = siteConfigOptionsOptions.Value;
extApiUrl = isndSettings.ExternalUrl + "/package";
extUrl = isndSettings.ExternalUrl ;
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,
int skip, int take, bool prerelease = false,
@ -51,9 +95,6 @@ namespace isnd.Services
data = pkgs
};
}
const int maxPageLen = 512;
public AutoCompleteResult AutoComplete(string id,
int skip, int take, bool prerelease = false,
string packageType = null)
@ -96,7 +137,7 @@ namespace isnd.Services
public static CatalogIndex CurrentCatalogIndex { get; protected set; }
public static List<Page> CurrentCatalogPages { get; protected set; }
private IsndSettings isndSettings;
private string extApiUrl;
private string extUrl;
public virtual CatalogIndex GetCatalogIndex()
{
@ -114,7 +155,7 @@ namespace isnd.Services
var oldPages = CurrentCatalogPages;
CurrentCatalogIndex = new CatalogIndex
{
Id = extApiUrl,
Id = extUrl,
Items = new List<PageRef>()
};
CurrentCatalogPages = new List<Page>();
@ -148,12 +189,14 @@ namespace isnd.Services
.Include(pkg => pkg.Versions)
.Include(pkg => pkg.LatestVersion)
.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
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
{
@ -204,44 +247,5 @@ namespace isnd.Services
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;
}
}
}