This commit is contained in:
Flaminel
2025-05-16 20:05:21 +03:00
parent 46ef6123cc
commit bc1da2113c
32 changed files with 421 additions and 811 deletions

View File

@@ -114,15 +114,12 @@ public class DownloadClientsController : ControllerBase
config.Clients.Add(clientConfig);
// Persist the updated configuration
var result = await _configManager.UpdateDownloadClientConfigAsync(config);
var result = await _configManager.SaveDownloadClientConfigAsync(config);
if (!result)
{
return StatusCode(500, new { Error = "Failed to save download client configuration" });
}
// Refresh the client factory to recognize the new client
await _clientFactory.RefreshClients();
_logger.LogInformation("Added new download client: {name} ({id})", clientConfig.Name, clientConfig.Id);
return CreatedAtAction(nameof(GetClient), new { id = clientConfig.Id }, clientConfig);
}
@@ -168,15 +165,12 @@ public class DownloadClientsController : ControllerBase
config.Clients[existingClientIndex] = clientConfig;
// Persist the updated configuration
var result = await _configManager.UpdateDownloadClientConfigAsync(config);
var result = await _configManager.SaveDownloadClientConfigAsync(config);
if (!result)
{
return StatusCode(500, new { Error = "Failed to save download client configuration" });
}
// Refresh the client factory to recognize the updated client
await _clientFactory.RefreshClients();
_logger.LogInformation("Updated download client: {name} ({id})", clientConfig.Name, clientConfig.Id);
return Ok(clientConfig);
}
@@ -213,15 +207,12 @@ public class DownloadClientsController : ControllerBase
config.Clients.RemoveAt(existingClientIndex);
// Persist the updated configuration
var result = await _configManager.UpdateDownloadClientConfigAsync(config);
var result = await _configManager.SaveDownloadClientConfigAsync(config);
if (!result)
{
return StatusCode(500, new { Error = "Failed to save download client configuration" });
}
// Refresh the client factory to recognize the deleted client
await _clientFactory.RefreshClients();
_logger.LogInformation("Deleted download client with ID: {id}", id);
return NoContent();
}
@@ -282,7 +273,7 @@ public class DownloadClientsController : ControllerBase
/// Gets all clients of a specific type
/// </summary>
[HttpGet("type/{type}")]
public async Task<IActionResult> GetClientsByType(DownloadClient type)
public async Task<IActionResult> GetClientsByType(DownloadClientType type)
{
try
{

View File

@@ -117,7 +117,6 @@ public class StatusController : ControllerBase
client.Name,
client.Type,
client.Host,
client.Port,
client.Enabled,
IsConnected = client.Enabled, // We can't check connection status without implementing test methods
});

View File

@@ -8,6 +8,8 @@ using Infrastructure.Http;
using Infrastructure.Services;
using Infrastructure.Verticals.DownloadClient.Factory;
using Infrastructure.Verticals.DownloadClient.Deluge;
using Infrastructure.Verticals.DownloadClient.QBittorrent;
using Infrastructure.Verticals.DownloadClient.Transmission;
using Infrastructure.Verticals.DownloadRemover.Consumers;
using Infrastructure.Verticals.Notifications.Consumers;
using Infrastructure.Verticals.Notifications.Models;
@@ -77,30 +79,30 @@ public static class MainDI
// add dynamic HTTP client provider
services.AddSingleton<IDynamicHttpClientProvider, DynamicHttpClientProvider>();
var configManager = services.BuildServiceProvider().GetRequiredService<IConfigManager>();
HttpConfig config = configManager.GetConfiguration<HttpConfig>("http.json") ?? new();
config.Validate();
// add retry HttpClient
services
.AddHttpClient(Constants.HttpClientWithRetryName, x =>
{
x.Timeout = TimeSpan.FromSeconds(config.Timeout);
})
.ConfigurePrimaryHttpMessageHandler(provider =>
{
CertificateValidationService service = provider.GetRequiredService<CertificateValidationService>();
return new HttpClientHandler
{
ServerCertificateCustomValidationCallback = service.ShouldByPassValidationError
};
})
.AddRetryPolicyHandler(config);
// Note: We're no longer configuring specific named HttpClients for each download service
// Instead, we use the DynamicHttpClientProvider to create HttpClients as needed based on client configurations
// var configManager = services.BuildServiceProvider().GetRequiredService<IConfigManager>();
// HttpConfig config = configManager.GetConfiguration<HttpConfig>("http.json") ?? new();
// config.Validate();
//
// // add retry HttpClient
// services
// .AddHttpClient(Constants.HttpClientWithRetryName, x =>
// {
// x.Timeout = TimeSpan.FromSeconds(config.Timeout);
// })
// .ConfigurePrimaryHttpMessageHandler(provider =>
// {
// CertificateValidationService service = provider.GetRequiredService<CertificateValidationService>();
//
// return new HttpClientHandler
// {
// ServerCertificateCustomValidationCallback = service.ShouldByPassValidationError
// };
// })
// .AddRetryPolicyHandler(config);
//
// // Note: We're no longer configuring specific named HttpClients for each download service
// // Instead, we use the DynamicHttpClientProvider to create HttpClients as needed based on client configurations
return services;
}
@@ -120,9 +122,9 @@ public static class MainDI
// Register all download client service types
// The factory will create instances as needed based on the client configuration
.AddTransient<Infrastructure.Verticals.DownloadClient.QBittorrent.QBitService>()
.AddTransient<Infrastructure.Verticals.DownloadClient.Transmission.TransmissionService>()
.AddTransient<Infrastructure.Verticals.DownloadClient.Deluge.DelugeService>();
.AddTransient<QBitService>()
.AddTransient<TransmissionService>()
.AddTransient<DelugeService>();
/// <summary>
/// Adds health check services to the service collection