cli helped
This commit is contained in:
parent
b6098c28a6
commit
5bbcf9cb29
4 changed files with 186 additions and 22 deletions
|
|
@ -8,21 +8,39 @@ namespace nuget_cli
|
|||
{
|
||||
internal class PushCommand
|
||||
{
|
||||
private static readonly int MAXSENDLEN = 0xffff;
|
||||
|
||||
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
|
||||
{
|
||||
var report = new PushReport {
|
||||
PkgName = pkg
|
||||
};
|
||||
var report = new PushReport
|
||||
{
|
||||
PkgName = pkg
|
||||
};
|
||||
FileInfo fi = new FileInfo(pkg);
|
||||
if (!fi.Exists)
|
||||
throw new Exception("Le fichier n'existe pas");
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("api-key", apikey);
|
||||
client.BaseAddress = new Uri(source);
|
||||
var content = new StreamContent(fi.OpenRead());
|
||||
var response = await client.PutAsync(source, content);
|
||||
report.StatusCode = response.StatusCode.ToString();
|
||||
report.Message = await response.Content.ReadAsStringAsync();
|
||||
if (fi.Length > MAXSENDLEN)
|
||||
throw new Exception($"Le fichier ne passe pas, trop gros ({MAXSENDLEN}).");
|
||||
|
||||
var fparams = new Dictionary<string, string> { { "userid", "9" } };
|
||||
|
||||
using (var fss = fi.OpenRead())
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
byte[] buffer = new byte[MAXSENDLEN];
|
||||
var form_bytes_read = fss.Read(buffer, 0, MAXSENDLEN);
|
||||
report.UploadFilesToServer(new Uri(source), fparams, fi.Name, "application/octet-stream",
|
||||
apikey, buffer);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync(ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
report.Executed = true;
|
||||
return report;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue