2024-02-06 23:28:29 +01:00
|
|
|
using System.Net;
|
2024-04-27 18:48:43 +02:00
|
|
|
using Serilog;
|
|
|
|
|
using Serilog.Filters;
|
2024-02-06 23:28:29 +01:00
|
|
|
using UmlautAdaptarr.Routing;
|
|
|
|
|
using UmlautAdaptarr.Services;
|
2024-04-27 18:48:43 +02:00
|
|
|
using UmlautAdaptarr.Services.Factory;
|
2024-04-14 16:43:09 +02:00
|
|
|
using UmlautAdaptarr.Utilities;
|
2024-02-06 23:28:29 +01:00
|
|
|
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
2025-01-13 21:20:03 +01:00
|
|
|
private static void Main(string[] args)
|
|
|
|
|
{
|
2024-10-21 17:28:31 +02:00
|
|
|
MainAsync(args).Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task MainAsync(string[] args)
|
2024-02-06 23:28:29 +01:00
|
|
|
{
|
2024-02-07 04:50:55 +01:00
|
|
|
// TODO:
|
|
|
|
|
// add option to sort by nzb age
|
2024-04-27 18:48:43 +02:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
var configuration = builder.Configuration;
|
2024-09-30 14:03:18 +02:00
|
|
|
ConfigureLogger(configuration);
|
2024-04-27 18:48:43 +02:00
|
|
|
|
|
|
|
|
builder.Services.AddSerilog();
|
2024-02-07 04:50:55 +01:00
|
|
|
|
2024-02-06 23:28:29 +01:00
|
|
|
// Add services to the container.
|
|
|
|
|
builder.Services.AddHttpClient("HttpClient").ConfigurePrimaryHttpMessageHandler(() =>
|
|
|
|
|
{
|
|
|
|
|
var handler = new HttpClientHandler
|
|
|
|
|
{
|
2024-04-27 18:48:43 +02:00
|
|
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate |
|
|
|
|
|
DecompressionMethods.Brotli
|
2024-02-06 23:28:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return handler;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
builder.Services.AddMemoryCache(options =>
|
|
|
|
|
{
|
2024-04-14 22:29:10 +02:00
|
|
|
// TODO cache size limit? option?
|
2024-02-12 01:57:41 +01:00
|
|
|
//options.SizeLimit = 20000;
|
2024-02-12 02:31:36 +01:00
|
|
|
});
|
|
|
|
|
|
2024-04-28 12:59:44 +02:00
|
|
|
builder.Services.AllowResolvingKeyedServicesAsDictionary();
|
2024-02-06 23:28:29 +01:00
|
|
|
builder.Services.AddControllers();
|
2024-04-14 16:43:09 +02:00
|
|
|
builder.AddTitleLookupService();
|
2024-02-12 01:57:41 +01:00
|
|
|
builder.Services.AddSingleton<SearchItemLookupService>();
|
|
|
|
|
builder.Services.AddSingleton<TitleMatchingService>();
|
2024-10-21 17:28:31 +02:00
|
|
|
await builder.AddSonarrSupport();
|
|
|
|
|
await builder.AddLidarrSupport();
|
|
|
|
|
await builder.AddReadarrSupport();
|
2024-02-12 01:57:41 +01:00
|
|
|
builder.Services.AddSingleton<CacheService>();
|
2024-04-15 00:48:27 +02:00
|
|
|
builder.Services.AddSingleton<ProxyRequestService>();
|
2024-04-28 12:59:44 +02:00
|
|
|
builder.Services.AddSingleton<ArrApplicationFactory>();
|
2024-04-27 18:48:43 +02:00
|
|
|
builder.Services.AddHostedService<ArrSyncBackgroundService>();
|
2024-04-15 00:48:27 +02:00
|
|
|
builder.Services.AddSingleton<IHostedService, HttpProxyService>();
|
2024-02-06 23:28:29 +01:00
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
2024-10-21 17:28:31 +02:00
|
|
|
Helper.ShowLogo();
|
|
|
|
|
|
|
|
|
|
if (app.Configuration.GetValue<bool>("IpLeakTest:Enabled"))
|
|
|
|
|
{
|
|
|
|
|
await Helper.ShowInformation();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-14 16:43:09 +02:00
|
|
|
GlobalStaticLogger.Initialize(app.Services.GetService<ILoggerFactory>()!);
|
2024-02-06 23:28:29 +01:00
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
2024-04-27 18:48:43 +02:00
|
|
|
app.MapControllerRoute("caps",
|
2025-01-13 21:20:03 +01:00
|
|
|
"{apiKey}/{*domain}",
|
2024-04-27 18:48:43 +02:00
|
|
|
new { controller = "Caps", action = "Caps" },
|
|
|
|
|
new { t = new TRouteConstraint("caps") });
|
|
|
|
|
|
|
|
|
|
app.MapControllerRoute("movie-search",
|
2025-01-13 21:20:03 +01:00
|
|
|
"{apiKey}/{*domain}",
|
2024-04-27 18:48:43 +02:00
|
|
|
new { controller = "Search", action = "MovieSearch" },
|
|
|
|
|
new { t = new TRouteConstraint("movie") });
|
|
|
|
|
|
|
|
|
|
app.MapControllerRoute("tv-search",
|
2025-01-13 21:20:03 +01:00
|
|
|
"{apiKey}/{*domain}",
|
2024-04-27 18:48:43 +02:00
|
|
|
new { controller = "Search", action = "TVSearch" },
|
|
|
|
|
new { t = new TRouteConstraint("tvsearch") });
|
|
|
|
|
|
|
|
|
|
app.MapControllerRoute("music-search",
|
2025-01-13 21:20:03 +01:00
|
|
|
"{apiKey}/{*domain}",
|
2024-04-27 18:48:43 +02:00
|
|
|
new { controller = "Search", action = "MusicSearch" },
|
|
|
|
|
new { t = new TRouteConstraint("music") });
|
|
|
|
|
|
|
|
|
|
app.MapControllerRoute("book-search",
|
2025-01-13 21:20:03 +01:00
|
|
|
"{apiKey}/{*domain}",
|
2024-04-27 18:48:43 +02:00
|
|
|
new { controller = "Search", action = "BookSearch" },
|
|
|
|
|
new { t = new TRouteConstraint("book") });
|
|
|
|
|
|
|
|
|
|
app.MapControllerRoute("generic-search",
|
2025-01-13 21:20:03 +01:00
|
|
|
"{apiKey}/{*domain}",
|
2024-04-27 18:48:43 +02:00
|
|
|
new { controller = "Search", action = "GenericSearch" },
|
|
|
|
|
new { t = new TRouteConstraint("search") });
|
2024-02-06 23:28:29 +01:00
|
|
|
app.Run();
|
|
|
|
|
}
|
2024-09-30 14:03:18 +02:00
|
|
|
|
|
|
|
|
private static void ConfigureLogger(ConfigurationManager configuration)
|
|
|
|
|
{
|
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
|
|
.ReadFrom.Configuration(configuration)
|
|
|
|
|
.WriteTo.Console(outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
|
|
|
|
|
|
|
|
|
|
#if RELEASE
|
|
|
|
|
.Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore.Mvc"))
|
|
|
|
|
.Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore.Routing"))
|
|
|
|
|
.Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore.Diagnostics"))
|
|
|
|
|
.Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore.Hosting"))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// TODO workaround to not log api keys
|
|
|
|
|
.Filter.ByExcluding(Matching.FromSource("System.Net.Http.HttpClient"))
|
|
|
|
|
.Filter.ByExcluding(Matching.FromSource("Microsoft.Extensions.Http.DefaultHttpClientFactory"))
|
|
|
|
|
//.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently
|
|
|
|
|
.CreateLogger();
|
|
|
|
|
}
|
2024-10-21 17:28:31 +02:00
|
|
|
}
|