mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-10-28 10:48:49 -04:00
89 lines
3.2 KiB
C#
89 lines
3.2 KiB
C#
using Cleanuparr.Domain.Enums;
|
|
using Cleanuparr.Infrastructure.Http.DynamicHttpClientSystem;
|
|
using Cleanuparr.Infrastructure.Logging;
|
|
using Cleanuparr.Persistence.Models.Configuration.General;
|
|
|
|
namespace Cleanuparr.Api.Features.General.Contracts.Requests;
|
|
|
|
public sealed record UpdateGeneralConfigRequest
|
|
{
|
|
public bool DisplaySupportBanner { get; init; } = true;
|
|
|
|
public bool DryRun { get; init; }
|
|
|
|
public ushort HttpMaxRetries { get; init; }
|
|
|
|
public ushort HttpTimeout { get; init; } = 100;
|
|
|
|
public CertificateValidationType HttpCertificateValidation { get; init; } = CertificateValidationType.Enabled;
|
|
|
|
public bool HttpSendUserAgent { get; init; }
|
|
|
|
public bool StatusCheckEnabled { get; init; } = true;
|
|
|
|
public string EncryptionKey { get; init; } = Guid.NewGuid().ToString();
|
|
|
|
public List<string> IgnoredDownloads { get; init; } = [];
|
|
|
|
public bool ConnectivityCheckEnabled { get; init; }
|
|
|
|
public List<string> ConnectivityCheckUrls { get; init; } = [];
|
|
|
|
public ushort StrikeInactivityWindowHours { get; init; } = 24;
|
|
|
|
public ushort HistoryRetentionDays { get; init; } = 365;
|
|
|
|
public UpdateLoggingConfigRequest Log { get; init; } = new();
|
|
|
|
public UpdateAuthConfigRequest Auth { get; init; } = new();
|
|
|
|
public GeneralConfig ApplyTo(GeneralConfig existingConfig, IServiceProvider services, ILogger logger)
|
|
{
|
|
existingConfig.DisplaySupportBanner = DisplaySupportBanner;
|
|
existingConfig.DryRun = DryRun;
|
|
existingConfig.HttpMaxRetries = HttpMaxRetries;
|
|
existingConfig.HttpTimeout = HttpTimeout;
|
|
existingConfig.HttpCertificateValidation = HttpCertificateValidation;
|
|
existingConfig.HttpSendUserAgent = HttpSendUserAgent;
|
|
existingConfig.StatusCheckEnabled = StatusCheckEnabled;
|
|
existingConfig.EncryptionKey = EncryptionKey;
|
|
existingConfig.IgnoredDownloads = IgnoredDownloads;
|
|
existingConfig.ConnectivityCheckEnabled = ConnectivityCheckEnabled;
|
|
existingConfig.ConnectivityCheckUrls = ConnectivityCheckUrls;
|
|
existingConfig.StrikeInactivityWindowHours = StrikeInactivityWindowHours;
|
|
existingConfig.HistoryRetentionDays = HistoryRetentionDays;
|
|
|
|
bool loggingChanged = Log.ApplyTo(existingConfig.Log);
|
|
Auth.ApplyTo(existingConfig.Auth);
|
|
|
|
existingConfig.Validate();
|
|
|
|
ApplySideEffects(existingConfig, services, logger, loggingChanged);
|
|
|
|
return existingConfig;
|
|
}
|
|
|
|
private void ApplySideEffects(GeneralConfig config, IServiceProvider services, ILogger logger, bool loggingChanged)
|
|
{
|
|
var dynamicHttpClientFactory = services.GetRequiredService<IDynamicHttpClientFactory>();
|
|
dynamicHttpClientFactory.UpdateAllClientsFromGeneralConfig(config);
|
|
|
|
logger.LogInformation("Updated all HTTP client configurations with new general settings");
|
|
|
|
if (!loggingChanged)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Log.LevelOnlyChange)
|
|
{
|
|
logger.LogCritical("Setting global log level to {level}", config.Log.Level);
|
|
LoggingConfigManager.SetLogLevel(config.Log.Level);
|
|
return;
|
|
}
|
|
|
|
logger.LogCritical("Reconfiguring logger due to configuration changes");
|
|
LoggingConfigManager.ReconfigureLogging(config);
|
|
}
|
|
}
|