Refactor of http client and addition of sonarr anime table

This commit is contained in:
2026-03-08 19:28:04 -06:00
parent 8f049e6704
commit 21a9cc86d8
10 changed files with 206 additions and 54 deletions

View File

@@ -11,7 +11,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;
using Jellyfin.Plugin.MediaCleaner.Enums;
using Jellyfin.Plugin.MediaCleaner.Helpers;
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
@@ -37,9 +37,6 @@ public record Season(
[Route("sonarr")]
public class SonarrController : Controller
{
private static Configuration Configuration =>
Plugin.Instance!.Configuration;
private readonly HttpClient _httpClient;
public SonarrController(HttpClient httpClient)
@@ -48,13 +45,11 @@ public class SonarrController : Controller
// Set the default request headers
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", Configuration.SonarrAPIKey);
}
private async Task<ObjectResult> GetSonarrSeriesInfo(SeriesInfo seriesInfo){
var responseBody = await HttpHelper.SendHttpRequestAsync(
_httpClient,
Configuration.SonarrAddress,
HttpHelper httpHelper = new(ServerType.Sonarr);
var responseBody = await httpHelper.SendHttpRequestAsync(
HttpMethod.Get,
$"/api/v3/series?tvdbId={Uri.EscapeDataString(seriesInfo.TvdbId ?? string.Empty)}"
).ConfigureAwait(false);
@@ -71,9 +66,8 @@ public class SonarrController : Controller
}
private async Task<ObjectResult> GetSonarrEpisodeInfo(SonarrSeries sonarrSeries){
var responseBody = await HttpHelper.SendHttpRequestAsync(
_httpClient,
Configuration.SonarrAddress,
HttpHelper httpHelper = new(ServerType.Sonarr);
var responseBody = await httpHelper.SendHttpRequestAsync(
HttpMethod.Get,
$"/api/v3/episode?seriesId={sonarrSeries.Id?.ToString(CultureInfo.InvariantCulture)}"
).ConfigureAwait(false);
@@ -109,7 +103,7 @@ public class SonarrController : Controller
}
[HttpPost("deleteSeriesFromSonarr")]
public async Task<IActionResult> DeleteSeriesFromRadarr([FromBody] SeriesInfo seriesInfo){
public async Task<IActionResult> DeleteSeriesFromSonarr([FromBody] SeriesInfo seriesInfo){
if (seriesInfo == null || string.IsNullOrEmpty(seriesInfo.TvdbId))
{
@@ -157,9 +151,8 @@ public class SonarrController : Controller
return BadRequest("No stale series provided.");
}
var series = await HttpHelper.SendHttpRequestAsync(
_httpClient,
Configuration.SonarrAddress,
HttpHelper httpHelper = new(ServerType.Sonarr);
var series = await httpHelper.SendHttpRequestAsync(
HttpMethod.Get,
$"/api/v3/series/{staleSeries.Id}"
).ConfigureAwait(false);
@@ -195,9 +188,7 @@ public class SonarrController : Controller
seriesDict["seasons"] = updatedSeasons;
var responseBody = await HttpHelper.SendHttpRequestAsync(
_httpClient,
Configuration.SonarrAddress,
var responseBody = await httpHelper.SendHttpRequestAsync(
HttpMethod.Put,
$"/api/v3/series/{staleSeries.Id}",
seriesDict
@@ -213,9 +204,8 @@ public class SonarrController : Controller
return BadRequest("No episode file IDs provided.");
}
var responseBody = await HttpHelper.SendHttpRequestAsync(
_httpClient,
Configuration.SonarrAddress,
HttpHelper httpHelper = new(ServerType.Sonarr);
var responseBody = await httpHelper.SendHttpRequestAsync(
HttpMethod.Delete,
"/api/v3/episodefile/bulk",
new { episodeFileIds }
@@ -231,9 +221,9 @@ public class SonarrController : Controller
return BadRequest("No episode IDs provided.");
}
var responseBody = await HttpHelper.SendHttpRequestAsync(
_httpClient,
Configuration.SonarrAddress,
HttpHelper httpHelper = new(ServerType.Sonarr);
var responseBody = await httpHelper.SendHttpRequestAsync(
HttpMethod.Put,
"/api/v3/episode/monitor",
new { episodeIds, monitored = false }