diff --git a/server/RdtClient.Service/Services/QBittorrent.cs b/server/RdtClient.Service/Services/QBittorrent.cs index 49ad1f2..86a8e2b 100644 --- a/server/RdtClient.Service/Services/QBittorrent.cs +++ b/server/RdtClient.Service/Services/QBittorrent.cs @@ -1,4 +1,5 @@ -using RdtClient.Data.Enums; +using Microsoft.Extensions.Logging; +using RdtClient.Data.Enums; using RdtClient.Data.Models.Data; using RdtClient.Data.Models.QBittorrent; @@ -7,12 +8,14 @@ namespace RdtClient.Service.Services; public class QBittorrent { private readonly Authentication _authentication; + private readonly ILogger _logger; private readonly Settings _settings; private readonly Torrents _torrents; private readonly Downloads _downloads; - public QBittorrent(Settings settings, Authentication authentication, Torrents torrents, Downloads downloads) + public QBittorrent(ILogger logger, Settings settings, Authentication authentication, Torrents torrents, Downloads downloads) { + _logger = logger; _settings = settings; _authentication = authentication; _torrents = torrents; @@ -21,6 +24,8 @@ public class QBittorrent public async Task AuthLogin(String userName, String password) { + _logger.LogDebug("Auth login"); + var login = await _authentication.Login(userName, password); return login.Succeeded; @@ -28,6 +33,8 @@ public class QBittorrent public async Task AuthLogout() { + _logger.LogDebug("Auth logout"); + await _authentication.Logout(); } @@ -405,6 +412,8 @@ public class QBittorrent public async Task TorrentsDelete(String hash, Boolean deleteFiles) { + _logger.LogDebug($"Delete {hash}"); + var torrent = await _torrents.GetByHash(hash); if (torrent == null) @@ -417,6 +426,8 @@ public class QBittorrent public async Task TorrentsAddMagnet(String magnetLink, String? category, Int32? priority) { + _logger.LogDebug($"Add magnet {category}"); + var torrent = new Torrent { Category = category, @@ -436,6 +447,8 @@ public class QBittorrent public async Task TorrentsAddFile(Byte[] fileBytes, String? category, Int32? priority) { + _logger.LogDebug($"Add file {category}"); + var torrent = new Torrent { Category = category, diff --git a/server/RdtClient.Web/Controllers/QBittorrentController.cs b/server/RdtClient.Web/Controllers/QBittorrentController.cs index 3a22c95..7136546 100644 --- a/server/RdtClient.Web/Controllers/QBittorrentController.cs +++ b/server/RdtClient.Web/Controllers/QBittorrentController.cs @@ -14,10 +14,12 @@ namespace RdtClient.Web.Controllers; [Route("api/v2")] public class QBittorrentController : Controller { + private readonly ILogger _logger; private readonly QBittorrent _qBittorrent; - public QBittorrentController(QBittorrent qBittorrent) + public QBittorrentController(ILogger logger, QBittorrent qBittorrent) { + _logger = logger; _qBittorrent = qBittorrent; } @@ -26,6 +28,8 @@ public class QBittorrentController : Controller [HttpGet] public async Task AuthLogin([FromQuery] QBAuthLoginRequest request) { + _logger.LogDebug($"Auth login"); + if (String.IsNullOrWhiteSpace(request.UserName) || String.IsNullOrEmpty(request.Password)) { return Ok("Fails."); @@ -55,6 +59,8 @@ public class QBittorrentController : Controller [HttpPost] public async Task AuthLogout() { + _logger.LogDebug($"Auth logout"); + await _qBittorrent.AuthLogout(); return Ok(); } @@ -285,6 +291,8 @@ public class QBittorrentController : Controller return BadRequest(); } + _logger.LogDebug($"Delete {request.Hashes}"); + var hashes = request.Hashes.Split("|"); foreach (var hash in hashes) diff --git a/server/RdtClient.Web/Controllers/TorrentsController.cs b/server/RdtClient.Web/Controllers/TorrentsController.cs index 88c3fef..4381b84 100644 --- a/server/RdtClient.Web/Controllers/TorrentsController.cs +++ b/server/RdtClient.Web/Controllers/TorrentsController.cs @@ -12,10 +12,12 @@ namespace RdtClient.Web.Controllers; public class TorrentsController : Controller { private readonly TorrentRunner _torrentRunner; + private readonly ILogger _logger; private readonly Torrents _torrents; - public TorrentsController(Torrents torrents, TorrentRunner torrentRunner) + public TorrentsController(ILogger logger, Torrents torrents, TorrentRunner torrentRunner) { + _logger = logger; _torrents = torrents; _torrentRunner = torrentRunner; } @@ -81,6 +83,8 @@ public class TorrentsController : Controller return BadRequest("Invalid Torrent"); } + _logger.LogDebug($"Add file"); + var fileStream = file.OpenReadStream(); await using var memoryStream = new MemoryStream(); @@ -113,6 +117,8 @@ public class TorrentsController : Controller return BadRequest("Invalid Torrent"); } + _logger.LogDebug($"Add magnet"); + await _torrents.UploadMagnet(request.MagnetLink, request.Torrent); return Ok(); @@ -167,6 +173,8 @@ public class TorrentsController : Controller return BadRequest(); } + _logger.LogDebug($"Delete {torrentId}"); + await _torrents.Delete(torrentId, request.DeleteData, request.DeleteRdTorrent, request.DeleteLocalFiles); return Ok(); @@ -176,6 +184,8 @@ public class TorrentsController : Controller [Route("Retry/{torrentId:guid}")] public async Task Retry(Guid torrentId) { + _logger.LogDebug($"Retry {torrentId}"); + await _torrents.UpdateRetry(torrentId, DateTimeOffset.UtcNow, 0); await _torrents.RetryTorrent(torrentId, 0); @@ -186,6 +196,8 @@ public class TorrentsController : Controller [Route("RetryDownload/{downloadId:guid}")] public async Task RetryDownload(Guid downloadId) { + _logger.LogDebug($"Retry download {downloadId}"); + await _torrents.RetryDownload(downloadId); return Ok();