diff --git a/src/nuget-host/Controllers/PackagesController.cs b/src/nuget-host/Controllers/PackagesController.cs index 12ecfe5..9186f74 100644 --- a/src/nuget-host/Controllers/PackagesController.cs +++ b/src/nuget-host/Controllers/PackagesController.cs @@ -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"); + } } } \ No newline at end of file diff --git a/src/nuget-host/Controllers/Resource.cs b/src/nuget-host/Controllers/Resource.cs new file mode 100644 index 0000000..6aab608 --- /dev/null +++ b/src/nuget-host/Controllers/Resource.cs @@ -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; } + + } +} \ No newline at end of file diff --git a/src/nuget-host/Controllers/SafeNameAttribute.cs b/src/nuget-host/Controllers/SafeNameAttribute.cs new file mode 100644 index 0000000..e80db28 --- /dev/null +++ b/src/nuget-host/Controllers/SafeNameAttribute.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/src/nuget-host/packages/nuget-cli/1.0.0/nuget-cli-1.0.0.nupkg b/src/nuget-host/packages/nuget-cli/1.0.0/nuget-cli-1.0.0.nupkg deleted file mode 100644 index 2b57d2c..0000000 Binary files a/src/nuget-host/packages/nuget-cli/1.0.0/nuget-cli-1.0.0.nupkg and /dev/null differ