From f30ff573282b696e8c33e95696bf59594dab0b12 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Mon, 27 May 2024 01:23:22 +0300 Subject: [PATCH] Vogen broke for some reason on ARM64 --- .../Jobs/NexusModsModFileProcessorJob.cs | 5 +++-- .../NexusModsModFileUpdatesProcessorJob.cs | 2 +- .../Options/NexusModsOptions.cs | 7 +++++-- .../Options/NexusModsUsersOptions.cs | 4 +++- src/BUTR.Site.NexusMods.Server/Program.cs | 2 +- src/BUTR.Site.NexusMods.Server/Startup.cs | 21 +++---------------- 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileProcessorJob.cs b/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileProcessorJob.cs index 73e6c1bc..14af60c0 100644 --- a/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileProcessorJob.cs +++ b/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileProcessorJob.cs @@ -86,8 +86,9 @@ public async Task Execute(IJobExecutionContext context) try { + var apiKey = NexusModsApiKey.From(_nexusModsOptions.ApiKey); var response = await _nexusModsAPIClient - .GetModFileInfosFullAsync(gameDomain, modId, _nexusModsOptions.ApiKey, ct); + .GetModFileInfosFullAsync(gameDomain, modId, apiKey, ct); if (response is null) { notFoundMods++; @@ -97,7 +98,7 @@ public async Task Execute(IJobExecutionContext context) continue; } - var infos = await _nexusModsModFileParser.GetModuleInfosAsync(gameDomain, modId, response.Files, _nexusModsOptions.ApiKey, ct).ToArrayAsync(ct); + var infos = await _nexusModsModFileParser.GetModuleInfosAsync(gameDomain, modId, response.Files, apiKey, ct).ToArrayAsync(ct); var latestFileUpdate = DateTimeOffset.FromUnixTimeSeconds(response.Files.Select(x => x.UploadedTimestamp).Where(x => x is not null).Max() ?? 0).ToUniversalTime(); nexusModsModModuleEntities.AddRange(infos.Select(x => x.ModuleInfo).DistinctBy(x => x.Id).Select(x => new NexusModsModToModuleEntity diff --git a/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs b/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs index 0bb2d3e6..5a66a43a 100644 --- a/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs +++ b/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs @@ -81,7 +81,7 @@ public async Task Execute(IJobExecutionContext context) var dateOneWeekAgo = DateTime.UtcNow.AddDays(-30); var updatesStoredWithinWeek = await unitOfRead.NexusModsModToFileUpdates.GetAllAsync(x => x.LastCheckedDate > dateOneWeekAgo, null, ct); - var updatedWithinWeek = await _nexusModsAPIClient.GetAllModUpdatesWeekAsync(gameDomain, _nexusModsOptions.ApiKey, ct) ?? Array.Empty(); + var updatedWithinWeek = await _nexusModsAPIClient.GetAllModUpdatesWeekAsync(gameDomain, NexusModsApiKey.From(_nexusModsOptions.ApiKey), ct) ?? Array.Empty(); var newUpdates = updatedWithinWeek.Where(x => { var latestFileUpdateDate = DateTimeOffset.FromUnixTimeSeconds(x.LatestFileUpdateTimestamp).ToUniversalTime(); diff --git a/src/BUTR.Site.NexusMods.Server/Options/NexusModsOptions.cs b/src/BUTR.Site.NexusMods.Server/Options/NexusModsOptions.cs index 2f0d5764..e1998fda 100644 --- a/src/BUTR.Site.NexusMods.Server/Options/NexusModsOptions.cs +++ b/src/BUTR.Site.NexusMods.Server/Options/NexusModsOptions.cs @@ -2,11 +2,13 @@ using FluentValidation; +using System.Net.Http; + namespace BUTR.Site.NexusMods.Server.Options; public sealed class NexusModsOptionsValidator : AbstractValidator { - public NexusModsOptionsValidator() + public NexusModsOptionsValidator(HttpClient client) { RuleFor(x => x.ApiKey).NotEmpty(); } @@ -14,5 +16,6 @@ public NexusModsOptionsValidator() public sealed record NexusModsOptions { - public required NexusModsApiKey ApiKey { get; init; } = NexusModsApiKey.None; + // TODO: + public required string ApiKey { get; init; } } \ No newline at end of file diff --git a/src/BUTR.Site.NexusMods.Server/Options/NexusModsUsersOptions.cs b/src/BUTR.Site.NexusMods.Server/Options/NexusModsUsersOptions.cs index 472cde7b..e28a4466 100644 --- a/src/BUTR.Site.NexusMods.Server/Options/NexusModsUsersOptions.cs +++ b/src/BUTR.Site.NexusMods.Server/Options/NexusModsUsersOptions.cs @@ -2,11 +2,13 @@ using FluentValidation; +using System.Net.Http; + namespace BUTR.Site.NexusMods.Server.Options; public sealed class NexusModsUsersOptionsValidator : AbstractValidator { - public NexusModsUsersOptionsValidator() + public NexusModsUsersOptionsValidator(HttpClient client) { RuleFor(x => x.ClientId).NotEmpty(); RuleFor(x => x.RedirectUri).NotEmpty().IsUri(); diff --git a/src/BUTR.Site.NexusMods.Server/Program.cs b/src/BUTR.Site.NexusMods.Server/Program.cs index 2a6c56f9..583ae2e7 100644 --- a/src/BUTR.Site.NexusMods.Server/Program.cs +++ b/src/BUTR.Site.NexusMods.Server/Program.cs @@ -43,7 +43,7 @@ public static async Task Main(string[] args) var host = CreateHostBuilder(args).Build(); await host - //.SeedDbContext() + .SeedDbContext() .RunAsync(); } catch (Exception ex) diff --git a/src/BUTR.Site.NexusMods.Server/Startup.cs b/src/BUTR.Site.NexusMods.Server/Startup.cs index 8deeb9d8..3da9438c 100644 --- a/src/BUTR.Site.NexusMods.Server/Startup.cs +++ b/src/BUTR.Site.NexusMods.Server/Startup.cs @@ -49,7 +49,6 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Text.Unicode; -using Serilog; namespace BUTR.Site.NexusMods.Server; @@ -109,13 +108,14 @@ public void ConfigureServices(IServiceCollection services) services.AddOptions().Configure(opt => Configure(opt)); services.AddValidatedOptions().Bind(connectionStringSection); + services.AddValidatedOptionsWithHttp().Bind(crashReporterSection); + services.AddValidatedOptionsWithHttp().Bind(nexusModsSection); + services.AddValidatedOptionsWithHttp().Bind(nexusModsUsersSection); services.AddValidatedOptions().Bind(jwtSection); services.AddValidatedOptions().Bind(gitHubSection); services.AddValidatedOptions().Bind(discordSection); services.AddValidatedOptions().Bind(steamAPISection); services.AddValidatedOptions().Bind(depotDownloaderSection); - //services.AddValidatedOptions().Bind(nexusModsSection); - services.AddValidatedOptions().Bind(nexusModsUsersSection); services.AddHttpClient(string.Empty).ConfigureHttpClient((_, client) => { @@ -185,9 +185,7 @@ public void ConfigureServices(IServiceCollection services) client.BaseAddress = new Uri("https://embed.gog.com/"); client.DefaultRequestHeaders.Add("User-Agent", userAgent); }).AddPolicyHandler(GetRetryPolicy()); - return; - Log.Warning("Test4"); services.AddQuartzHostedService(options => { options.AwaitApplicationStarted = true; @@ -236,22 +234,18 @@ public void ConfigureServices(IServiceCollection services) services.AddMemoryCache(); - Log.Warning("Test5"); var types = typeof(Startup).Assembly.GetTypes().Where(x => x is { IsAbstract: false, BaseType: { IsGenericType: true } }).ToList(); foreach (var type in types.Where(x => x.BaseType!.GetGenericTypeDefinition() == typeof(BaseEntityConfigurationWithTenant<>))) services.TryAddEnumerable(ServiceDescriptor.Scoped(typeof(IEntityConfiguration), type)); foreach (var type in types.Where(x => x.BaseType!.GetGenericTypeDefinition() == typeof(BaseEntityConfiguration<>))) services.TryAddEnumerable(ServiceDescriptor.Scoped(typeof(IEntityConfiguration), type)); - Log.Warning("Tes6"); services.AddDbContext(ServiceLifetime.Scoped); services.AddDbContextFactory(lifetime: ServiceLifetime.Scoped); services.AddDbContextFactory(lifetime: ServiceLifetime.Scoped); - Log.Warning("Test7"); services.AddNexusModsDefaultServices(); - Log.Warning("Test8"); services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.AddAuthentication(ButrNexusModsAuthSchemeConstants.AuthScheme).AddNexusMods(options => @@ -260,16 +254,13 @@ public void ConfigureServices(IServiceCollection services) options.EncryptionKey = opts?.EncryptionKey ?? string.Empty; }); - Log.Warning("Test9"); services.AddStreamingMultipartResult(); services.AddHttpContextAccessor(); - Log.Warning("Test10"); services.AddRouting(opt => { opt.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer); }); - Log.Warning("Test11"); services.AddControllersWithAPIResult(opt => { opt.Conventions.Add(new SlugifyActionConvention()); @@ -279,7 +270,6 @@ public void ConfigureServices(IServiceCollection services) opt.ValueProviderFactories.Add(new ClaimsValueProviderFactory()); }).AddJsonOptions(opt => Configure(opt.JsonSerializerOptions)); - Log.Warning("Test12"); services.AddResponseCompression(opt => { opt.Providers.Add(); @@ -294,7 +284,6 @@ public void ConfigureServices(IServiceCollection services) options.Level = CompressionLevel.SmallestSize; }); - Log.Warning("Test13"); services.AddSwaggerGen(opt => { opt.SwaggerDoc("v1", new OpenApiInfo @@ -350,7 +339,6 @@ public void ConfigureServices(IServiceCollection services) opt.IncludeXmlComments(xmlFilePath); }); - Log.Warning("Test14"); services.Configure(options => { options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; @@ -358,7 +346,6 @@ public void ConfigureServices(IServiceCollection services) services.AddResponseCaching(); - Log.Warning("Test15"); services.AddCors(options => { options.AddPolicy("Development", builder => builder @@ -368,7 +355,6 @@ public void ConfigureServices(IServiceCollection services) ); }); - Log.Warning("Test16"); services.AddDistributedPostgreSqlCache(options => { var opts = connectionStringSection.Get(); @@ -384,7 +370,6 @@ public void ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app, IHostEnvironment env) { - return; app.UseForwardedHeaders(); if (env.IsDevelopment())