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.
This commit is contained in:
parent
1166e9ba99
commit
e1635a43a9
4 changed files with 20 additions and 25 deletions
|
|
@ -21,7 +21,7 @@
|
||||||
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="22.1.1" />
|
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="22.1.1" />
|
||||||
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="22.1.1" />
|
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="22.1.1" />
|
||||||
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.1.1" />
|
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.1.1" />
|
||||||
<PackageReference Include="TorBox.NET" Version="2.0.0" />
|
<PackageReference Include="TorBox.NET" Version="2.1.0" />
|
||||||
<PackageReference Include="xunit" Version="2.9.3" />
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ public class TorBoxDebridClientTest
|
||||||
{
|
{
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
|
Id = 12345,
|
||||||
Hash = "hash1",
|
Hash = "hash1",
|
||||||
Name = "torrent1",
|
Name = "torrent1",
|
||||||
Size = 1000,
|
Size = 1000,
|
||||||
|
|
@ -76,7 +77,7 @@ public class TorBoxDebridClientTest
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, result.Count);
|
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.NotNull(torrentResult);
|
||||||
Assert.Equal(DownloadType.Torrent, torrentResult.Type);
|
Assert.Equal(DownloadType.Torrent, torrentResult.Type);
|
||||||
|
|
||||||
|
|
@ -198,12 +199,12 @@ public class TorBoxDebridClientTest
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Delete_CallsTorrentsControl_WhenTypeIsTorrent()
|
public async Task Delete_CallsTorrentsControlById_WhenTypeIsTorrent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var torrent = new Torrent
|
var torrent = new Torrent
|
||||||
{
|
{
|
||||||
RdId = "torrent-id",
|
RdId = "12345",
|
||||||
Type = DownloadType.Torrent
|
Type = DownloadType.Torrent
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -218,7 +219,7 @@ public class TorBoxDebridClientTest
|
||||||
await clientMock.Object.Delete(torrent);
|
await clientMock.Object.Delete(torrent);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
torrentsApiMock.Verify(m => m.ControlAsync("torrent-id", "delete", It.IsAny<CancellationToken>()), Times.Once);
|
torrentsApiMock.Verify(m => m.ControlByIdAsync(12345, "delete", It.IsAny<CancellationToken>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -373,6 +374,7 @@ public class TorBoxDebridClientTest
|
||||||
var torrent = new Torrent
|
var torrent = new Torrent
|
||||||
{
|
{
|
||||||
Hash = "test-hash",
|
Hash = "test-hash",
|
||||||
|
RdId = "12345",
|
||||||
RdFiles = JsonConvert.SerializeObject(files)
|
RdFiles = JsonConvert.SerializeObject(files)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -383,12 +385,6 @@ public class TorBoxDebridClientTest
|
||||||
torBoxClientMock.Setup(m => m.Torrents).Returns(torrentsApiMock.Object);
|
torBoxClientMock.Setup(m => m.Torrents).Returns(torrentsApiMock.Object);
|
||||||
clientMock.Protected().Setup<ITorBoxNetClient>("GetClient", ItExpr.IsAny<String>()).Returns(torBoxClientMock.Object);
|
clientMock.Protected().Setup<ITorBoxNetClient>("GetClient", ItExpr.IsAny<String>()).Returns(torBoxClientMock.Object);
|
||||||
|
|
||||||
torrentsApiMock.Setup(m => m.GetHashInfoAsync("test-hash", true, 1000, It.IsAny<CancellationToken>()))
|
|
||||||
.ReturnsAsync(new TorrentInfoResult
|
|
||||||
{
|
|
||||||
Id = 12345
|
|
||||||
});
|
|
||||||
|
|
||||||
_fileFilterMock.Setup(m => m.IsDownloadable(torrent, It.IsAny<String>(), It.IsAny<Int64>())).Returns(true);
|
_fileFilterMock.Setup(m => m.IsDownloadable(torrent, It.IsAny<String>(), It.IsAny<Int64>())).Returns(true);
|
||||||
|
|
||||||
Settings.Get.Provider.PreferZippedDownloads = false;
|
Settings.Get.Provider.PreferZippedDownloads = false;
|
||||||
|
|
@ -420,6 +416,7 @@ public class TorBoxDebridClientTest
|
||||||
var torrent = new Torrent
|
var torrent = new Torrent
|
||||||
{
|
{
|
||||||
Hash = "test-hash",
|
Hash = "test-hash",
|
||||||
|
RdId = "12345",
|
||||||
RdName = "TestTorrent",
|
RdName = "TestTorrent",
|
||||||
RdFiles = JsonConvert.SerializeObject(files),
|
RdFiles = JsonConvert.SerializeObject(files),
|
||||||
DownloadClient = DownloadClient.Aria2c
|
DownloadClient = DownloadClient.Aria2c
|
||||||
|
|
@ -434,12 +431,6 @@ public class TorBoxDebridClientTest
|
||||||
torBoxClientMock.Setup(m => m.Torrents).Returns(torrentsApiMock.Object);
|
torBoxClientMock.Setup(m => m.Torrents).Returns(torrentsApiMock.Object);
|
||||||
clientMock.Protected().Setup<ITorBoxNetClient>("GetClient", ItExpr.IsAny<String>()).Returns(torBoxClientMock.Object);
|
clientMock.Protected().Setup<ITorBoxNetClient>("GetClient", ItExpr.IsAny<String>()).Returns(torBoxClientMock.Object);
|
||||||
|
|
||||||
torrentsApiMock.Setup(m => m.GetHashInfoAsync("test-hash", true, 1000, It.IsAny<CancellationToken>()))
|
|
||||||
.ReturnsAsync(new TorrentInfoResult
|
|
||||||
{
|
|
||||||
Id = 12345
|
|
||||||
});
|
|
||||||
|
|
||||||
_fileFilterMock.Setup(m => m.IsDownloadable(torrent, It.IsAny<String>(), It.IsAny<Int64>())).Returns(true);
|
_fileFilterMock.Setup(m => m.IsDownloadable(torrent, It.IsAny<String>(), It.IsAny<Int64>())).Returns(true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
<PackageReference Include="Synology.Api.Client" Version="[0.3.93]" />
|
<PackageReference Include="Synology.Api.Client" Version="[0.3.93]" />
|
||||||
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="22.1.1" />
|
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="22.1.1" />
|
||||||
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.1.1" />
|
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.1.1" />
|
||||||
<PackageReference Include="TorBox.NET" Version="2.0.0" />
|
<PackageReference Include="TorBox.NET" Version="2.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ public class TorBoxDebridClient(ILogger<TorBoxDebridClient> logger, IHttpClientF
|
||||||
allowZip: Settings.Get.Provider.PreferZippedDownloads,
|
allowZip: Settings.Get.Provider.PreferZippedDownloads,
|
||||||
as_queued: asQueued);
|
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<TorBoxDebridClient> logger, IHttpClientF
|
||||||
allowZip: Settings.Get.Provider.PreferZippedDownloads,
|
allowZip: Settings.Get.Provider.PreferZippedDownloads,
|
||||||
as_queued: asQueued);
|
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<TorBoxDebridClient> logger, IHttpClientF
|
||||||
}
|
}
|
||||||
else
|
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<TorBoxDebridClient> logger, IHttpClientF
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var torrentId = await HandleErrors(() => GetClient().Torrents.GetHashInfoAsync(torrent.Hash, true));
|
if (torrent.RdId == null)
|
||||||
id = torrentId?.Id;
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = Int32.Parse(torrent.RdId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == null)
|
if (id == null)
|
||||||
|
|
@ -447,7 +451,7 @@ public class TorBoxDebridClient(ILogger<TorBoxDebridClient> logger, IHttpClientF
|
||||||
{
|
{
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Id = torrent.Hash,
|
Id = torrent.Id.ToString(),
|
||||||
Filename = torrent.Name,
|
Filename = torrent.Name,
|
||||||
OriginalFilename = torrent.Name,
|
OriginalFilename = torrent.Name,
|
||||||
Hash = torrent.Hash,
|
Hash = torrent.Hash,
|
||||||
|
|
@ -602,7 +606,7 @@ public class TorBoxDebridClient(ILogger<TorBoxDebridClient> logger, IHttpClientF
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var result = await GetClient().Torrents.GetHashInfoAsync(id, true);
|
var result = await GetClient().Torrents.GetIdInfoAsync(Int32.Parse(id), true);
|
||||||
|
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue