mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-03-04 14:27:52 -05:00
fix #8
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user