Fix progress handler

This commit is contained in:
Caelan Sayler
2024-12-24 14:54:07 +00:00
committed by Caelan
parent 6eb35b8a81
commit 120aba3a2a
3 changed files with 10 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ public class ApiCommandRunner(ILogger logger, IFancyConsole console) : ICommand<
return;
}
string response = await client.InvokeEndpointAsync(options, options.Endpoint, options.Method, options.Body, token);
string response = await client.InvokeEndpointAsync(options.Endpoint, options.Method, options.Body, token);
Console.WriteLine(response);
}
}

View File

@@ -3,7 +3,7 @@ using System.Net.Http.Headers;
namespace Velopack.Flow;
public class HmacAuthHttpClientHandler : DelegatingHandler
public class HmacAuthHttpClientHandler(HttpMessageHandler innerHandler) : DelegatingHandler(innerHandler)
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{

View File

@@ -33,10 +33,11 @@ public class VelopackFlowServiceClient(
private HttpClient GetHttpClient(Action<int>? progress = null)
{
HttpMessageHandler primaryHandler = new HmacAuthHttpClientHandler();
HttpMessageHandler handler;
if (progress != null) {
var ph = new HttpFormatting::System.Net.Http.Handlers.ProgressMessageHandler(primaryHandler);
var ph = new HttpFormatting::System.Net.Http.Handlers.ProgressMessageHandler(
new HmacAuthHttpClientHandler(new HttpClientHandler() { AllowAutoRedirect = true }));
ph.HttpSendProgress += (_, args) => {
progress(args.ProgressPercentage);
// Console.WriteLine($"upload progress: {((double)args.BytesTransferred / args.TotalBytes) * 100.0}");
@@ -44,11 +45,12 @@ public class VelopackFlowServiceClient(
ph.HttpReceiveProgress += (_, args) => {
progress(args.ProgressPercentage);
};
primaryHandler = ph;
handler = ph;
} else {
handler = new HmacAuthHttpClientHandler(new HttpClientHandler() { AllowAutoRedirect = true });
}
var client = new HttpClient(primaryHandler);
var client = new HttpClient(handler);
client.DefaultRequestHeaders.Authorization = Authorization;
client.Timeout = TimeSpan.FromMinutes(Options.Timeout);
return client;
@@ -132,7 +134,6 @@ public class VelopackFlowServiceClient(
}
public async Task<string> InvokeEndpointAsync(
VelopackFlowServiceOptions? options,
string endpointUri,
string method,
string? body,
@@ -184,6 +185,7 @@ public class VelopackFlowServiceClient(
var filesToUpload = assets.GetNonReleaseAssetPaths().Select(p => (p, FileType.Installer))
.Concat([(fullAssetPath, FileType.Release)])
.Where(kvp => !kvp.Item1.Contains("-Portable.zip"))
.ToArray();
Logger.LogInformation("Beginning upload to Velopack Flow");