diff --git a/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj b/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj
index 9483522..143f40a 100644
--- a/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj
+++ b/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj
@@ -22,7 +22,7 @@
-
+
all
diff --git a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs
index 66b405c..49514cf 100644
--- a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs
+++ b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs
@@ -46,6 +46,7 @@ public class TorBoxDebridClientTest
{
new()
{
+ Id = 12345,
Hash = "hash1",
Name = "torrent1",
Size = 1000,
@@ -78,7 +79,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);
@@ -200,12 +201,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
};
@@ -220,7 +221,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]
@@ -375,6 +376,7 @@ public class TorBoxDebridClientTest
var torrent = new Torrent
{
Hash = "test-hash",
+ RdId = "12345",
RdFiles = JsonConvert.SerializeObject(files)
};
@@ -385,12 +387,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.Current.Provider.PreferZippedDownloads = false;
@@ -422,6 +418,7 @@ public class TorBoxDebridClientTest
var torrent = new Torrent
{
Hash = "test-hash",
+ RdId = "12345",
RdName = "TestTorrent",
RdFiles = JsonConvert.SerializeObject(files),
DownloadClient = DownloadClient.Aria2c
@@ -436,12 +433,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 916e039..8c7dfe5 100644
--- a/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs
+++ b/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs
@@ -81,7 +81,7 @@ public class TorBoxDebridClient(
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.");
});
}
@@ -97,7 +97,7 @@ public class TorBoxDebridClient(
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");
});
}
@@ -171,7 +171,7 @@ public class TorBoxDebridClient(
}
else
{
- await GetClient().Torrents.ControlAsync(torrent.RdId, "delete");
+ await GetClient().Torrents.ControlByIdAsync(Int32.Parse(torrent.RdId), "delete");
}
});
}
@@ -331,8 +331,12 @@ public class TorBoxDebridClient(
}
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)
@@ -456,7 +460,7 @@ public class TorBoxDebridClient(
{
return new()
{
- Id = torrent.Hash,
+ Id = torrent.Id.ToString(),
Filename = torrent.Name,
OriginalFilename = torrent.Name,
Hash = torrent.Hash,
@@ -611,7 +615,7 @@ public class TorBoxDebridClient(
}
else
{
- var result = await GetClient().Torrents.GetHashInfoAsync(id, true);
+ var result = await GetClient().Torrents.GetIdInfoAsync(Int32.Parse(id), true);
if (result != null)
{
diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs
index ce15b4d..30c600b 100644
--- a/server/RdtClient.Service/Services/Torrents.cs
+++ b/server/RdtClient.Service/Services/Torrents.cs
@@ -664,6 +664,38 @@ public class Torrents(
{
torrentsByRdId.TryGetValue(rdTorrent.Id, out var torrent);
+ // TorBox migration from storing torrent hash in RdId to torrent ids.
+ if (torrent == null
+ && Settings.Get.Provider.Provider == Provider.TorBox
+ && rdTorrent.Type == DownloadType.Torrent
+ && !String.IsNullOrWhiteSpace(rdTorrent.Hash)
+ && !String.IsNullOrWhiteSpace(rdTorrent.Id))
+ {
+ torrent = torrents.FirstOrDefault(localTorrent => localTorrent is { Type: DownloadType.Torrent, ClientKind: null or Provider.TorBox }
+ && !String.IsNullOrWhiteSpace(localTorrent.Hash)
+ && !String.IsNullOrWhiteSpace(localTorrent.RdId)
+ && localTorrent.RdId.Equals(localTorrent.Hash, StringComparison.OrdinalIgnoreCase)
+ && localTorrent.Hash.Equals(rdTorrent.Hash, StringComparison.OrdinalIgnoreCase));
+
+ if (torrent != null)
+ {
+ if (!String.IsNullOrWhiteSpace(torrent.RdId))
+ {
+ torrentsByRdId.Remove(torrent.RdId);
+ }
+
+ await torrentData.UpdateRdId(torrent, rdTorrent.Id);
+ torrent.RdId = rdTorrent.Id;
+ torrent.ClientKind = Provider.TorBox;
+ torrentsByRdId[rdTorrent.Id] = torrent;
+
+ logger.LogInformation("Migrated TorBox torrent RdId from hash to torrent id for {TorrentName} ({Hash}) -> {RdId}",
+ torrent.RdName ?? rdTorrent.Filename,
+ rdTorrent.Hash,
+ rdTorrent.Id);
+ }
+ }
+
// Auto import torrents only torrents that have their files selected
if (torrent == null && settings.Current.Provider.AutoImport)
{