diff --git a/UmlautAdaptarr/Controllers/CapsController.cs b/UmlautAdaptarr/Controllers/CapsController.cs index 9dc8fc3..e8df172 100644 --- a/UmlautAdaptarr/Controllers/CapsController.cs +++ b/UmlautAdaptarr/Controllers/CapsController.cs @@ -13,7 +13,7 @@ namespace UmlautAdaptarr.Controllers [HttpGet] public async Task Caps([FromRoute] string options, [FromRoute] string domain, [FromQuery] string? apikey) { - if (!UrlUtilities.IsValidDomain(domain)) + if (!domain.StartsWith("localhost") && !UrlUtilities.IsValidDomain(domain)) { return NotFound($"{domain} is not a valid URL."); } diff --git a/UmlautAdaptarr/Controllers/SearchController.cs b/UmlautAdaptarr/Controllers/SearchController.cs index 63f2f03..9961616 100644 --- a/UmlautAdaptarr/Controllers/SearchController.cs +++ b/UmlautAdaptarr/Controllers/SearchController.cs @@ -1,12 +1,13 @@ using Microsoft.AspNetCore.Mvc; using System.Text; using UmlautAdaptarr.Models; +using UmlautAdaptarr.Providers; using UmlautAdaptarr.Services; using UmlautAdaptarr.Utilities; namespace UmlautAdaptarr.Controllers { - public abstract class SearchControllerBase(ProxyRequestService proxyRequestService, TitleMatchingService titleMatchingService) : ControllerBase + public abstract class SearchControllerBase(ProxyRequestService proxyRequestService, TitleMatchingService titleMatchingService, ILogger logger) : ControllerBase { // TODO evaluate if this should be set to true by default private readonly bool TODO_FORCE_TEXT_SEARCH_ORIGINAL_TITLE = true; @@ -110,7 +111,15 @@ namespace UmlautAdaptarr.Controllers private string ProcessContent(string content, SearchItem? searchItem) { - return titleMatchingService.RenameTitlesInContent(content, searchItem); + try + { + return titleMatchingService.RenameTitlesInContent(content, searchItem); + } + catch (Exception ex) + { + logger.LogError($"Error at ProcessContent: {ex.Message}{Environment.NewLine}Content:{Environment.NewLine}{content}"); + } + return null; } public async Task AggregateSearchResults( @@ -154,7 +163,8 @@ namespace UmlautAdaptarr.Controllers public class SearchController(ProxyRequestService proxyRequestService, TitleMatchingService titleMatchingService, - SearchItemLookupService searchItemLookupService) : SearchControllerBase(proxyRequestService, titleMatchingService) + SearchItemLookupService searchItemLookupService, + ILogger logger) : SearchControllerBase(proxyRequestService, titleMatchingService, logger) { 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"]; diff --git a/UmlautAdaptarr/Services/Factory/ArrApplicationFactory.cs b/UmlautAdaptarr/Services/Factory/ArrApplicationFactory.cs index 98f2b5c..dda33b9 100644 --- a/UmlautAdaptarr/Services/Factory/ArrApplicationFactory.cs +++ b/UmlautAdaptarr/Services/Factory/ArrApplicationFactory.cs @@ -52,7 +52,7 @@ namespace UmlautAdaptarr.Services.Factory } catch (Exception e) { - _logger.LogError("Error while Register ArrFactory. This might be a Config Problem", e.Message); + _logger.LogError("Error while registering ArrFactory. This is most likely a config problem, please check your environment variables.", e.Message); throw; } } diff --git a/UmlautAdaptarr/Utilities/UrlUtilities.cs b/UmlautAdaptarr/Utilities/UrlUtilities.cs index 2d016ae..dd81425 100644 --- a/UmlautAdaptarr/Utilities/UrlUtilities.cs +++ b/UmlautAdaptarr/Utilities/UrlUtilities.cs @@ -5,7 +5,8 @@ namespace UmlautAdaptarr.Utilities { public partial class UrlUtilities { - [GeneratedRegex(@"^(?!http:\/\/)([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+.*)$")] + [GeneratedRegex(@"^(?!http:\/\/)([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+(:\d+)?(/.*)?)$")] + private static partial Regex UrlMatchingRegex(); public static bool IsValidDomain(string domain) { diff --git a/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs b/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs index de6d087..e4c90a8 100644 --- a/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs +++ b/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs @@ -35,34 +35,38 @@ public class GlobalInstanceOptionsValidator : AbstractValidator BeReachable(GlobalInstanceOptions opts, CancellationToken cancellationToken) - { - var endTime = DateTime.Now.AddMinutes(3); - var reachable = false; - var url = $"{opts.Host}/api?apikey={opts.ApiKey}"; + private static async Task BeReachable(GlobalInstanceOptions opts, CancellationToken cancellationToken) + { + var endTime = DateTime.Now.AddMinutes(3); + var reachable = false; + var url = $"{opts.Host}/api?apikey={opts.ApiKey}"; - while (DateTime.Now < endTime) - { - try - { - using var response = await httpClient.GetAsync(url, cancellationToken); - reachable = response.StatusCode == HttpStatusCode.OK; - if (response.IsSuccessStatusCode) - { - break; - } - } - catch - { + while (DateTime.Now < endTime) + { + try + { + using var response = await httpClient.GetAsync(url, cancellationToken); + if (response.IsSuccessStatusCode) + { + reachable = true; + break; + } + else + { + Console.WriteLine($"Reachable check got unexpected status code {response.StatusCode}."); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } - } + // Wait for 15 seconds for next try + Console.WriteLine($"The URL \"{opts.Host}/api?apikey=[REDACTED]\" is not reachable. Next attempt in 15 seconds..."); + Thread.Sleep(15000); + } - // Wait for 15 seconds for next try - Console.WriteLine($"The URL \"{opts.Host}\" is not reachable. Next attempt in 15 seconds..."); - Thread.Sleep(15000); - } - - return reachable; - } + return reachable; + } } \ No newline at end of file diff --git a/UmlautAdaptarr/appsettings.json b/UmlautAdaptarr/appsettings.json index c1874b8..9a94818 100644 --- a/UmlautAdaptarr/appsettings.json +++ b/UmlautAdaptarr/appsettings.json @@ -67,7 +67,7 @@ }, "IpLeakTest": { // Docker Environment Variables: - // - IpLeakTest: false (set to true to enable) + // - IpLeakTest__Enabled: false (set to true to enable) "Enabled": false } } diff --git a/docker-compose.yml b/docker-compose.yml index 52252cd..586a1b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,7 +23,7 @@ services: - LIDARR__ENABLED=false - LIDARR__HOST=http://localhost:8686 - LIDARR__APIKEY=APIKEY - #- IpLeakTest=false # uncomment and set to true to enable IP leak test + #- IpLeakTest__Enabled=false # uncomment and set to true to enable IP leak test ### example for multiple instances of same type #- SONARR__0__NAME=NAME 1 (optional) #- SONARR__0__ENABLED=false