mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-03-04 14:27:52 -05:00
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using Common.Configuration.ContentBlocker;
|
||||
using Common.Configuration.DownloadCleaner;
|
||||
using Common.Configuration.DownloadClient;
|
||||
using Common.Configuration.IgnoredDownloads;
|
||||
using Common.Configuration.QueueCleaner;
|
||||
using Infrastructure.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Executable.Controllers;
|
||||
|
||||
@@ -13,34 +13,23 @@ namespace Executable.Controllers;
|
||||
public class ConfigurationController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<ConfigurationController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IOptionsMonitor<QueueCleanerConfig> _queueCleanerConfig;
|
||||
private readonly IOptionsMonitor<ContentBlockerConfig> _contentBlockerConfig;
|
||||
private readonly IOptionsMonitor<DownloadCleanerConfig> _downloadCleanerConfig;
|
||||
private readonly IConfigurationService _configService;
|
||||
|
||||
public ConfigurationController(
|
||||
ILogger<ConfigurationController> logger,
|
||||
IConfiguration configuration,
|
||||
IOptionsMonitor<QueueCleanerConfig> queueCleanerConfig,
|
||||
IOptionsMonitor<ContentBlockerConfig> contentBlockerConfig,
|
||||
IOptionsMonitor<DownloadCleanerConfig> downloadCleanerConfig,
|
||||
IConfigurationService configService)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_queueCleanerConfig = queueCleanerConfig;
|
||||
_contentBlockerConfig = contentBlockerConfig;
|
||||
_downloadCleanerConfig = downloadCleanerConfig;
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
[HttpGet("queuecleaner")]
|
||||
public IActionResult GetQueueCleanerConfig()
|
||||
public async Task<IActionResult> GetQueueCleanerConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_queueCleanerConfig.CurrentValue);
|
||||
var config = await _configService.GetQueueCleanerConfigAsync();
|
||||
return Ok(config);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -50,11 +39,12 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("contentblocker")]
|
||||
public IActionResult GetContentBlockerConfig()
|
||||
public async Task<IActionResult> GetContentBlockerConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_contentBlockerConfig.CurrentValue);
|
||||
var config = await _configService.GetContentBlockerConfigAsync();
|
||||
return Ok(config);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -64,11 +54,12 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("downloadcleaner")]
|
||||
public IActionResult GetDownloadCleanerConfig()
|
||||
public async Task<IActionResult> GetDownloadCleanerConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_downloadCleanerConfig.CurrentValue);
|
||||
var config = await _configService.GetDownloadCleanerConfigAsync();
|
||||
return Ok(config);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -76,6 +67,36 @@ public class ConfigurationController : ControllerBase
|
||||
return StatusCode(500, "An error occurred while retrieving DownloadCleaner configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("downloadclient")]
|
||||
public async Task<IActionResult> GetDownloadClientConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _configService.GetDownloadClientConfigAsync();
|
||||
return Ok(config);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving DownloadClient configuration");
|
||||
return StatusCode(500, "An error occurred while retrieving DownloadClient configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("ignoreddownloads")]
|
||||
public async Task<IActionResult> GetIgnoredDownloadsConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _configService.GetIgnoredDownloadsConfigAsync();
|
||||
return Ok(config);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving IgnoredDownloads configuration");
|
||||
return StatusCode(500, "An error occurred while retrieving IgnoredDownloads configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("queuecleaner")]
|
||||
public async Task<IActionResult> UpdateQueueCleanerConfig([FromBody] QueueCleanerConfig config)
|
||||
@@ -86,7 +107,7 @@ public class ConfigurationController : ControllerBase
|
||||
config.Validate();
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configService.UpdateConfigurationAsync(QueueCleanerConfig.SectionName, config);
|
||||
var result = await _configService.UpdateQueueCleanerConfigAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save QueueCleaner configuration");
|
||||
@@ -111,7 +132,7 @@ public class ConfigurationController : ControllerBase
|
||||
config.Validate();
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configService.UpdateConfigurationAsync(ContentBlockerConfig.SectionName, config);
|
||||
var result = await _configService.UpdateContentBlockerConfigAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save ContentBlocker configuration");
|
||||
@@ -136,7 +157,7 @@ public class ConfigurationController : ControllerBase
|
||||
config.Validate();
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configService.UpdateConfigurationAsync(DownloadCleanerConfig.SectionName, config);
|
||||
var result = await _configService.UpdateDownloadCleanerConfigAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save DownloadCleaner configuration");
|
||||
@@ -151,4 +172,48 @@ public class ConfigurationController : ControllerBase
|
||||
return StatusCode(500, "An error occurred while updating DownloadCleaner configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("downloadclient")]
|
||||
public async Task<IActionResult> UpdateDownloadClientConfig([FromBody] DownloadClientConfig config)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Persist the configuration
|
||||
var result = await _configService.UpdateDownloadClientConfigAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save DownloadClient configuration");
|
||||
}
|
||||
|
||||
_logger.LogInformation("DownloadClient configuration updated successfully");
|
||||
return Ok(new { Message = "DownloadClient configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating DownloadClient configuration");
|
||||
return StatusCode(500, "An error occurred while updating DownloadClient configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("ignoreddownloads")]
|
||||
public async Task<IActionResult> UpdateIgnoredDownloadsConfig([FromBody] IgnoredDownloadsConfig config)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Persist the configuration
|
||||
var result = await _configService.UpdateIgnoredDownloadsConfigAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save IgnoredDownloads configuration");
|
||||
}
|
||||
|
||||
_logger.LogInformation("IgnoredDownloads configuration updated successfully");
|
||||
return Ok(new { Message = "IgnoredDownloads configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating IgnoredDownloads configuration");
|
||||
return StatusCode(500, "An error occurred while updating IgnoredDownloads configuration");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
121
code/Executable/Controllers/IgnoredDownloadsController.cs
Normal file
121
code/Executable/Controllers/IgnoredDownloadsController.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using Common.Configuration.IgnoredDownloads;
|
||||
using Infrastructure.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Executable.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class IgnoredDownloadsController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<IgnoredDownloadsController> _logger;
|
||||
private readonly IIgnoredDownloadsService _ignoredDownloadsService;
|
||||
|
||||
public IgnoredDownloadsController(
|
||||
ILogger<IgnoredDownloadsController> logger,
|
||||
IIgnoredDownloadsService ignoredDownloadsService)
|
||||
{
|
||||
_logger = logger;
|
||||
_ignoredDownloadsService = ignoredDownloadsService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all ignored downloads
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetIgnoredDownloads()
|
||||
{
|
||||
try
|
||||
{
|
||||
var ignoredDownloads = await _ignoredDownloadsService.GetIgnoredDownloadsAsync();
|
||||
return Ok(ignoredDownloads);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving ignored downloads");
|
||||
return StatusCode(500, "An error occurred while retrieving ignored downloads");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new download ID to be ignored
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddIgnoredDownload([FromBody] string downloadId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(downloadId))
|
||||
{
|
||||
return BadRequest("Download ID cannot be empty");
|
||||
}
|
||||
|
||||
var result = await _ignoredDownloadsService.AddIgnoredDownloadAsync(downloadId);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to add download ID to ignored list");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Added download ID to ignored list: {DownloadId}", downloadId);
|
||||
return Ok(new { Message = $"Download ID '{downloadId}' added to ignored list" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error adding download ID to ignored list");
|
||||
return StatusCode(500, "An error occurred while adding download ID to ignored list");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a download ID from the ignored list
|
||||
/// </summary>
|
||||
[HttpDelete("{downloadId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredDownload(string downloadId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(downloadId))
|
||||
{
|
||||
return BadRequest("Download ID cannot be empty");
|
||||
}
|
||||
|
||||
var result = await _ignoredDownloadsService.RemoveIgnoredDownloadAsync(downloadId);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to remove download ID from ignored list");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Removed download ID from ignored list: {DownloadId}", downloadId);
|
||||
return Ok(new { Message = $"Download ID '{downloadId}' removed from ignored list" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error removing download ID from ignored list");
|
||||
return StatusCode(500, "An error occurred while removing download ID from ignored list");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear all ignored downloads
|
||||
/// </summary>
|
||||
[HttpDelete]
|
||||
public async Task<IActionResult> ClearIgnoredDownloads()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _ignoredDownloadsService.ClearIgnoredDownloadsAsync();
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to clear ignored downloads list");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Cleared all ignored downloads");
|
||||
return Ok(new { Message = "All ignored downloads have been cleared" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error clearing ignored downloads list");
|
||||
return StatusCode(500, "An error occurred while clearing ignored downloads list");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user