Fixed scanning issue. Updated worker.
Some checks failed
ci / build-test (push) Has been cancelled
ci / publish-image (push) Has been cancelled

This commit is contained in:
2026-02-14 22:47:19 -05:00
parent 340c62d18b
commit a85989a337
14 changed files with 286 additions and 36 deletions

View File

@@ -48,6 +48,7 @@ public static class InfrastructureServiceCollectionExtensions
services.AddKeyedScoped<IVoiceWorkUpdater, VoiceWorkUpdater>(Locale.Japanese);
services.AddKeyedScoped<IVoiceWorkUpdater, EnglishVoiceWorkUpdater>(Locale.English);
services.AddScoped<IVoiceWorkSearchUpdater, VoiceWorkSearchUpdater>();
//services.AddKeyedScoped<ISupportedLanguage, JapaneseLanguage>(Locale.Japanese);
//services.AddKeyedScoped<ISupportedLanguage, EnglishLanguage>(Locale.English);
@@ -64,27 +65,34 @@ public static class InfrastructureServiceCollectionExtensions
services.AddSingleton<ICache, MemoryCacheAdapter>();
services.AddSingleton<ISpamCircleCache, SpamCircleCache>();
services.AddHttpClient<IHttpService, HttpService>(client =>
{
client.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0");
});
services.AddScoped<IHttpService, HttpService>();
services.AddScoped<IHtmlLoader, HtmlLoader>();
services.AddSingleton<ILanguageIdentifier, LanguageIdentifier>();
services.AddSingleton<IClock, Clock>();
services.AddSingleton<ITimeProvider, TokyoTimeProvider>();
services.AddHttpClient<IDLSiteClient, DLSiteClient>(httpClient =>
services.AddHttpServices();
return services;
}
private static IServiceCollection AddHttpServices(this IServiceCollection services)
{
//services.AddHttpClient<IHttpService, HttpService>(client =>
//{
// client.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0");
//});
//services.AddScoped<IHttpService, HttpService>();
services.AddScoped<IHtmlLoader, HtmlLoader>();
// ONE registration for IHttpService as a typed client:
services.AddHttpClient<IHttpService, HttpService>((sp, http) =>
{
httpClient.BaseAddress = new Uri("https://www.dlsite.com/");
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0 (+contact@example.com)");
httpClient.Timeout = TimeSpan.FromSeconds(15);
http.BaseAddress = new Uri("https://www.dlsite.com/");
http.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0");
http.Timeout = TimeSpan.FromSeconds(15);
})
.AddResilienceHandler("dlsite", builder =>
{
.AddResilienceHandler("dlsite", builder => {
builder.AddRetry(new HttpRetryStrategyOptions
{
MaxRetryAttempts = 3,
@@ -93,21 +101,13 @@ public static class InfrastructureServiceCollectionExtensions
BackoffType = DelayBackoffType.Exponential,
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
.Handle<HttpRequestException>()
.HandleResult(msg =>
msg.StatusCode == (HttpStatusCode)429 ||
(int)msg.StatusCode >= 500)
.HandleResult(r => (int)r.StatusCode >= 500 || (int)r.StatusCode == 429)
});
// (Optional) add a circuit breaker:
// builder.AddCircuitBreaker(new HttpCircuitBreakerStrategyOptions
// {
// FailureRatio = 0.2,
// SamplingDuration = TimeSpan.FromSeconds(30),
// MinimumThroughput = 20,
// BreakDuration = TimeSpan.FromSeconds(15)
// });
});
// Register DLSiteClient as a normal scoped service
services.AddScoped<IDLSiteClient, DLSiteClient>();
return services;
}
}