Refactor of http client and addition of sonarr anime table
This commit is contained in:
@@ -4,11 +4,10 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Jellyfin.Plugin.MediaCleaner.Enums;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Linq;
|
||||
|
||||
@@ -24,25 +23,10 @@ public record RadarrMovie(
|
||||
[Route("radarr")]
|
||||
public class RadarrController : Controller
|
||||
{
|
||||
private static Configuration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public RadarrController(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
|
||||
// Set the default request headers
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", Configuration.RadarrAPIKey);
|
||||
}
|
||||
|
||||
private async Task<ObjectResult> GetRadarrMovieInfo(MovieInfo movieInfo)
|
||||
{
|
||||
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||
_httpClient,
|
||||
Configuration.RadarrAddress,
|
||||
HttpHelper httpHelper = new(ServerType.Radarr);
|
||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||
HttpMethod.Get,
|
||||
$"/api/v3/movie?tmdbId={Uri.EscapeDataString(movieInfo.TmdbId ?? string.Empty)}&excludeLocalCovers=false"
|
||||
).ConfigureAwait(false);
|
||||
@@ -76,9 +60,8 @@ public class RadarrController : Controller
|
||||
|
||||
RadarrMovie movie = (RadarrMovie)radarrMovieInfoResult.Value;
|
||||
|
||||
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||
_httpClient,
|
||||
Configuration.RadarrAddress,
|
||||
HttpHelper httpHelper = new(ServerType.Radarr);
|
||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||
HttpMethod.Delete,
|
||||
$"/api/v3/movie/{movie.Id}?deleteFiles=true&addImportExclusion=true"
|
||||
).ConfigureAwait(false);
|
||||
@@ -109,10 +92,11 @@ public class RadarrController : Controller
|
||||
|
||||
try
|
||||
{
|
||||
using var testHttpClient = new HttpClient();
|
||||
using var httpRequest = new HttpRequestMessage(HttpMethod.Get, address);
|
||||
httpRequest.Headers.Add("X-Api-Key", request.ApiKey);
|
||||
|
||||
var response = await _httpClient.SendAsync(httpRequest).ConfigureAwait(false);
|
||||
var response = await testHttpClient.SendAsync(httpRequest).ConfigureAwait(false);
|
||||
return Ok(new { success = response.IsSuccessStatusCode });
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
|
||||
Reference in New Issue
Block a user