mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 22:17:22 +01:00
potential fix for downloads hanging at 0 bytes
This commit is contained in:
parent
9307aaecac
commit
b65ae8fca3
3 changed files with 25 additions and 18 deletions
|
|
@ -3,6 +3,7 @@ using MareSynchronos.Services.Mediator;
|
|||
using MareSynchronos.Services.ServerConfiguration;
|
||||
using MareSynchronos.WebAPI.Files.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection;
|
||||
|
|
@ -17,6 +18,7 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
|||
private readonly ServerConfigurationManager _serverManager;
|
||||
private int _availableDownloadSlots;
|
||||
private SemaphoreSlim _downloadSemaphore;
|
||||
private readonly ConcurrentDictionary<Guid, bool> _downloadReady = new();
|
||||
|
||||
public FileTransferOrchestrator(ILogger<FileTransferOrchestrator> logger, MareConfigService mareConfig, ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
|
||||
{
|
||||
|
|
@ -39,6 +41,10 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
|||
{
|
||||
FilesCdnUri = null;
|
||||
});
|
||||
Mediator.Subscribe<DownloadReadyMessage>(this, (msg) =>
|
||||
{
|
||||
_downloadReady[msg.RequestId] = true;
|
||||
});
|
||||
}
|
||||
|
||||
public Uri? FilesCdnUri { private set; get; }
|
||||
|
|
@ -50,6 +56,21 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
|||
_downloadSemaphore.Release();
|
||||
}
|
||||
|
||||
public bool IsDownloadReady(Guid guid)
|
||||
{
|
||||
if (_downloadReady.TryGetValue(guid, out bool isReady) && isReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ClearDownloadRequest(Guid guid)
|
||||
{
|
||||
_downloadReady.Remove(guid, out _);
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri, CancellationToken? ct = null)
|
||||
{
|
||||
using var requestMessage = new HttpRequestMessage(method, uri);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue