resources
This commit is contained in:
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
10
src/nuget-host/Controllers/Resource.cs
Normal file
10
src/nuget-host/Controllers/Resource.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace nuget_host.Controllers
|
||||
{
|
||||
internal class Resource
|
||||
{
|
||||
public string id {get; set; }
|
||||
public string type {get; set; }
|
||||
public string comment {get; set; }
|
||||
|
||||
}
|
||||
}
|
20
src/nuget-host/Controllers/SafeNameAttribute.cs
Normal file
20
src/nuget-host/Controllers/SafeNameAttribute.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
namespace nuget_host.Controllers
|
||||
{
|
||||
internal class SafeNameAttribute : ValidationAttribute
|
||||
{
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
if (!(value is string))
|
||||
return false;
|
||||
string str = value as string;
|
||||
if (str.Length>126) return false;
|
||||
if (str.Any(c => !char.IsLetterOrDigit(c)
|
||||
&& !"-_.".Contains(c))) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Reference in New Issue
Block a user