Rename ProxyService to ProxyRequestService

This commit is contained in:
pcjones
2024-04-14 23:22:40 +02:00
parent 881f3b7281
commit 49193ef12f
5 changed files with 16 additions and 16 deletions

View File

@@ -6,9 +6,9 @@ using UmlautAdaptarr.Utilities;
namespace UmlautAdaptarr.Controllers namespace UmlautAdaptarr.Controllers
{ {
public class CapsController(ProxyService proxyService) : ControllerBase public class CapsController(ProxyRequestService proxyRequestService) : ControllerBase
{ {
private readonly ProxyService _proxyService = proxyService; private readonly ProxyRequestService _proxyRequestService = proxyRequestService;
[HttpGet] [HttpGet]
public async Task<IActionResult> Caps([FromRoute] string options, [FromRoute] string domain, [FromQuery] string? apikey) public async Task<IActionResult> Caps([FromRoute] string options, [FromRoute] string domain, [FromQuery] string? apikey)
@@ -20,7 +20,7 @@ namespace UmlautAdaptarr.Controllers
var requestUrl = UrlUtilities.BuildUrl(domain, "caps", apikey); var requestUrl = UrlUtilities.BuildUrl(domain, "caps", apikey);
var responseMessage = await _proxyService.ProxyRequestAsync(HttpContext, requestUrl); var responseMessage = await _proxyRequestService.ProxyRequestAsync(HttpContext, requestUrl);
var content = await responseMessage.Content.ReadAsStringAsync(); var content = await responseMessage.Content.ReadAsStringAsync();
var encoding = responseMessage.Content.Headers.ContentType?.CharSet != null ? var encoding = responseMessage.Content.Headers.ContentType?.CharSet != null ?

View File

@@ -6,7 +6,7 @@ using UmlautAdaptarr.Utilities;
namespace UmlautAdaptarr.Controllers namespace UmlautAdaptarr.Controllers
{ {
public abstract class SearchControllerBase(ProxyService proxyService, TitleMatchingService titleMatchingService) : ControllerBase public abstract class SearchControllerBase(ProxyRequestService proxyRequestService, TitleMatchingService titleMatchingService) : ControllerBase
{ {
// TODO evaluate if this should be set to true by default // TODO evaluate if this should be set to true by default
private readonly bool TODO_FORCE_TEXT_SEARCH_ORIGINAL_TITLE = true; private readonly bool TODO_FORCE_TEXT_SEARCH_ORIGINAL_TITLE = true;
@@ -96,7 +96,7 @@ namespace UmlautAdaptarr.Controllers
private async Task<IActionResult> PerformSingleSearchRequest(string domain, IDictionary<string, string> queryParameters) private async Task<IActionResult> PerformSingleSearchRequest(string domain, IDictionary<string, string> queryParameters)
{ {
var requestUrl = UrlUtilities.BuildUrl(domain, queryParameters); var requestUrl = UrlUtilities.BuildUrl(domain, queryParameters);
var responseMessage = await proxyService.ProxyRequestAsync(HttpContext, requestUrl); var responseMessage = await proxyRequestService.ProxyRequestAsync(HttpContext, requestUrl);
var content = await responseMessage.Content.ReadAsStringAsync(); var content = await responseMessage.Content.ReadAsStringAsync();
var encoding = responseMessage.Content.Headers.ContentType?.CharSet != null ? var encoding = responseMessage.Content.Headers.ContentType?.CharSet != null ?
@@ -130,7 +130,7 @@ namespace UmlautAdaptarr.Controllers
{ {
queryParameters["q"] = titleVariation; // Replace the "q" parameter for each variation queryParameters["q"] = titleVariation; // Replace the "q" parameter for each variation
var requestUrl = UrlUtilities.BuildUrl(domain, queryParameters); var requestUrl = UrlUtilities.BuildUrl(domain, queryParameters);
var responseMessage = await proxyService.ProxyRequestAsync(HttpContext, requestUrl); var responseMessage = await proxyRequestService.ProxyRequestAsync(HttpContext, requestUrl);
var content = await responseMessage.Content.ReadAsStringAsync(); var content = await responseMessage.Content.ReadAsStringAsync();
// Only update encoding from the first response // Only update encoding from the first response
@@ -152,9 +152,9 @@ namespace UmlautAdaptarr.Controllers
} }
} }
public class SearchController(ProxyService proxyService, public class SearchController(ProxyRequestService proxyRequestService,
TitleMatchingService titleMatchingService, TitleMatchingService titleMatchingService,
SearchItemLookupService searchItemLookupService) : SearchControllerBase(proxyService, titleMatchingService) SearchItemLookupService searchItemLookupService) : SearchControllerBase(proxyRequestService, titleMatchingService)
{ {
public readonly string[] LIDARR_CATEGORY_IDS = ["3000", "3010", "3020", "3040", "3050"]; public readonly string[] LIDARR_CATEGORY_IDS = ["3000", "3010", "3020", "3040", "3050"];
public readonly string[] READARR_CATEGORY_IDS = ["3030", "3130", "7000", "7010", "7020", "7030", "7100", "7110", "7120", "7130"]; public readonly string[] READARR_CATEGORY_IDS = ["3030", "3130", "7000", "7010", "7020", "7030", "7100", "7110", "7120", "7130"];

View File

@@ -56,7 +56,7 @@ internal class Program
builder.AddLidarrSupport(); builder.AddLidarrSupport();
builder.AddReadarrSupport(); builder.AddReadarrSupport();
builder.Services.AddSingleton<CacheService>(); builder.Services.AddSingleton<CacheService>();
builder.AddProxyService(); builder.AddProxyRequestService();
var app = builder.Build(); var app = builder.Build();

View File

@@ -6,17 +6,17 @@ using UmlautAdaptarr.Utilities;
namespace UmlautAdaptarr.Services namespace UmlautAdaptarr.Services
{ {
public class ProxyService public class ProxyRequestService
{ {
private readonly HttpClient _httpClient; private readonly HttpClient _httpClient;
private readonly string _userAgent; private readonly string _userAgent;
private readonly ILogger<ProxyService> _logger; private readonly ILogger<ProxyRequestService> _logger;
private readonly IMemoryCache _cache; private readonly IMemoryCache _cache;
private readonly GlobalOptions _options; private readonly GlobalOptions _options;
private static readonly ConcurrentDictionary<string, DateTimeOffset> _lastRequestTimes = new(); private static readonly ConcurrentDictionary<string, DateTimeOffset> _lastRequestTimes = new();
private static readonly TimeSpan MINIMUM_DELAY_FOR_SAME_HOST = new(0, 0, 0, 1); private static readonly TimeSpan MINIMUM_DELAY_FOR_SAME_HOST = new(0, 0, 0, 1);
public ProxyService(IHttpClientFactory clientFactory, ILogger<ProxyService> logger, IMemoryCache cache, IOptions<GlobalOptions> options) public ProxyRequestService(IHttpClientFactory clientFactory, ILogger<ProxyRequestService> logger, IMemoryCache cache, IOptions<GlobalOptions> options)
{ {
_options = options.Value; _options = options.Value;
_httpClient = clientFactory.CreateClient("HttpClient") ?? throw new ArgumentNullException(nameof(clientFactory)); _httpClient = clientFactory.CreateClient("HttpClient") ?? throw new ArgumentNullException(nameof(clientFactory));
@@ -76,7 +76,7 @@ namespace UmlautAdaptarr.Services
try try
{ {
_logger.LogInformation($"ProxyService GET {UrlUtilities.RedactApiKey(targetUri)}"); _logger.LogInformation($"ProxyRequestService GET {UrlUtilities.RedactApiKey(targetUri)}");
var responseMessage = await _httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted); var responseMessage = await _httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted);
if (responseMessage.IsSuccessStatusCode) if (responseMessage.IsSuccessStatusCode)

View File

@@ -80,13 +80,13 @@ namespace UmlautAdaptarr.Utilities
} }
/// <summary> /// <summary>
/// Adds a proxy service to the service collection. /// Adds a proxy request service to the service collection.
/// </summary> /// </summary>
/// <param name="builder">The <see cref="WebApplicationBuilder"/> to configure the service collection.</param> /// <param name="builder">The <see cref="WebApplicationBuilder"/> to configure the service collection.</param>
/// <returns>The configured <see cref="WebApplicationBuilder"/>.</returns> /// <returns>The configured <see cref="WebApplicationBuilder"/>.</returns>
public static WebApplicationBuilder AddProxyService(this WebApplicationBuilder builder) public static WebApplicationBuilder AddProxyRequestService(this WebApplicationBuilder builder)
{ {
return builder.AddServiceWithOptions<GlobalOptions, ProxyService>("Settings"); return builder.AddServiceWithOptions<GlobalOptions, ProxyRequestService>("Settings");
} }
} }
} }