diff --git a/README.md b/README.md index 96e5d53..ca94d4d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ isnd& # get an api-key from isn push -k -s http://localhost:5000/index.json your-lame-versionned.nupkg - +wget http://localhost:5000/package/index.json?q=your&prerelease=true&semVerLevel=2.0.0 ```` ## Installation @@ -21,7 +21,7 @@ isn push -k -s http://localhost:5000/index.json your-lame-version Depuis le dossier de la solution, compiler la solution : ````bash -dotnet build /restore +dotnet build /restore -c Release dotnet publish -c Release ```` @@ -50,6 +50,7 @@ sudo systemctl start isnd sudo systemctl enable isnd ```` + ### Installer le client ````bash @@ -77,7 +78,6 @@ sudo cp -a src/isn/bin/Release/net472/* /usr/local/lib/isn sudo chmod +x /usr/local/lib/isn/isn.exe ```` - ## TODO ````bash @@ -85,4 +85,3 @@ isn add isn set-api-key isn sources ```` - diff --git a/src/isn/PushCommand.cs b/src/isn/PushCommand.cs index 134170a..b4fc04d 100644 --- a/src/isn/PushCommand.cs +++ b/src/isn/PushCommand.cs @@ -24,11 +24,8 @@ namespace nuget_cli try { var wrqueryHandler = new UploadFilesToServerUsingWebRequest(); - await wrqueryHandler.UploadFilesToServerAsync(report, new Uri(source), fi, apikey); -#if FAILS - var hcqueryHandler = new HttpClientServerQueryHandler(); - await hcqueryHandler.UploadFilesToServerAsync(report, new Uri(source), fi, apikey); -#endif + // await wrqueryHandler.UploadFilesToServerAsync(report, new Uri(source), fi, apikey); + wrqueryHandler.UploadFilesToServer(report, new Uri(source), fi, apikey); } catch (WebException ex) diff --git a/src/isn/UploadFilesToServerUsingWebRequest.cs b/src/isn/UploadFilesToServerUsingWebRequest.cs index e3831af..3ae9236 100644 --- a/src/isn/UploadFilesToServerUsingWebRequest.cs +++ b/src/isn/UploadFilesToServerUsingWebRequest.cs @@ -15,6 +15,81 @@ namespace nuget_cli } public class UploadFilesToServerUsingWebRequest { + internal void UploadFilesToServer(PushReport report, Uri uri, FileInfo fi, + string apikey) + { +// string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}"; + const int TXLEN = 0x1000; + /// the form-data file upload, properly formatted + string fileheaderTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\";\r\nContent-Type: {2}\r\n\r\n"; + + ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; + + // "X-NuGet-ApiKey + string boundary = "----------" + DateTime.Now.Ticks.ToString("x"); + string fileheader = string.Format(fileheaderTemplate, "file", fi.Name, "application/octet-stream"); + byte[] fileheaderbytes = Encoding.ASCII.GetBytes(fileheader); + var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); + var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--"); + HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); + + httpWebRequest.Method = "PUT"; + httpWebRequest.ContentType = "multipart/form-data; boundary=" + boundary; + httpWebRequest.AllowAutoRedirect = false; + httpWebRequest.Headers.Add("X-NuGet-Client-Version", Constants.ClientVersion); + httpWebRequest.Headers.Add("X-NuGet-ApiKey", apikey); + httpWebRequest.ContentLength = boundarybytes.Length + + fileheaderbytes.Length + fi.Length + endBoundaryBytes.Length; + + + httpWebRequest.BeginGetRequestStream(async (result) => + { + try + { + HttpWebRequest request = (HttpWebRequest)result.AsyncState; + + using (Stream requestStream = request.EndGetRequestStream(result)) + { + await WriteToStream(requestStream, boundarybytes, boundarybytes.Length); + await WriteToStream(requestStream, fileheaderbytes, fileheaderbytes.Length); + using (var fss = fi.OpenRead()) + { + byte[] buffer = new byte[TXLEN]; + var form_bytes_read = fss.Read(buffer, 0, TXLEN); + while (form_bytes_read > 0) + { + await WriteToStream(requestStream, buffer, form_bytes_read); + form_bytes_read = fss.Read(buffer, 0, TXLEN); + } + } + requestStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length); + requestStream.Close(); + } + } + catch (Exception rex) + { + report.Message = rex.Message; + Console.Error.WriteLine(rex.Message); + Console.Error.WriteLine("Stack trace:"); + Console.Error.WriteLine(rex.StackTrace); + } + }, httpWebRequest); + + WebResponse resp = httpWebRequest.GetResponse(); + + Stream stream = resp.GetResponseStream(); + StreamReader re = new StreamReader(stream); + if (resp is HttpWebResponse) + { + String json = re.ReadToEnd(); + report.Message = json; + var hrep = resp as HttpWebResponse; + report.StatusCode = hrep.StatusCode.ToString(); + report.OK = hrep.StatusCode == HttpStatusCode.Accepted + || hrep.StatusCode == HttpStatusCode.OK; + } + else throw new Exception("Invalid server response type"); + } /// /// Creates HTTP POST request & uploads database to server. Author : Farhan Ghumra @@ -22,7 +97,7 @@ namespace nuget_cli internal async Task UploadFilesToServerAsync(PushReport report, Uri uri, FileInfo fi, string apikey) { - // string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}"; +// string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}"; const int TXLEN = 0x1000; /// the form-data file upload, properly formatted string fileheaderTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\";\r\nContent-Type: {2}\r\n\r\n"; @@ -95,6 +170,7 @@ namespace nuget_cli || hrep.StatusCode == HttpStatusCode.OK; } else throw new Exception("Invalid server response type"); + } /// diff --git a/src/isnd/Controllers/PackagesController.Put.cs b/src/isnd/Controllers/PackagesController.Put.cs index b99b1e5..b8d1f01 100644 --- a/src/isnd/Controllers/PackagesController.Put.cs +++ b/src/isnd/Controllers/PackagesController.Put.cs @@ -13,6 +13,7 @@ using NuGet.Packaging.Core; using NuGet.Versioning; using isn.Data; using isn.Helpers; +using Microsoft.AspNetCore.Http; namespace isn.Controllers { @@ -26,7 +27,7 @@ namespace isn.Controllers try { var clientVersionId = Request.Headers["X-NuGet-Client-Version"]; - var apiKey = Request.Headers["X-NuGet-ApiKey"]; + string apiKey = Request.Headers["X-NuGet-ApiKey"][0]; ViewData["versionId"] = typeof(PackagesController).Assembly.FullName; var files = new List(); ViewData["files"] = files; @@ -39,7 +40,7 @@ namespace isn.Controllers return Unauthorized(); } - foreach (var file in Request.Form.Files) + foreach (IFormFile file in Request.Form.Files) { string initpath = Path.Combine(Environment.GetEnvironmentVariable("TEMP") ?? Environment.GetEnvironmentVariable("TMP") ?? "/tmp", diff --git a/src/isnd/Controllers/PackagesController.cs b/src/isnd/Controllers/PackagesController.cs index 44827c6..5359e28 100644 --- a/src/isnd/Controllers/PackagesController.cs +++ b/src/isnd/Controllers/PackagesController.cs @@ -86,7 +86,7 @@ namespace isn.Controllers } if (semVerLevel != defaultSemVer) { - ModelState.AddModelError("semVerLevel", defaultSemVer + " expected"); + _logger.LogWarning("Unexpected sementic version : "+semVerLevel); } if (ModelState.IsValid) { diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index a31be36..47f27ed 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -19,6 +19,7 @@ namespace isnd.Services int skip, int take,bool prerelease = false, string packageType = null) { + var scope = dbContext.Packages .Include(p => p.Versions) .Where( @@ -26,11 +27,13 @@ namespace isnd.Services && (prerelease || p.Versions.Any(v => !v.IsPrerelease)) && (packageType == null || p.Versions.Any(v => v.Type == packageType)) ); + var total = scope.Count(); + var pkgs = scope.Skip(skip).Take(take).ToArray(); + return new IndexResult { - totalHits = scope.Count(), - data = scope.OrderBy(p => p.Id) - .Skip(skip).Take(take).ToArray() + totalHits = total, + data = pkgs }; } public AutoCompleteResult AutoComplete (string id, diff --git a/src/isnd/packages/isn/1.0.0/isn.nuspec b/src/isnd/packages/isn/1.0.0/isn.nuspec new file mode 100644 index 0000000..13b223a --- /dev/null +++ b/src/isnd/packages/isn/1.0.0/isn.nuspec @@ -0,0 +1,19 @@ + + + + isn + 1.0.0 + isn + Package Description + + + + + + + + + + + + \ No newline at end of file diff --git a/src/isnd/wwwroot/css/site.scss b/src/isnd/wwwroot/css/site.scss index f7fa096..93a4b32 100644 --- a/src/isnd/wwwroot/css/site.scss +++ b/src/isnd/wwwroot/css/site.scss @@ -1,4 +1,6 @@ -.body-container { + + +.body-container { margin-top: 60px; padding-bottom:40px; } @@ -38,5 +40,14 @@ } } } +// Your variable overrides +$body-bg: #000; +$body-color: #111; +$theme-colors: ( + "primary": #0074d9, + "danger": #ff4136 +); + +@import "../lib/bootstrap/scss/bootstrap";