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; 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); Console.WriteLine(response);
} }
} }

View File

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