add content blocker (#5)
* refactored code added deluge support added transmission support added content blocker added blacklist and whitelist * increased level on some logs; updated test docker compose; updated dev appsettings * updated docker compose and readme * moved some logs * fixed env var typo; fixed sonarr and radarr default download client
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using Common.Configuration;
|
||||
using Infrastructure.Verticals.DownloadClient.Deluge;
|
||||
using Infrastructure.Verticals.DownloadClient.QBittorrent;
|
||||
using Infrastructure.Verticals.DownloadClient.Transmission;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Infrastructure.Verticals.DownloadClient;
|
||||
|
||||
public sealed class DownloadServiceFactory
|
||||
{
|
||||
private readonly QBitConfig _qBitConfig;
|
||||
private readonly DelugeConfig _delugeConfig;
|
||||
private readonly TransmissionConfig _transmissionConfig;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public DownloadServiceFactory(
|
||||
IOptions<QBitConfig> qBitConfig,
|
||||
IOptions<DelugeConfig> delugeConfig,
|
||||
IOptions<TransmissionConfig> transmissionConfig,
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
_qBitConfig = qBitConfig.Value;
|
||||
_delugeConfig = delugeConfig.Value;
|
||||
_transmissionConfig = transmissionConfig.Value;
|
||||
_serviceProvider = serviceProvider;
|
||||
|
||||
_qBitConfig.Validate();
|
||||
_delugeConfig.Validate();
|
||||
_transmissionConfig.Validate();
|
||||
|
||||
int enabledCount = new[] { _qBitConfig.Enabled, _delugeConfig.Enabled, _transmissionConfig.Enabled }
|
||||
.Count(enabled => enabled);
|
||||
|
||||
if (enabledCount > 1)
|
||||
{
|
||||
throw new Exception("only one download client can be enabled");
|
||||
}
|
||||
|
||||
if (enabledCount == 0)
|
||||
{
|
||||
throw new Exception("no download client is enabled");
|
||||
}
|
||||
}
|
||||
|
||||
public IDownloadService CreateDownloadClient()
|
||||
{
|
||||
if (_qBitConfig.Enabled)
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<QBitService>();
|
||||
}
|
||||
|
||||
if (_delugeConfig.Enabled)
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<DelugeService>();
|
||||
}
|
||||
|
||||
if (_transmissionConfig.Enabled)
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<TransmissionService>();
|
||||
}
|
||||
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user