Added Chobit integration. Updated tests.
This commit is contained in:
@@ -24,6 +24,7 @@ using JSMR.Infrastructure.Data.Repositories.Users;
|
||||
using JSMR.Infrastructure.Data.Repositories.VoiceWorks;
|
||||
using JSMR.Infrastructure.Http;
|
||||
using JSMR.Infrastructure.Ingestion;
|
||||
using JSMR.Infrastructure.Integrations.Chobit;
|
||||
using JSMR.Infrastructure.Integrations.DLSite;
|
||||
using JSMR.Infrastructure.Scanning;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -76,6 +77,9 @@ public static class InfrastructureServiceCollectionExtensions
|
||||
services.AddSingleton<ITimeProvider, TokyoTimeProvider>();
|
||||
|
||||
services.AddHttpServices();
|
||||
services.AddNewHttpServices();
|
||||
|
||||
services.AddScoped<IUserRepository, UserRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
@@ -113,7 +117,50 @@ public static class InfrastructureServiceCollectionExtensions
|
||||
// Register DLSiteClient as a normal scoped service
|
||||
services.AddScoped<IDLSiteClient, DLSiteClient>();
|
||||
|
||||
services.AddScoped<IUserRepository, UserRepository>();
|
||||
return services;
|
||||
}
|
||||
|
||||
private static IServiceCollection AddNewHttpServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpClient<IDLSiteClient, DLSiteClient>((sp, http) =>
|
||||
{
|
||||
http.BaseAddress = new Uri("https://www.dlsite.com/");
|
||||
http.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0");
|
||||
http.Timeout = TimeSpan.FromSeconds(15);
|
||||
})
|
||||
.AddResilienceHandler("dlsite", builder =>
|
||||
{
|
||||
builder.AddRetry(new HttpRetryStrategyOptions
|
||||
{
|
||||
MaxRetryAttempts = 3,
|
||||
UseJitter = true,
|
||||
Delay = TimeSpan.FromMilliseconds(200),
|
||||
BackoffType = DelayBackoffType.Exponential,
|
||||
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
|
||||
.Handle<HttpRequestException>()
|
||||
.HandleResult(r => (int)r.StatusCode >= 500 || (int)r.StatusCode == 429)
|
||||
});
|
||||
});
|
||||
|
||||
services.AddHttpClient<IChobitClient, ChobitClient>((sp, http) =>
|
||||
{
|
||||
http.BaseAddress = new Uri("https://chobit.cc/");
|
||||
http.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0");
|
||||
http.Timeout = TimeSpan.FromSeconds(15);
|
||||
})
|
||||
.AddResilienceHandler("chobit", builder =>
|
||||
{
|
||||
builder.AddRetry(new HttpRetryStrategyOptions
|
||||
{
|
||||
MaxRetryAttempts = 3,
|
||||
UseJitter = true,
|
||||
Delay = TimeSpan.FromMilliseconds(200),
|
||||
BackoffType = DelayBackoffType.Exponential,
|
||||
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
|
||||
.Handle<HttpRequestException>()
|
||||
.HandleResult(r => (int)r.StatusCode >= 500 || (int)r.StatusCode == 429)
|
||||
});
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user