Add extra request logging.

This commit is contained in:
Roger Far 2023-09-20 20:28:06 -06:00
parent 89efa76f76
commit 6ad6da5679
3 changed files with 37 additions and 4 deletions

View file

@ -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.Data;
using RdtClient.Data.Models.QBittorrent; using RdtClient.Data.Models.QBittorrent;
@ -7,12 +8,14 @@ namespace RdtClient.Service.Services;
public class QBittorrent public class QBittorrent
{ {
private readonly Authentication _authentication; private readonly Authentication _authentication;
private readonly ILogger<QBittorrent> _logger;
private readonly Settings _settings; private readonly Settings _settings;
private readonly Torrents _torrents; private readonly Torrents _torrents;
private readonly Downloads _downloads; private readonly Downloads _downloads;
public QBittorrent(Settings settings, Authentication authentication, Torrents torrents, Downloads downloads) public QBittorrent(ILogger<QBittorrent> logger, Settings settings, Authentication authentication, Torrents torrents, Downloads downloads)
{ {
_logger = logger;
_settings = settings; _settings = settings;
_authentication = authentication; _authentication = authentication;
_torrents = torrents; _torrents = torrents;
@ -21,6 +24,8 @@ public class QBittorrent
public async Task<Boolean> AuthLogin(String userName, String password) public async Task<Boolean> AuthLogin(String userName, String password)
{ {
_logger.LogDebug("Auth login");
var login = await _authentication.Login(userName, password); var login = await _authentication.Login(userName, password);
return login.Succeeded; return login.Succeeded;
@ -28,6 +33,8 @@ public class QBittorrent
public async Task AuthLogout() public async Task AuthLogout()
{ {
_logger.LogDebug("Auth logout");
await _authentication.Logout(); await _authentication.Logout();
} }
@ -405,6 +412,8 @@ public class QBittorrent
public async Task TorrentsDelete(String hash, Boolean deleteFiles) public async Task TorrentsDelete(String hash, Boolean deleteFiles)
{ {
_logger.LogDebug($"Delete {hash}");
var torrent = await _torrents.GetByHash(hash); var torrent = await _torrents.GetByHash(hash);
if (torrent == null) if (torrent == null)
@ -417,6 +426,8 @@ public class QBittorrent
public async Task TorrentsAddMagnet(String magnetLink, String? category, Int32? priority) public async Task TorrentsAddMagnet(String magnetLink, String? category, Int32? priority)
{ {
_logger.LogDebug($"Add magnet {category}");
var torrent = new Torrent var torrent = new Torrent
{ {
Category = category, Category = category,
@ -436,6 +447,8 @@ public class QBittorrent
public async Task TorrentsAddFile(Byte[] fileBytes, String? category, Int32? priority) public async Task TorrentsAddFile(Byte[] fileBytes, String? category, Int32? priority)
{ {
_logger.LogDebug($"Add file {category}");
var torrent = new Torrent var torrent = new Torrent
{ {
Category = category, Category = category,

View file

@ -14,10 +14,12 @@ namespace RdtClient.Web.Controllers;
[Route("api/v2")] [Route("api/v2")]
public class QBittorrentController : Controller public class QBittorrentController : Controller
{ {
private readonly ILogger<QBittorrentController> _logger;
private readonly QBittorrent _qBittorrent; private readonly QBittorrent _qBittorrent;
public QBittorrentController(QBittorrent qBittorrent) public QBittorrentController(ILogger<QBittorrentController> logger, QBittorrent qBittorrent)
{ {
_logger = logger;
_qBittorrent = qBittorrent; _qBittorrent = qBittorrent;
} }
@ -26,6 +28,8 @@ public class QBittorrentController : Controller
[HttpGet] [HttpGet]
public async Task<ActionResult> AuthLogin([FromQuery] QBAuthLoginRequest request) public async Task<ActionResult> AuthLogin([FromQuery] QBAuthLoginRequest request)
{ {
_logger.LogDebug($"Auth login");
if (String.IsNullOrWhiteSpace(request.UserName) || String.IsNullOrEmpty(request.Password)) if (String.IsNullOrWhiteSpace(request.UserName) || String.IsNullOrEmpty(request.Password))
{ {
return Ok("Fails."); return Ok("Fails.");
@ -55,6 +59,8 @@ public class QBittorrentController : Controller
[HttpPost] [HttpPost]
public async Task<ActionResult> AuthLogout() public async Task<ActionResult> AuthLogout()
{ {
_logger.LogDebug($"Auth logout");
await _qBittorrent.AuthLogout(); await _qBittorrent.AuthLogout();
return Ok(); return Ok();
} }
@ -285,6 +291,8 @@ public class QBittorrentController : Controller
return BadRequest(); return BadRequest();
} }
_logger.LogDebug($"Delete {request.Hashes}");
var hashes = request.Hashes.Split("|"); var hashes = request.Hashes.Split("|");
foreach (var hash in hashes) foreach (var hash in hashes)

View file

@ -12,10 +12,12 @@ namespace RdtClient.Web.Controllers;
public class TorrentsController : Controller public class TorrentsController : Controller
{ {
private readonly TorrentRunner _torrentRunner; private readonly TorrentRunner _torrentRunner;
private readonly ILogger<TorrentsController> _logger;
private readonly Torrents _torrents; private readonly Torrents _torrents;
public TorrentsController(Torrents torrents, TorrentRunner torrentRunner) public TorrentsController(ILogger<TorrentsController> logger, Torrents torrents, TorrentRunner torrentRunner)
{ {
_logger = logger;
_torrents = torrents; _torrents = torrents;
_torrentRunner = torrentRunner; _torrentRunner = torrentRunner;
} }
@ -81,6 +83,8 @@ public class TorrentsController : Controller
return BadRequest("Invalid Torrent"); return BadRequest("Invalid Torrent");
} }
_logger.LogDebug($"Add file");
var fileStream = file.OpenReadStream(); var fileStream = file.OpenReadStream();
await using var memoryStream = new MemoryStream(); await using var memoryStream = new MemoryStream();
@ -113,6 +117,8 @@ public class TorrentsController : Controller
return BadRequest("Invalid Torrent"); return BadRequest("Invalid Torrent");
} }
_logger.LogDebug($"Add magnet");
await _torrents.UploadMagnet(request.MagnetLink, request.Torrent); await _torrents.UploadMagnet(request.MagnetLink, request.Torrent);
return Ok(); return Ok();
@ -167,6 +173,8 @@ public class TorrentsController : Controller
return BadRequest(); return BadRequest();
} }
_logger.LogDebug($"Delete {torrentId}");
await _torrents.Delete(torrentId, request.DeleteData, request.DeleteRdTorrent, request.DeleteLocalFiles); await _torrents.Delete(torrentId, request.DeleteData, request.DeleteRdTorrent, request.DeleteLocalFiles);
return Ok(); return Ok();
@ -176,6 +184,8 @@ public class TorrentsController : Controller
[Route("Retry/{torrentId:guid}")] [Route("Retry/{torrentId:guid}")]
public async Task<ActionResult> Retry(Guid torrentId) public async Task<ActionResult> Retry(Guid torrentId)
{ {
_logger.LogDebug($"Retry {torrentId}");
await _torrents.UpdateRetry(torrentId, DateTimeOffset.UtcNow, 0); await _torrents.UpdateRetry(torrentId, DateTimeOffset.UtcNow, 0);
await _torrents.RetryTorrent(torrentId, 0); await _torrents.RetryTorrent(torrentId, 0);
@ -186,6 +196,8 @@ public class TorrentsController : Controller
[Route("RetryDownload/{downloadId:guid}")] [Route("RetryDownload/{downloadId:guid}")]
public async Task<ActionResult> RetryDownload(Guid downloadId) public async Task<ActionResult> RetryDownload(Guid downloadId)
{ {
_logger.LogDebug($"Retry download {downloadId}");
await _torrents.RetryDownload(downloadId); await _torrents.RetryDownload(downloadId);
return Ok(); return Ok();