- Applied to TorBox, can be extended easily to other providers - Reads response headers commonplace for pre-emptive rate limit throttling and retry-after - When a rate limit is reached, displays a warning in the UI - Fix socket leak from direct allocation of HttpClient, replaced with factory which handles pooling and re-use of sockets. While HttpClient is Disposable, it doesn't gaurantee (and does not) directly release underlying sockets for queries at the time the client is disposed. These sockets will go into a TCP WAIT state often for a very long time. The expected pattern in C# is to always use the HttClientFactory which will correctly handle re-use of the OS sockets in suqsequent queries reducing resource and memory leaks.
87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
using Microsoft.AspNetCore.SignalR;
|
|
using RdtClient.Data.Models.Internal;
|
|
|
|
namespace RdtClient.Service.Services;
|
|
|
|
public class RemoteService(IHubContext<RdtHub> hub, Torrents torrents)
|
|
{
|
|
public async Task Update()
|
|
{
|
|
var allTorrents = await torrents.Get();
|
|
|
|
var torrentDtos = allTorrents.Select(torrent => new TorrentDto
|
|
{
|
|
TorrentId = torrent.TorrentId,
|
|
Hash = torrent.Hash,
|
|
Category = torrent.Category,
|
|
DownloadAction = torrent.DownloadAction,
|
|
FinishedAction = torrent.FinishedAction,
|
|
FinishedActionDelay = torrent.FinishedActionDelay,
|
|
HostDownloadAction = torrent.HostDownloadAction,
|
|
DownloadMinSize = torrent.DownloadMinSize,
|
|
IncludeRegex = torrent.IncludeRegex,
|
|
ExcludeRegex = torrent.ExcludeRegex,
|
|
DownloadManualFiles = torrent.DownloadManualFiles,
|
|
DownloadClient = torrent.DownloadClient,
|
|
Added = torrent.Added,
|
|
FilesSelected = torrent.FilesSelected,
|
|
Completed = torrent.Completed,
|
|
Type = torrent.Type,
|
|
IsFile = torrent.IsFile,
|
|
Priority = torrent.Priority,
|
|
RetryCount = torrent.RetryCount,
|
|
DownloadRetryAttempts = torrent.DownloadRetryAttempts,
|
|
TorrentRetryAttempts = torrent.TorrentRetryAttempts,
|
|
DeleteOnError = torrent.DeleteOnError,
|
|
Lifetime = torrent.Lifetime,
|
|
Error = torrent.Error,
|
|
RdId = torrent.RdId,
|
|
RdName = torrent.RdName,
|
|
RdSize = torrent.RdSize,
|
|
RdHost = torrent.RdHost,
|
|
RdSplit = torrent.RdSplit,
|
|
RdProgress = torrent.RdProgress,
|
|
RdStatus = torrent.RdStatus,
|
|
RdStatusRaw = torrent.RdStatusRaw,
|
|
RdAdded = torrent.RdAdded,
|
|
RdEnded = torrent.RdEnded,
|
|
RdSpeed = torrent.RdSpeed,
|
|
RdSeeders = torrent.RdSeeders,
|
|
Files = torrent.Files,
|
|
Downloads = torrent.Downloads.Select(download => new DownloadDto
|
|
{
|
|
DownloadId = download.DownloadId,
|
|
TorrentId = download.TorrentId,
|
|
Path = download.Path,
|
|
Link = download.Link,
|
|
Added = download.Added,
|
|
DownloadQueued = download.DownloadQueued,
|
|
DownloadStarted = download.DownloadStarted,
|
|
DownloadFinished = download.DownloadFinished,
|
|
UnpackingQueued = download.UnpackingQueued,
|
|
UnpackingStarted = download.UnpackingStarted,
|
|
UnpackingFinished = download.UnpackingFinished,
|
|
Completed = download.Completed,
|
|
RetryCount = download.RetryCount,
|
|
Error = download.Error,
|
|
BytesTotal = download.BytesTotal,
|
|
BytesDone = download.BytesDone,
|
|
Speed = download.Speed
|
|
}).ToList()
|
|
}).ToList();
|
|
await hub.Clients.All.SendCoreAsync("update",
|
|
[
|
|
torrentDtos
|
|
]);
|
|
}
|
|
|
|
public async Task UpdateDiskSpaceStatus(Object status)
|
|
{
|
|
await hub.Clients.All.SendCoreAsync("diskSpaceStatus", [status]);
|
|
}
|
|
|
|
public async Task UpdateRateLimitStatus(RateLimitStatus status)
|
|
{
|
|
await hub.Clients.All.SendCoreAsync("rateLimitStatus", [status]);
|
|
}
|
|
}
|