2021-05-10 23:03:59 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace nuget_cli
|
|
|
|
|
{
|
|
|
|
|
internal class PushCommand
|
|
|
|
|
{
|
2021-05-11 02:38:52 +01:00
|
|
|
private static readonly int MAXSENDLEN = 0xffff;
|
|
|
|
|
|
2021-05-10 23:03:59 +01:00
|
|
|
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
|
|
|
|
|
{
|
2021-05-11 02:38:52 +01:00
|
|
|
var report = new PushReport
|
|
|
|
|
{
|
|
|
|
|
PkgName = pkg
|
|
|
|
|
};
|
2021-05-10 23:03:59 +01:00
|
|
|
FileInfo fi = new FileInfo(pkg);
|
|
|
|
|
if (!fi.Exists)
|
|
|
|
|
throw new Exception("Le fichier n'existe pas");
|
2021-05-11 02:38:52 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-10 23:03:59 +01:00
|
|
|
report.Executed = true;
|
|
|
|
|
return report;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|