Files
UmlautAdaptarr/UmlautAdaptarr/Program.cs

123 lines
4.5 KiB
C#
Raw Permalink Normal View History

2024-02-06 23:28:29 +01:00
using System.Net;
using Serilog;
using Serilog.Filters;
2024-02-06 23:28:29 +01:00
using UmlautAdaptarr.Routing;
using UmlautAdaptarr.Services;
using UmlautAdaptarr.Services.Factory;
using UmlautAdaptarr.Utilities;
2024-02-06 23:28:29 +01:00
internal class Program
{
private static void Main(string[] args)
{
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
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
2024-09-30 14:03:18 +02:00
ConfigureLogger(configuration);
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
{
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();
builder.AddTitleLookupService();
2024-02-12 01:57:41 +01:00
builder.Services.AddSingleton<SearchItemLookupService>();
builder.Services.AddSingleton<TitleMatchingService>();
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>();
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();
Helper.ShowLogo();
if (app.Configuration.GetValue<bool>("IpLeakTest:Enabled"))
{
await Helper.ShowInformation();
}
GlobalStaticLogger.Initialize(app.Services.GetService<ILoggerFactory>()!);
2024-02-06 23:28:29 +01:00
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllerRoute("caps",
"{apiKey}/{*domain}",
new { controller = "Caps", action = "Caps" },
new { t = new TRouteConstraint("caps") });
app.MapControllerRoute("movie-search",
"{apiKey}/{*domain}",
new { controller = "Search", action = "MovieSearch" },
new { t = new TRouteConstraint("movie") });
app.MapControllerRoute("tv-search",
"{apiKey}/{*domain}",
new { controller = "Search", action = "TVSearch" },
new { t = new TRouteConstraint("tvsearch") });
app.MapControllerRoute("music-search",
"{apiKey}/{*domain}",
new { controller = "Search", action = "MusicSearch" },
new { t = new TRouteConstraint("music") });
app.MapControllerRoute("book-search",
"{apiKey}/{*domain}",
new { controller = "Search", action = "BookSearch" },
new { t = new TRouteConstraint("book") });
app.MapControllerRoute("generic-search",
"{apiKey}/{*domain}",
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();
}
}