Fix warnings
This commit is contained in:
@@ -23,7 +23,7 @@ namespace UmlautAdaptarr.Controllers
|
|||||||
return NotFound($"{domain} is not a valid URL.");
|
return NotFound($"{domain} is not a valid URL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var initialSearchResult = await PerformSingleSearchRequest(domain, queryParameters) as ContentResult;
|
ContentResult? initialSearchResult = await PerformSingleSearchRequest(domain, queryParameters) as ContentResult;
|
||||||
if (initialSearchResult == null)
|
if (initialSearchResult == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -5,29 +5,29 @@ namespace UmlautAdaptarr.Utilities;
|
|||||||
public class IpInfo
|
public class IpInfo
|
||||||
{
|
{
|
||||||
[JsonPropertyName("ip")]
|
[JsonPropertyName("ip")]
|
||||||
public string Ip { get; set; }
|
public string? Ip { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("hostname")]
|
[JsonPropertyName("hostname")]
|
||||||
public string Hostname { get; set; }
|
public string? Hostname { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("city")]
|
[JsonPropertyName("city")]
|
||||||
public string City { get; set; }
|
public string? City { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("region")]
|
[JsonPropertyName("region")]
|
||||||
public string Region { get; set; }
|
public string? Region { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("country")]
|
[JsonPropertyName("country")]
|
||||||
public string Country { get; set; }
|
public string? Country { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("loc")]
|
[JsonPropertyName("loc")]
|
||||||
public string Loc { get; set; }
|
public string? Loc { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("org")]
|
[JsonPropertyName("org")]
|
||||||
public string Org { get; set; }
|
public string? Org { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("postal")]
|
[JsonPropertyName("postal")]
|
||||||
public string Postal { get; set; }
|
public string? Postal { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("timezone")]
|
[JsonPropertyName("timezone")]
|
||||||
public string Timezone { get; set; }
|
public string? Timezone { get; set; }
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ namespace UmlautAdaptarr.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GenerateVariations(string? title, string mediaType)
|
private static IEnumerable<string> GenerateVariations(string? title, string mediaType)
|
||||||
{
|
{
|
||||||
if (title == null)
|
if (title == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ namespace UmlautAdaptarr.Providers;
|
|||||||
|
|
||||||
public abstract class ArrClientBase : IArrApplication
|
public abstract class ArrClientBase : IArrApplication
|
||||||
{
|
{
|
||||||
|
#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable.
|
||||||
public string InstanceName;
|
public string InstanceName;
|
||||||
|
#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable.
|
||||||
public abstract Task<IEnumerable<SearchItem>> FetchAllItemsAsync();
|
public abstract Task<IEnumerable<SearchItem>> FetchAllItemsAsync();
|
||||||
public abstract Task<SearchItem?> FetchItemByExternalIdAsync(string externalId);
|
public abstract Task<SearchItem?> FetchItemByExternalIdAsync(string externalId);
|
||||||
public abstract Task<SearchItem?> FetchItemByTitleAsync(string title);
|
public abstract Task<SearchItem?> FetchItemByTitleAsync(string title);
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace UmlautAdaptarr.Services
|
|||||||
private readonly int _proxyPort = 5006; // TODO move to appsettings.json
|
private readonly int _proxyPort = 5006; // TODO move to appsettings.json
|
||||||
private readonly IHttpClientFactory _clientFactory;
|
private readonly IHttpClientFactory _clientFactory;
|
||||||
private readonly HashSet<string> _knownHosts = [];
|
private readonly HashSet<string> _knownHosts = [];
|
||||||
private readonly object _hostsLock = new object();
|
private readonly object _hostsLock = new();
|
||||||
|
private static readonly string[] newLineSeparator = ["\r\n"];
|
||||||
|
|
||||||
public HttpProxyService(ILogger<HttpProxyService> logger, IHttpClientFactory clientFactory)
|
public HttpProxyService(ILogger<HttpProxyService> logger, IHttpClientFactory clientFactory)
|
||||||
{
|
{
|
||||||
@@ -123,7 +123,7 @@ namespace UmlautAdaptarr.Services
|
|||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
var headerString = Encoding.ASCII.GetString(buffer, 0, length);
|
var headerString = Encoding.ASCII.GetString(buffer, 0, length);
|
||||||
var lines = headerString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
var lines = headerString.Split(newLineSeparator, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (var line in lines.Skip(1)) // Skip the request line
|
foreach (var line in lines.Skip(1)) // Skip the request line
|
||||||
{
|
{
|
||||||
var colonIndex = line.IndexOf(':');
|
var colonIndex = line.IndexOf(':');
|
||||||
@@ -137,7 +137,7 @@ namespace UmlautAdaptarr.Services
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private (string host, int port) ParseTargetInfo(string requestLine)
|
private static (string host, int port) ParseTargetInfo(string requestLine)
|
||||||
{
|
{
|
||||||
var parts = requestLine.Split(' ')[1].Split(':');
|
var parts = requestLine.Split(' ')[1].Split(':');
|
||||||
return (parts[0], int.Parse(parts[1]));
|
return (parts[0], int.Parse(parts[1]));
|
||||||
@@ -150,7 +150,7 @@ namespace UmlautAdaptarr.Services
|
|||||||
await Task.WhenAll(clientToTargetTask, targetToClientTask);
|
await Task.WhenAll(clientToTargetTask, targetToClientTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RelayStream(NetworkStream input, NetworkStream output)
|
private static async Task RelayStream(NetworkStream input, NetworkStream output)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ namespace UmlautAdaptarr.Services
|
|||||||
public void FindAndReplaceForBooksAndAudio(SearchItem searchItem, XElement? titleElement, string originalTitle)
|
public void FindAndReplaceForBooksAndAudio(SearchItem searchItem, XElement? titleElement, string originalTitle)
|
||||||
{
|
{
|
||||||
var authorMatch = FindBestMatch(searchItem.AuthorMatchVariations, originalTitle.NormalizeForComparison(), originalTitle);
|
var authorMatch = FindBestMatch(searchItem.AuthorMatchVariations, originalTitle.NormalizeForComparison(), originalTitle);
|
||||||
var titleMatch = FindBestMatch(searchItem.TitleMatchVariations, originalTitle.NormalizeForComparison(), originalTitle);
|
var (foundMatch, bestStart, bestEndInOriginal) = FindBestMatch(searchItem.TitleMatchVariations, originalTitle.NormalizeForComparison(), originalTitle);
|
||||||
|
|
||||||
if (authorMatch.foundMatch && titleMatch.foundMatch)
|
if (authorMatch.foundMatch && foundMatch)
|
||||||
{
|
{
|
||||||
int matchEndPositionInOriginal = Math.Max(authorMatch.bestEndInOriginal, titleMatch.bestEndInOriginal);
|
int matchEndPositionInOriginal = Math.Max(authorMatch.bestEndInOriginal, bestEndInOriginal);
|
||||||
|
|
||||||
// Check and adjust for immediate following delimiter
|
// Check and adjust for immediate following delimiter
|
||||||
char[] delimiters = [' ', '-', '_', '.'];
|
char[] delimiters = [' ', '-', '_', '.'];
|
||||||
@@ -103,7 +103,7 @@ namespace UmlautAdaptarr.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private (bool foundMatch, int bestStart, int bestEndInOriginal) FindBestMatch(string[] variations, string normalizedOriginal, string originalTitle)
|
private static (bool foundMatch, int bestStart, int bestEndInOriginal) FindBestMatch(string[] variations, string normalizedOriginal, string originalTitle)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
int bestStart = int.MaxValue;
|
int bestStart = int.MaxValue;
|
||||||
@@ -131,7 +131,7 @@ namespace UmlautAdaptarr.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maps an index from the normalized string back to a corresponding index in the original string
|
// Maps an index from the normalized string back to a corresponding index in the original string
|
||||||
private int MapNormalizedIndexToOriginal(string normalizedOriginal, string originalTitle, int normalizedIndex)
|
private static int MapNormalizedIndexToOriginal(string normalizedOriginal, string originalTitle, int normalizedIndex)
|
||||||
{
|
{
|
||||||
// Count non-special characters up to the given index in the normalized string
|
// Count non-special characters up to the given index in the normalized string
|
||||||
int nonSpecialCharCount = 0;
|
int nonSpecialCharCount = 0;
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ public static class Helper
|
|||||||
|
|
||||||
private static async Task<IpInfo?> GetPublicIpAddressInfoAsync()
|
private static async Task<IpInfo?> GetPublicIpAddressInfoAsync()
|
||||||
{
|
{
|
||||||
using (var client = new HttpClient())
|
using var client = new HttpClient();
|
||||||
{
|
|
||||||
client.Timeout = TimeSpan.FromSeconds(10);
|
client.Timeout = TimeSpan.FromSeconds(10);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -54,5 +53,4 @@ public static class Helper
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,17 +35,15 @@ public static class ServicesExtensions
|
|||||||
where TService : class, TInterface
|
where TService : class, TInterface
|
||||||
where TInterface : class
|
where TInterface : class
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (builder.Services == null) throw new ArgumentNullException(nameof(builder), "Service collection is null.");
|
if (builder.Services == null) throw new ArgumentNullException(nameof(builder), "Service collection is null.");
|
||||||
|
|
||||||
|
|
||||||
var singleInstance = builder.Configuration.GetSection(sectionName).Get<TOptions>();
|
var singleInstance = builder.Configuration.GetSection(sectionName).Get<TOptions>();
|
||||||
|
|
||||||
var singleHost = (string?)typeof(TOptions).GetProperty("Host")?.GetValue(singleInstance, null);
|
var singleHost = (string?)typeof(TOptions).GetProperty("Host")?.GetValue(singleInstance, null);
|
||||||
|
|
||||||
// If we have no Single Instance , we try to parse for a Array
|
// If we have no Single Instance, we try to parse for an Array
|
||||||
var optionsArray = singleHost == null
|
var optionsArray = singleHost == null
|
||||||
? builder.Configuration.GetSection(sectionName).Get<TOptions[]>()
|
? builder.Configuration.GetSection(sectionName).Get<TOptions[]>()
|
||||||
:
|
:
|
||||||
@@ -59,7 +57,6 @@ public static class ServicesExtensions
|
|||||||
|
|
||||||
foreach (var option in optionsArray)
|
foreach (var option in optionsArray)
|
||||||
{
|
{
|
||||||
|
|
||||||
GlobalInstanceOptionsValidator validator = new GlobalInstanceOptionsValidator();
|
GlobalInstanceOptionsValidator validator = new GlobalInstanceOptionsValidator();
|
||||||
|
|
||||||
var results = validator.Validate(option as GlobalInstanceOptions);
|
var results = validator.Validate(option as GlobalInstanceOptions);
|
||||||
@@ -100,7 +97,7 @@ public static class ServicesExtensions
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogWarning((prop.PropertyType + "No Support"));
|
Logger.LogWarning(prop.PropertyType + "No Support");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,9 +107,9 @@ public static class ServicesExtensions
|
|||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error while Init UmlautAdaptrr");
|
Console.WriteLine($"Error in AddServicesWithOptions: {ex.Message}");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,11 +130,8 @@ public static class ServicesExtensions
|
|||||||
{
|
{
|
||||||
if (builder.Services == null) throw new ArgumentNullException(nameof(builder), "Service collection is null.");
|
if (builder.Services == null) throw new ArgumentNullException(nameof(builder), "Service collection is null.");
|
||||||
|
|
||||||
var options = builder.Configuration.GetSection(sectionName).Get<TOptions>();
|
var options = builder.Configuration.GetSection(sectionName).Get<TOptions>() ?? throw new InvalidOperationException(
|
||||||
if (options == null)
|
|
||||||
throw new InvalidOperationException(
|
|
||||||
$"{typeof(TService).Name} options could not be loaded from Configuration or ENV Variable.");
|
$"{typeof(TService).Name} options could not be loaded from Configuration or ENV Variable.");
|
||||||
|
|
||||||
builder.Services.Configure<TOptions>(builder.Configuration.GetSection(sectionName));
|
builder.Services.Configure<TOptions>(builder.Configuration.GetSection(sectionName));
|
||||||
builder.Services.AddSingleton<TService>();
|
builder.Services.AddSingleton<TService>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user