diff --git a/server/RdtClient.Data/Enums/TorrentStatus.cs b/server/RdtClient.Data/Enums/TorrentStatus.cs index 37e49fd..dc3e433 100644 --- a/server/RdtClient.Data/Enums/TorrentStatus.cs +++ b/server/RdtClient.Data/Enums/TorrentStatus.cs @@ -2,6 +2,7 @@ public enum TorrentStatus { + // Queued by RDTClient, not the provider. Queued = 0, Processing = 1, diff --git a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs index 30d6ddd..365369b 100644 --- a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs +++ b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs @@ -478,4 +478,36 @@ public class TorBoxDebridClientTest Assert.Equal("https://real-usenet-link", result); usenetApiMock.Verify(m => m.RequestDownloadAsync(98765, 4321, false, It.IsAny()), Times.Once); } + + [Fact] + public async Task UpdateData_LogsWarning_WhenTorBoxStatusIsUnmapped() + { + // Arrange + var torrent = new Torrent + { + RdId = "test-rd-id", + RdStatus = TorrentStatus.Downloading, + RdName = "test-torrent" + }; + var torrentClientTorrent = new DebridClientTorrent + { + Status = "some-unknown-status", + Filename = "test-torrent" + }; + + var clientMock = new Mock(_loggerMock.Object, _httpClientFactoryMock.Object, _fileFilterMock.Object); + + // Act + await clientMock.Object.UpdateData(torrent, torrentClientTorrent); + + // Assert + _loggerMock.Verify( + x => x.Log( + Microsoft.Extensions.Logging.LogLevel.Information, + It.IsAny(), + It.Is((v, t) => v.ToString()!.Contains("unmapped status") && v.ToString()!.Contains("some-unknown-status")), + It.IsAny(), + It.Is>((v, t) => true)), + Times.Once); + } } diff --git a/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs b/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs index cb23cc6..53ccb7b 100644 --- a/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs +++ b/server/RdtClient.Service/Services/DebridClients/TorBoxDebridClient.cs @@ -389,13 +389,17 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF } else { + logger.LogTrace("Updating status for {TorrentName} from {OldStatus} to {NewStatus}", torrent.RdName, torrent.RdStatus, rdTorrent.Status); torrent.RdStatus = rdTorrent.Status switch { + "allocating" => TorrentStatus.Processing, "queued" => TorrentStatus.Processing, + "queuedDL" => TorrentStatus.Processing, "metaDL" => TorrentStatus.Processing, "checking" => TorrentStatus.Processing, "checkingResumeData" => TorrentStatus.Processing, "paused" => TorrentStatus.Downloading, + "pausedDL" => TorrentStatus.Downloading, "stalledDL" => TorrentStatus.Downloading, "downloading" => TorrentStatus.Downloading, "completed" => TorrentStatus.Downloading, @@ -404,8 +408,11 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF "stalled" => TorrentStatus.Downloading, "stalled (no seeds)" => TorrentStatus.Downloading, "processing" => TorrentStatus.Downloading, + "checkingDL" => TorrentStatus.Downloading, "cached" => TorrentStatus.Finished, - _ => TorrentStatus.Error + "error" => TorrentStatus.Error, + _ when rdTorrent.Status != null && rdTorrent.Status.StartsWith("failed") => TorrentStatus.Error, + _ => LogUnmappedStatus(rdTorrent.Status, torrent) }; } } @@ -555,6 +562,16 @@ public class TorBoxDebridClient(ILogger logger, IHttpClientF } } + private TorrentStatus LogUnmappedStatus(String? status, Torrent torrent) + { + if (!String.IsNullOrWhiteSpace(status)) + { + logger.LogInformation("TorBoxDebridClient encountered an unmapped status: {Status} for torrent {TorrentName}", status, torrent.RdName); + } + + return torrent.RdStatus ?? TorrentStatus.Processing; + } + private void Log(String message, Torrent? torrent = null) { if (torrent != null)