mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-06-10 14:55:34 -04:00
fix #10
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
using Common.Configuration.Arr;
|
||||
using Common.Configuration.ContentBlocker;
|
||||
using Common.Configuration.DownloadCleaner;
|
||||
using Common.Configuration.DownloadClient;
|
||||
using Common.Configuration.IgnoredDownloads;
|
||||
using Common.Configuration.QueueCleaner;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Infrastructure.Configuration;
|
||||
@@ -43,150 +37,41 @@ public class ConfigInitializer
|
||||
|
||||
private async Task EnsureContentBlockerConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetContentBlockerConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default ContentBlocker configuration");
|
||||
var defaultConfig = new ContentBlockerConfig
|
||||
{
|
||||
Enabled = false,
|
||||
CronExpression = "0 */30 * ? * *", // Every 30 minutes
|
||||
DeletePrivate = false,
|
||||
IgnorePrivate = true,
|
||||
Sonarr = new BlocklistSettings
|
||||
{
|
||||
Enabled = false,
|
||||
Type = BlocklistType.Blacklist,
|
||||
Path = ""
|
||||
},
|
||||
Radarr = new BlocklistSettings
|
||||
{
|
||||
Enabled = false,
|
||||
Type = BlocklistType.Blacklist,
|
||||
Path = ""
|
||||
},
|
||||
Lidarr = new BlocklistSettings
|
||||
{
|
||||
Enabled = false,
|
||||
Type = BlocklistType.Blacklist,
|
||||
Path = ""
|
||||
}
|
||||
};
|
||||
await _configManager.SaveContentBlockerConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetContentBlockerConfigAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureQueueCleanerConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetQueueCleanerConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default QueueCleaner configuration");
|
||||
var defaultConfig = new QueueCleanerConfig
|
||||
{
|
||||
Enabled = false,
|
||||
CronExpression = "0 */15 * ? * *", // Every 15 minutes
|
||||
RunSequentially = false,
|
||||
ImportFailedMaxStrikes = 3,
|
||||
StalledMaxStrikes = 3,
|
||||
SlowMaxStrikes = 3
|
||||
};
|
||||
await _configManager.SaveQueueCleanerConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetQueueCleanerConfigAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureDownloadCleanerConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetDownloadCleanerConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default DownloadCleaner configuration");
|
||||
var defaultConfig = new DownloadCleanerConfig
|
||||
{
|
||||
Enabled = false,
|
||||
CronExpression = "0 */20 * ? * *", // Every 20 minutes
|
||||
DeletePrivate = false,
|
||||
UnlinkedTargetCategory = "cleanuperr-unlinked",
|
||||
UnlinkedUseTag = false
|
||||
};
|
||||
await _configManager.SaveDownloadCleanerConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetDownloadCleanerConfigAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureDownloadClientConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetDownloadClientConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default DownloadClient configuration");
|
||||
var defaultConfig = new DownloadClientConfig
|
||||
{
|
||||
Clients = []
|
||||
};
|
||||
await _configManager.SaveDownloadClientConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetDownloadClientConfigAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureSonarrConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetSonarrConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default Sonarr configuration");
|
||||
var defaultConfig = new SonarrConfig
|
||||
{
|
||||
Enabled = false,
|
||||
ImportFailedMaxStrikes = 3,
|
||||
SearchType = SonarrSearchType.Episode,
|
||||
Instances = new List<ArrInstance>()
|
||||
};
|
||||
await _configManager.SaveSonarrConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetSonarrConfigAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureRadarrConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetRadarrConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default Radarr configuration");
|
||||
var defaultConfig = new RadarrConfig
|
||||
{
|
||||
Enabled = false,
|
||||
ImportFailedMaxStrikes = 3,
|
||||
Instances = new List<ArrInstance>()
|
||||
};
|
||||
await _configManager.SaveRadarrConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetRadarrConfigAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureLidarrConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetLidarrConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default Lidarr configuration");
|
||||
var defaultConfig = new LidarrConfig
|
||||
{
|
||||
Enabled = false,
|
||||
ImportFailedMaxStrikes = 3,
|
||||
Instances = new List<ArrInstance>()
|
||||
};
|
||||
await _configManager.SaveLidarrConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetLidarrConfigAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureIgnoredDownloadsConfigAsync()
|
||||
{
|
||||
var config = await _configManager.GetIgnoredDownloadsConfigAsync();
|
||||
if (config == null)
|
||||
{
|
||||
_logger.LogInformation("Creating default IgnoredDownloads configuration");
|
||||
var defaultConfig = new IgnoredDownloadsConfig
|
||||
{
|
||||
IgnoredDownloads = new List<string>()
|
||||
};
|
||||
await _configManager.SaveIgnoredDownloadsConfigAsync(defaultConfig);
|
||||
}
|
||||
_ = await _configManager.GetIgnoredDownloadsConfigAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,10 @@ public class JsonConfigurationProvider
|
||||
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
_logger.LogDebug("Configuration file does not exist: {file}", fullPath);
|
||||
return new T();
|
||||
_logger.LogDebug("Configuration file does not exist: {file} | creating it now", fullPath);
|
||||
T defaultConfig = new();
|
||||
await WriteConfigurationAsync(fileName, defaultConfig);
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
var json = await File.ReadAllTextAsync(fullPath);
|
||||
|
||||
Reference in New Issue
Block a user