@ -21,7 +21,7 @@ namespace isnd.Services
{
public class PackageManager : IPackageManager
{
public const string BASE_API_LEVEL = "3. 5 .0";
public const string BASE_API_LEVEL = "3. 0 .0";
ApplicationDbContext dbContext ;
@ -36,86 +36,61 @@ namespace isnd.Services
public IEnumerable < Resource > GetResources ( IUnleash unleashClient )
{
var res = new List < Resource > ( ) ;
// stable
if ( unleashClient . IsEnabled ( "pkg-push" , true ) )
res . Add (
new Resource
var res = new List < Resource >
{
new Resource ( extUrl + ApiConfig . Publish , "PackagePublish/2.0.0" )
{
Id = extUrl + ApiConfig . Publish ,
Type = "PackagePublish/2.0.0" ,
Comment = "Package Publish service"
} ) ;
} ,
// under dev, only leash in release mode
if ( unleashClient . IsEnabled ( "pkg-get" , true ) )
res . Add (
new Resource
new Resource ( extUrl + ApiConfig . GetPackage , "PackageBaseAddress/3.0.0" )
{
Id = extUrl + ApiConfig . GetPackage ,
Type = "PackageBaseAddress/3.0.0" ,
Comment = @"Package Base Address service - Base URL of where NuGet packages are stored, in the format https://<host>/nupkg/{id-lower}/{version-lower}/{id-lower}.{version-lower}.nupkg"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-autocomplete" , false ) )
res . Add (
new Resource
} ,
new Resource ( extUrl + ApiConfig . AutoComplete , "SearchAutocompleteService/" + BASE_API_LEVEL )
{
Id = extUrl + ApiConfig . AutoComplete ,
Type = "SearchAutocompleteService/" + BASE_API_LEVEL ,
Comment = "Auto complete service"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-search" , false ) )
res . Add (
new Resource
} ,
new Resource ( extUrl + ApiConfig . Search , "SearchQueryService/" + BASE_API_LEVEL )
{
Id = extUrl + ApiConfig . Search ,
Type = "SearchQueryService/" + BASE_API_LEVEL ,
Comment = "Search Query service"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-catalog" , true ) )
res . Add (
new Resource
} ,
new Resource ( extUrl + "versioned/" + ApiConfig . Registration , "RegistrationsBaseUrl/Versioned" )
{
Comment = "Base URL of storage where isn package registration info is stored. This base URL includes SemVer 2.0.0 packages."
}
} ;
/ * new Resource ( extUrl + ApiConfig . Catalog , "Catalog/" + BASE_API_LEVEL )
{
Id = extUrl + ApiConfig . Catalog ,
Type = "Catalog/" + BASE_API_LEVEL ,
Comment = "Package Catalog Index"
} ) ;
} , * /
res . Add (
new Resource
/ * res . Add (
) ; res . Add (
new Resource ( extUrl + "v3.0.0/" + ApiConfig . Registration , "RegistrationsBaseUrl" )
{
Id = extUrl + "v3.0.0/" + ApiConfig . Registration ,
Type = "RegistrationsBaseUrl" ,
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
} ) ;
res . Add (
new Resource
new Resource ( extUrl + "v3.0.0-beta/" + ApiConfig . Registration , "RegistrationsBaseUrl/3.0.0-beta" )
{
Id = extUrl + "v3.0.0-beta/" + ApiConfig . Registration ,
Type = "RegistrationsBaseUrl/3.0.0-beta" ,
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
} ) ;
res . Add (
new Resource
new Resource ( extUrl + "v3.0.0-rc/" + ApiConfig . Registration , "RegistrationsBaseUrl/3.0.0-rc" )
{
Id = extUrl + "v3.0.0-rc/" + ApiConfig . Registration ,
Type = "RegistrationsBaseUrl/3.0.0-rc" ,
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
} ) ;
res . Add ( new Resource
res . Add ( new Resource ( extUrl + "v3.4.0/" + ApiConfig . Registration , "RegistrationsBaseUrl/3.4.0" )
{
Id = extUrl + "v3.4.0/" + ApiConfig . Registration ,
Type = "RegistrationsBaseUrl/3.4.0" ,
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
} ) ;
res . Add ( new Resource
{
Id = extUrl + "v3.6.0/" + ApiConfig . Registration ,
Type = "RegistrationsBaseUrl/3.6.0" ,
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
} ) ;
res . Add ( ) ; * /
return res ;
}
@ -177,24 +152,15 @@ namespace isnd.Services
string baseid = extUrl + ApiConfig . Catalog ;
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}" ;
RegistrationPageIndex CurrentCatalogI ndex = new RegistrationPageIndex ( ) ;
RegistrationPageIndex i ndex = new RegistrationPageIndex ( baseid ) ;
var scope = await dbContext . Commits . OrderBy ( c = > c . TimeStamp ) . ToArrayAsync ( ) ;
RegistrationPage page = null ;
i = isndSettings . CatalogPageLen ;
foreach ( var commit in scope )
{
if ( i > = this . isndSettings . CatalogPageLen )
{
page = new RegistrationPage ( bidreg , extUrl )
{
CommitId = commit . CommitId ,
CommitTimeStamp = commit . CommitTimeStamp
} ;
CurrentCatalogIndex . Items . Add ( page ) ;
i = 0 ;
}
var validPkgs = ( await dbContext . Packages
. Include ( po = > po . Owner )
. Include ( pkg = > pkg . Versions )
@ -204,25 +170,35 @@ namespace isnd.Services
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
foreach ( var pkgid in validPkgs )
{
StringBuilder refid = new ( bidreg ) ;
refid . AppendFormat ( "{0}/" , pkgid . Key ) ;
RegistrationPage page = index . Items . FirstOrDefault
( p = > p . GetPackageId ( ) = = pkgid . Key ) ;
if ( page = = null )
{
page = new RegistrationPage ( bidreg , pkgid . Key , extUrl ) ;
index . Items . Add ( page ) ;
}
foreach ( var pkgv in pkgid )
{
page . AddVersionRange ( pkgv . Versions ) ;
}
}
reason = commit ;
i + + ;
}
if ( reason ! = null )
{
CurrentCatalogIndex . CommitId = reason . CommitId ;
index . CommitId = reason . CommitId ;
index . CommitTimeStamp = reason . CommitTimeStamp ;
}
else
{
// From a fresh db
CurrentCatalogI ndex. CommitId = "none" ;
i ndex. CommitId = "none" ;
}
return CurrentCatalogI ndex;
return i ndex;
}
public async Task < PackageDeletionReport > DeletePackageAsync ( string pkgid , string version , string type )
@ -258,15 +234,15 @@ namespace isnd.Services
) ;
}
public IEnumerable < PackageVersion > GetCatalogLeaf ( string pkgId , string semver = null , string pkgType = null )
public async Task < CatalogEntry > GetCatalogLeafAsync ( string pkgId , string semver = null , string pkgType = null )
{
return dbContext . PackageVersions
return ( await dbContext . PackageVersions
. Include ( v = > v . Package )
. Include ( v = > v . LatestCommit )
. Where ( v = > v . PackageId = = pkgId
& & ( semver = = null | |
semver . StartsWith ( v . SementicVersionString ) )
& & ( pkgType = = null | | pkgType = = v . Type ) ) ;
& & semver = = v . SementicVersionString
& & ( pkgType = = null | | pkgType = = v . Type ) ) . SingleOrDefaultAsync ( ) ) . ToLeave ( BID ,
extUrl ) ;
}
public async Task < PackageDeletionReport > UserAskForPackageDeletionAsync ( string uid , string id , string lower , string type )
@ -280,9 +256,11 @@ namespace isnd.Services
return new PackageDeletionReport { Deleted = true , DeletedVersion = packageVersion } ;
}
public IEnumerable < Data . Catalog . RegistrationLeaf > SearchById ( string pkgId , string semver , string pkgType )
public string BID { get = > $"{extUrl}v3.4.0/{ApiConfig.Registration}" ; }
public IEnumerable < CatalogEntry > SearchById ( string pkgId , string semver , string pkgType )
{
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}" ;
return dbContext . PackageVersions
. Include ( v = > v . Package )
. Include ( v = > v . Package . Owner )
@ -290,7 +268,7 @@ namespace isnd.Services
. Where ( v = > v . PackageId = = pkgId & & semver = = v . FullString
& & ( pkgType = = null | | pkgType = = v . Type ) )
. OrderByDescending ( p = > p . CommitNId )
. Select ( p = > p . ToLeave ( bid , extUrl ) )
. Select ( p = > p . ToLeave ( BID , extUrl ) )
;
}
public PackageVersion GetPackage ( string pkgId , string semver , string pkgType )
@ -305,8 +283,10 @@ namespace isnd.Services
public async Task < RegistrationPageIndex > GetPackageRegistrationIndexAsync ( RegistrationPageIndexQuery query )
{
// RegistrationPageIndexAndQuery
if ( string . IsNullOrWhiteSpace ( query . Query ) ) return null ;
query . Query = query . Query . ToLower ( ) ;
var scope = await dbContext . Packages . Include ( p = > p . Versions ) . Include ( p = > p . Owner )
. Where ( p = > MatchingExact ( p , query ) ) . Skip ( query . Skip ) . Take ( query . Take ) . ToListAsync ( ) ;
. Where ( p = > p. Id . ToLower ( ) = = query . Query ) . Skip ( query . Skip ) . Take ( query . Take ) . ToListAsync ( ) ;
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}" ;
return