Update for 6.3 and change to File Service Queue (#34)

* add request queue processing on clientside, switch to net7

* reuse httpclient

* dispose and renew httpclient on building connection

* add handling of QueueRequestDto to downloads

* group download by host and port

* refactor SendAsync to SendRequestAsync for readability

* add holding ctrl before clearing cache, add tooltip

* update pathing

* fixes to api usage in client

* fix rendermodel offsets

* fixes for downloads

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2023-01-11 14:41:13 +01:00
committed by GitHub
parent 964b29b87e
commit 099ac2b3a1
7 changed files with 130 additions and 38 deletions

View File

@@ -33,7 +33,7 @@ public partial class ApiController : IDisposable, IMareHubClient
private readonly FileCacheManager _fileDbManager;
private CancellationTokenSource _connectionCancellationTokenSource;
private Dictionary<JwtCache, string> _jwtToken = new();
private KeyValuePair<string, string> AuthorizationJwtHeader => new("Authorization", "Bearer " + _jwtToken.GetValueOrDefault(new JwtCache(ApiUri, _dalamudUtil.PlayerNameHashed, SecretKey), string.Empty));
private string Authorization => _jwtToken.GetValueOrDefault(new JwtCache(ApiUri, _dalamudUtil.PlayerNameHashed, SecretKey), string.Empty);
private HubConnection? _mareHub;
@@ -49,6 +49,8 @@ public partial class ApiController : IDisposable, IMareHubClient
public bool IsAdmin => _connectionDto?.IsAdmin ?? false;
private HttpClient _httpClient;
public ApiController(Configuration pluginConfiguration, DalamudUtil dalamudUtil, FileCacheManager fileDbManager)
{
Logger.Verbose("Creating " + nameof(ApiController));
@@ -144,6 +146,9 @@ public partial class ApiController : IDisposable, IMareHubClient
{
Logger.Debug("CreateConnections called");
_httpClient?.Dispose();
_httpClient = new();
if (_pluginConfiguration.FullPause)
{
Logger.Info("Not recreating Connection, paused");
@@ -181,9 +186,9 @@ public partial class ApiController : IDisposable, IMareHubClient
{
Logger.Debug("Requesting new JWT");
using HttpClient httpClient = new();
var postUri = new Uri(new Uri(ApiUri
var postUri = MareAuth.AuthFullPath(new Uri(ApiUri
.Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase)
.Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase)), MareAuth.AuthFullPath);
.Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase)));
using var sha256 = SHA256.Create();
var auth = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(SecretKey))).Replace("-", "", StringComparison.OrdinalIgnoreCase);
var result = await httpClient.PostAsync(postUri, new FormUrlEncodedContent(new[]
@@ -343,7 +348,7 @@ public partial class ApiController : IDisposable, IMareHubClient
return new HubConnectionBuilder()
.WithUrl(ApiUri + hubName, options =>
{
options.Headers.Add(AuthorizationJwtHeader);
options.Headers.Add("Authorization", "Bearer " + Authorization);
options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling;
})
.WithAutomaticReconnect(new ForeverRetryPolicy())