From e1635a43a9c70debc36245a2857d6f161f1f0f22 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Thu, 28 May 2026 14:50:39 +1000 Subject: [PATCH] fix: remove usage of GetHashInfoAsync Removes GetHashInfoAsync, and only uses the actual torrentId. This was originally required as cachedtorrents endpoints used to use a different torrentId to the regular torrent endpoints for whatever reason, but luckily they figured out a while ago that that was not a good idea and just combined them which means calling API to search for hashes isnt needed anymore, hopefully this will reduce rate limiting a bit. --- .../RdtClient.Service.Test.csproj | 2 +- .../TorrentClients/TorBoxDebridClientTest.cs | 23 ++++++------------- .../RdtClient.Service.csproj | 2 +- .../DebridClients/TorBoxDebridClient.cs | 18 +++++++++------ 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj b/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj index 4abcc2d..987703d 100644 --- a/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj +++ b/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj @@ -21,7 +21,7 @@ - + all diff --git a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs index a19381f..24b7fa8 100644 --- a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs +++ b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs @@ -44,6 +44,7 @@ public class TorBoxDebridClientTest { new() { + Id = 12345, Hash = "hash1", Name = "torrent1", Size = 1000, @@ -76,7 +77,7 @@ public class TorBoxDebridClientTest // Assert Assert.Equal(2, result.Count); - var torrentResult = result.FirstOrDefault(r => r.Id == "hash1"); + var torrentResult = result.FirstOrDefault(r => r.Id == "12345"); Assert.NotNull(torrentResult); Assert.Equal(DownloadType.Torrent, torrentResult.Type); @@ -198,12 +199,12 @@ public class TorBoxDebridClientTest } [Fact] - public async Task Delete_CallsTorrentsControl_WhenTypeIsTorrent() + public async Task Delete_CallsTorrentsControlById_WhenTypeIsTorrent() { // Arrange var torrent = new Torrent { - RdId = "torrent-id", + RdId = "12345", Type = DownloadType.Torrent }; @@ -218,7 +219,7 @@ public class TorBoxDebridClientTest await clientMock.Object.Delete(torrent); // Assert - torrentsApiMock.Verify(m => m.ControlAsync("torrent-id", "delete", It.IsAny()), Times.Once); + torrentsApiMock.Verify(m => m.ControlByIdAsync(12345, "delete", It.IsAny()), Times.Once); } [Fact] @@ -373,6 +374,7 @@ public class TorBoxDebridClientTest var torrent = new Torrent { Hash = "test-hash", + RdId = "12345", RdFiles = JsonConvert.SerializeObject(files) }; @@ -383,12 +385,6 @@ public class TorBoxDebridClientTest torBoxClientMock.Setup(m => m.Torrents).Returns(torrentsApiMock.Object); clientMock.Protected().Setup("GetClient", ItExpr.IsAny()).Returns(torBoxClientMock.Object); - torrentsApiMock.Setup(m => m.GetHashInfoAsync("test-hash", true, 1000, It.IsAny())) - .ReturnsAsync(new TorrentInfoResult - { - Id = 12345 - }); - _fileFilterMock.Setup(m => m.IsDownloadable(torrent, It.IsAny(), It.IsAny())).Returns(true); Settings.Get.Provider.PreferZippedDownloads = false; @@ -420,6 +416,7 @@ public class TorBoxDebridClientTest var torrent = new Torrent { Hash = "test-hash", + RdId = "12345", RdName = "TestTorrent", RdFiles = JsonConvert.SerializeObject(files), DownloadClient = DownloadClient.Aria2c @@ -434,12 +431,6 @@ public class TorBoxDebridClientTest torBoxClientMock.Setup(m => m.Torrents).Returns(torrentsApiMock.Object); clientMock.Protected().Setup("GetClient", ItExpr.IsAny()).Returns(torBoxClientMock.Object); - torrentsApiMock.Setup(m => m.GetHashInfoAsync("test-hash", true, 1000, It.IsAny())) - .ReturnsAsync(new TorrentInfoResult - { - Id = 12345 - }); - _fileFilterMock.Setup(m => m.IsDownloadable(torrent, It.IsAny(), It.IsAny())).Returns(true); // Act diff --git a/server/RdtClient.Service/RdtClient.Service.csproj b/server/RdtClient.Service/RdtClient.Service.csproj index 758787a..5a6e5ca 100644 --- a/server/RdtClient.Service/RdtClient.Service.csproj +++ b/server/RdtClient.Service/RdtClient.Service.csproj @@ -26,7 +26,7 @@ - + diff --git a/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs b/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs index 98b9b17..0677614 100644 --- a/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs +++ b/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs @@ -74,7 +74,7 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF allowZip: Settings.Get.Provider.PreferZippedDownloads, as_queued: asQueued); - return result.Data!.Hash!; + return result.Data?.TorrentId?.ToString() ?? throw new InvalidOperationException("TorBox API did not return torrent ID."); }); } @@ -88,7 +88,7 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF allowZip: Settings.Get.Provider.PreferZippedDownloads, as_queued: asQueued); - return result.Data!.Hash!; + return result.Data?.TorrentId?.ToString() ?? throw new InvalidOperationException("TorBox API did not return torrent ID"); }); } @@ -162,7 +162,7 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF } else { - await GetClient().Torrents.ControlAsync(torrent.RdId, "delete"); + await GetClient().Torrents.ControlByIdAsync(Int32.Parse(torrent.RdId), "delete"); } }); } @@ -322,8 +322,12 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF } else { - var torrentId = await HandleErrors(() => GetClient().Torrents.GetHashInfoAsync(torrent.Hash, true)); - id = torrentId?.Id; + if (torrent.RdId == null) + { + return null; + } + + id = Int32.Parse(torrent.RdId); } if (id == null) @@ -447,7 +451,7 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF { return new() { - Id = torrent.Hash, + Id = torrent.Id.ToString(), Filename = torrent.Name, OriginalFilename = torrent.Name, Hash = torrent.Hash, @@ -602,7 +606,7 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF } else { - var result = await GetClient().Torrents.GetHashInfoAsync(id, true); + var result = await GetClient().Torrents.GetIdInfoAsync(Int32.Parse(id), true); if (result != null) {