Add extra request logging.
This commit is contained in:
parent
89efa76f76
commit
6ad6da5679
3 changed files with 37 additions and 4 deletions
|
|
@ -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<QBittorrent> _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<QBittorrent> 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<Boolean> 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,
|
||||
|
|
|
|||
|
|
@ -14,10 +14,12 @@ namespace RdtClient.Web.Controllers;
|
|||
[Route("api/v2")]
|
||||
public class QBittorrentController : Controller
|
||||
{
|
||||
private readonly ILogger<QBittorrentController> _logger;
|
||||
private readonly QBittorrent _qBittorrent;
|
||||
|
||||
public QBittorrentController(QBittorrent qBittorrent)
|
||||
public QBittorrentController(ILogger<QBittorrentController> logger, QBittorrent qBittorrent)
|
||||
{
|
||||
_logger = logger;
|
||||
_qBittorrent = qBittorrent;
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +28,8 @@ public class QBittorrentController : Controller
|
|||
[HttpGet]
|
||||
public async Task<ActionResult> 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<ActionResult> 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)
|
||||
|
|
|
|||
|
|
@ -12,10 +12,12 @@ namespace RdtClient.Web.Controllers;
|
|||
public class TorrentsController : Controller
|
||||
{
|
||||
private readonly TorrentRunner _torrentRunner;
|
||||
private readonly ILogger<TorrentsController> _logger;
|
||||
private readonly Torrents _torrents;
|
||||
|
||||
public TorrentsController(Torrents torrents, TorrentRunner torrentRunner)
|
||||
public TorrentsController(ILogger<TorrentsController> 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<ActionResult> 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<ActionResult> RetryDownload(Guid downloadId)
|
||||
{
|
||||
_logger.LogDebug($"Retry download {downloadId}");
|
||||
|
||||
await _torrents.RetryDownload(downloadId);
|
||||
|
||||
return Ok();
|
||||
|
|
|
|||
Loading…
Reference in a new issue