Merge pull request #645 from asylumexp/fix/torbox-availability

[TB] Fix Index was out of range error #644
This commit is contained in:
Roger Far 2025-01-03 15:53:07 -07:00 committed by GitHub
commit 8205e0e652
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 21 deletions

View file

@ -22,7 +22,7 @@
<PackageReference Include="Serilog" Version="4.2.0" /> <PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="SharpCompress" Version="0.38.0" /> <PackageReference Include="SharpCompress" Version="0.38.0" />
<PackageReference Include="TorBox.NET" Version="1.2.1" /> <PackageReference Include="TorBox.NET" Version="1.3.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -40,20 +40,20 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
{ {
foreach (var inner in ae.InnerExceptions) foreach (var inner in ae.InnerExceptions)
{ {
logger.LogError(inner, $"The connection to RealDebrid has failed: {inner.Message}"); logger.LogError(inner, $"The connection to TorBox has failed: {inner.Message}");
} }
throw; throw;
} }
catch (TaskCanceledException ex) when (ex.InnerException is TimeoutException) catch (TaskCanceledException ex) when (ex.InnerException is TimeoutException)
{ {
logger.LogError(ex, $"The connection to RealDebrid has timed out: {ex.Message}"); logger.LogError(ex, $"The connection to TorBox has timed out: {ex.Message}");
throw; throw;
} }
catch (TaskCanceledException ex) catch (TaskCanceledException ex)
{ {
logger.LogError(ex, $"The connection to RealDebrid has timed out: {ex.Message}"); logger.LogError(ex, $"The connection to TorBox has timed out: {ex.Message}");
throw; throw;
} }
@ -120,13 +120,9 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
public async Task<String> AddMagnet(String magnetLink) public async Task<String> AddMagnet(String magnetLink)
{ {
// var seeding = Settings.Get.Integrations.Default.FinishedAction; var user = await GetClient().User.GetAsync(true);
// Line is not working right now, will disable seeding and fix in december when I have time again. var result = await GetClient().Torrents.AddMagnetAsync(magnetLink, user.Data?.Settings?.SeedTorrents ?? 3, false);
// var seed = (seeding == TorrentFinishedAction.RemoveAllTorrents || seeding == TorrentFinishedAction.RemoveRealDebrid) ? 3 : 2;
var seed = 3;
var result = await GetClient().Torrents.AddMagnetAsync(magnetLink, seed, false);
if (result.Error == "ACTIVE_LIMIT") if (result.Error == "ACTIVE_LIMIT")
{ {
@ -141,11 +137,9 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
public async Task<String> AddFile(Byte[] bytes) public async Task<String> AddFile(Byte[] bytes)
{ {
// Line is not working right now, will disable seeding and fix in december when I have time again. var user = await GetClient().User.GetAsync(true);
// var seed = (seeding == TorrentFinishedAction.RemoveAllTorrents || seeding == TorrentFinishedAction.RemoveRealDebrid) ? 3 : 2;
const Int32 seed = 3;
var result = await GetClient().Torrents.AddFileAsync(bytes, seed); var result = await GetClient().Torrents.AddFileAsync(bytes, user.Data?.Settings?.SeedTorrents ?? 3);
if (result.Error == "ACTIVE_LIMIT") if (result.Error == "ACTIVE_LIMIT")
{ {
using var stream = new MemoryStream(bytes); using var stream = new MemoryStream(bytes);
@ -161,17 +155,16 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
{ {
var availability = await GetClient().Torrents.GetAvailabilityAsync(hash, listFiles: true); var availability = await GetClient().Torrents.GetAvailabilityAsync(hash, listFiles: true);
if (availability.Data != null || availability.Data?.Count < 0) if (availability.Data != null && availability.Data.Count > 0)
{ {
return (availability.Data[0]?.Files ?? []).Select(file => new TorrentClientAvailableFile return (availability.Data[0]?.Files ?? []).Select(file => new TorrentClientAvailableFile
{ {
Filename = file.Name, Filename = file.Name,
Filesize = file.Size Filesize = file.Size
}) }).ToList();
.ToList();
} }
return []; return new List<TorrentClientAvailableFile>();
} }
public Task SelectFiles(Data.Models.Data.Torrent torrent) public Task SelectFiles(Data.Models.Data.Torrent torrent)