|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
@ -41,8 +42,38 @@ namespace nuget_host.Controllers
|
|
|
|
|
// Search
|
|
|
|
|
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
|
|
|
|
|
|
|
|
|
|
const string _apiPrefix = "~/package";
|
|
|
|
|
[HttpGet(_apiPrefix + "/index.json")]
|
|
|
|
|
|
|
|
|
|
private readonly Resource[] ressources = {
|
|
|
|
|
new Resource {
|
|
|
|
|
id = "package/index.json",
|
|
|
|
|
type ="SearchAutocompleteService/3.5.0",
|
|
|
|
|
comment = "Auto complete service"
|
|
|
|
|
},
|
|
|
|
|
new Resource {
|
|
|
|
|
id = "package/index.json",
|
|
|
|
|
type ="SearchQueryService/3.5.0",
|
|
|
|
|
comment = "Search Query service"
|
|
|
|
|
},
|
|
|
|
|
new Resource {
|
|
|
|
|
id = "package",
|
|
|
|
|
type ="PackagePublish/2.0.0",
|
|
|
|
|
comment = "Package Publish service"
|
|
|
|
|
},
|
|
|
|
|
new Resource {
|
|
|
|
|
id = "package",
|
|
|
|
|
type = "PackageBaseAddress/3.0.0",
|
|
|
|
|
comment = "Package Base Address service"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const string _pkgRootPrefix = "~/package";
|
|
|
|
|
[HttpGet("~/index.json")]
|
|
|
|
|
public IActionResult ApiIndex()
|
|
|
|
|
{
|
|
|
|
|
return Ok(ressources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet(_pkgRootPrefix + "/index.json")]
|
|
|
|
|
public IActionResult Index(
|
|
|
|
|
string q,
|
|
|
|
|
string semVerLevel = defaultSemVer,
|
|
|
|
@ -107,7 +138,7 @@ namespace nuget_host.Controllers
|
|
|
|
|
}
|
|
|
|
|
const int maxTake = 100;
|
|
|
|
|
// GET /autocomplete?id=nuget.protocol&prerelease=true
|
|
|
|
|
[HttpGet(_apiPrefix + "/autocomplete")]
|
|
|
|
|
[HttpGet(_pkgRootPrefix + "/autocomplete")]
|
|
|
|
|
public IActionResult AutoComplete(
|
|
|
|
|
string id,
|
|
|
|
|
string semVerLevel = defaultSemVer,
|
|
|
|
@ -129,15 +160,15 @@ namespace nuget_host.Controllers
|
|
|
|
|
.OrderBy(v => v.FullString);
|
|
|
|
|
return Ok(new
|
|
|
|
|
{
|
|
|
|
|
data =scope.Select(v => v.FullString)
|
|
|
|
|
data = scope.Select(v => v.FullString)
|
|
|
|
|
.Skip(skip).Take(take).ToArray(),
|
|
|
|
|
totalHits = scope.Count()
|
|
|
|
|
totalHits = scope.Count()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// TODO GET {@id}/{LOWER_ID}/index.json
|
|
|
|
|
// LOWER_ID URL string yes The package ID, lowercased
|
|
|
|
|
// response : versions array of strings yes The versions available
|
|
|
|
|
[HttpGet(_apiPrefix + "/{id}/{lower}/index.json")]
|
|
|
|
|
[HttpGet(_pkgRootPrefix + "/{id}/{lower}/index.json")]
|
|
|
|
|
public IActionResult GetVersions(
|
|
|
|
|
string id,
|
|
|
|
|
string lower,
|
|
|
|
@ -180,8 +211,33 @@ namespace nuget_host.Controllers
|
|
|
|
|
// 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 + "/{id}/{lower}/{idf}.{lowerf}.nupkg")]
|
|
|
|
|
public IActionResult GetPackage(
|
|
|
|
|
[FromRoute] string id, [FromRoute] string lower,
|
|
|
|
|
[FromRoute] string idf, [FromRoute] string lowerf)
|
|
|
|
|
{
|
|
|
|
|
var pkgpath = Path.Combine(nugetSettings.PackagesRootDir,
|
|
|
|
|
id, lower, $"{idf}.{lowerf}.nupkg"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
FileInfo pkgfi = new FileInfo(pkgpath);
|
|
|
|
|
return File(pkgfi.OpenRead(), "application/zip; charset=binary");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec
|
|
|
|
|
// response 200 : the nuspec
|
|
|
|
|
[HttpGet(_pkgRootPrefix + "/{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(nugetSettings.PackagesRootDir,
|
|
|
|
|
id, lower, $"{idf}.{lowerf}.nuspec");
|
|
|
|
|
|
|
|
|
|
FileInfo pkgfi = new FileInfo(pkgpath);
|
|
|
|
|
return File(pkgfi.OpenRead(), "text/xml; charset=utf-8");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|