mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2025-12-31 01:48:49 -05:00
Compare commits
24 Commits
v2.0.14
...
fix_qbit_c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b834078c11 | ||
|
|
9cc36c7a50 | ||
|
|
861c135cc6 | ||
|
|
3b0275c411 | ||
|
|
cad1b51202 | ||
|
|
f50acd29f4 | ||
|
|
af11d595d8 | ||
|
|
44994d5b21 | ||
|
|
592fd2d846 | ||
|
|
e96be1fca2 | ||
|
|
ee44e2b5ac | ||
|
|
323bfc4d2e | ||
|
|
dca45585ca | ||
|
|
8b5918d221 | ||
|
|
9c227c1f59 | ||
|
|
2ad4499a6f | ||
|
|
33a5bf9ab3 | ||
|
|
de06d1c2d3 | ||
|
|
72855bc030 | ||
|
|
b185ea6899 | ||
|
|
1e0127e97e | ||
|
|
5bdbc98d68 | ||
|
|
e1aeb3da31 | ||
|
|
283b09e8f1 |
14
.github/workflows/build-docker.yml
vendored
14
.github/workflows/build-docker.yml
vendored
@@ -29,6 +29,8 @@ jobs:
|
||||
githubHeadRef=${{ env.githubHeadRef }}
|
||||
latestDockerTag=""
|
||||
versionDockerTag=""
|
||||
majorVersionDockerTag=""
|
||||
minorVersionDockerTag=""
|
||||
version="0.0.1"
|
||||
|
||||
if [[ "$githubRef" =~ ^"refs/tags/" ]]; then
|
||||
@@ -36,6 +38,12 @@ jobs:
|
||||
latestDockerTag="latest"
|
||||
versionDockerTag=${branch#v}
|
||||
version=${branch#v}
|
||||
|
||||
# Extract major and minor versions for additional tags
|
||||
if [[ "$versionDockerTag" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
|
||||
majorVersionDockerTag="${BASH_REMATCH[1]}"
|
||||
minorVersionDockerTag="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
|
||||
fi
|
||||
else
|
||||
# Determine if this run is for the main branch or another branch
|
||||
if [[ -z "$githubHeadRef" ]]; then
|
||||
@@ -58,6 +66,12 @@ jobs:
|
||||
if [ -n "$versionDockerTag" ]; then
|
||||
githubTags="$githubTags,ghcr.io/cleanuparr/cleanuparr:$versionDockerTag"
|
||||
fi
|
||||
if [ -n "$minorVersionDockerTag" ]; then
|
||||
githubTags="$githubTags,ghcr.io/cleanuparr/cleanuparr:$minorVersionDockerTag"
|
||||
fi
|
||||
if [ -n "$majorVersionDockerTag" ]; then
|
||||
githubTags="$githubTags,ghcr.io/cleanuparr/cleanuparr:$majorVersionDockerTag"
|
||||
fi
|
||||
|
||||
# set env vars
|
||||
echo "branch=$branch" >> $GITHUB_ENV
|
||||
|
||||
36
.github/workflows/cloudflare-pages.yml
vendored
Normal file
36
.github/workflows/cloudflare-pages.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Deploy to Cloudflare Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'Cloudflare/**'
|
||||
- 'blacklist'
|
||||
- 'blacklist_permissive'
|
||||
- 'whitelist'
|
||||
- 'whitelist_with_subtitles'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy to Cloudflare Pages
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Copy root static files to Cloudflare static directory
|
||||
run: |
|
||||
cp blacklist Cloudflare/static/
|
||||
cp blacklist_permissive Cloudflare/static/
|
||||
cp whitelist Cloudflare/static/
|
||||
cp whitelist_with_subtitles Cloudflare/static/
|
||||
|
||||
- name: Deploy to Cloudflare Pages
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }}
|
||||
workingDirectory: "Cloudflare"
|
||||
command: pages deploy . --project-name=cleanuparr
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -106,7 +106,7 @@ jobs:
|
||||
- name: Create release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
name: Cleanuparr ${{ needs.validate.outputs.release_version }}
|
||||
name: ${{ needs.validate.outputs.release_version }}
|
||||
tag_name: ${{ needs.validate.outputs.release_version }}
|
||||
token: ${{ env.REPO_READONLY_PAT }}
|
||||
make_latest: true
|
||||
|
||||
3
Cloudflare/_headers
Normal file
3
Cloudflare/_headers
Normal file
@@ -0,0 +1,3 @@
|
||||
# Cache static files for 5 minutes
|
||||
/static/*
|
||||
Cache-Control: public, max-age=300, s-maxage=300
|
||||
2
Cloudflare/static/known_malware_file_name_patterns
Normal file
2
Cloudflare/static/known_malware_file_name_patterns
Normal file
@@ -0,0 +1,2 @@
|
||||
thepirateheaven.org
|
||||
RARBG.work
|
||||
24
README.md
24
README.md
@@ -15,7 +15,8 @@ Cleanuparr was created primarily to address malicious files, such as `*.lnk` or
|
||||
> - Remove and block downloads that are **failing to be imported** by the arrs.
|
||||
> - Remove and block downloads that are **stalled** or in **metadata downloading** state.
|
||||
> - Remove and block downloads that have a **low download speed** or **high estimated completion time**.
|
||||
> - Remove and block downloads blocked by qBittorrent or by Cleanuparr's **Content Blocker**.
|
||||
> - Remove and block downloads blocked by qBittorrent or by Cleanuparr's **Malware Blocker**.
|
||||
> - Remove and block known malware based on patterns found by the community.
|
||||
> - Automatically trigger a search for downloads removed from the arrs.
|
||||
> - Clean up downloads that have been **seeding** for a certain amount of time.
|
||||
> - Remove downloads that are **orphaned**/have no **hardlinks**/are not referenced by the arrs anymore (with [cross-seed](https://www.cross-seed.org/) support).
|
||||
@@ -25,21 +26,24 @@ Cleanuparr was created primarily to address malicious files, such as `*.lnk` or
|
||||
## 🎯 Supported Applications
|
||||
|
||||
### *Arr Applications
|
||||
- **Sonarr** (TV Shows)
|
||||
- **Radarr** (Movies)
|
||||
- **Lidarr** (Music)
|
||||
- **Sonarr**
|
||||
- **Radarr**
|
||||
- **Lidarr**
|
||||
- **Readarr**
|
||||
- **Whisparr**
|
||||
|
||||
### Download Clients
|
||||
- **qBittorrent**
|
||||
- **Transmission**
|
||||
- **Deluge**
|
||||
- **µTorrent**
|
||||
|
||||
### Platforms
|
||||
- **Docker** (Linux, Windows, macOS)
|
||||
- **Windows** (Native installer)
|
||||
- **macOS** (Intel & Apple Silicon)
|
||||
- **Linux** (Portable executable)
|
||||
- **Unraid** (Community Apps)
|
||||
- **Docker**
|
||||
- **Windows**
|
||||
- **macOS**
|
||||
- **Linux**
|
||||
- **Unraid**
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
@@ -55,7 +59,7 @@ docker run -d --name cleanuparr \
|
||||
ghcr.io/cleanuparr/cleanuparr:latest
|
||||
```
|
||||
|
||||
For Docker Compose, health checks, and other installation methods, see our [Complete Installation Guide](https://cleanuparr.github.io/Cleanuparr/docs/installation/detailed).
|
||||
For Docker Compose, health checks, and other installation methods, see the [Complete Installation Guide](https://cleanuparr.github.io/Cleanuparr/docs/installation/detailed).
|
||||
|
||||
### 🌐 Access the Web Interface
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ using Cleanuparr.Infrastructure.Utilities;
|
||||
using Cleanuparr.Persistence;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Cleanuparr.Persistence.Models.Configuration.Arr;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.DownloadCleaner;
|
||||
using Cleanuparr.Persistence.Models.Configuration.General;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.Notification;
|
||||
using Cleanuparr.Persistence.Models.Configuration.QueueCleaner;
|
||||
using Mapster;
|
||||
@@ -65,8 +65,8 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("content_blocker")]
|
||||
public async Task<IActionResult> GetContentBlockerConfig()
|
||||
[HttpGet("malware_blocker")]
|
||||
public async Task<IActionResult> GetMalwareBlockerConfig()
|
||||
{
|
||||
await DataContext.Lock.WaitAsync();
|
||||
try
|
||||
@@ -483,8 +483,8 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("content_blocker")]
|
||||
public async Task<IActionResult> UpdateContentBlockerConfig([FromBody] ContentBlockerConfig newConfig)
|
||||
[HttpPut("malware_blocker")]
|
||||
public async Task<IActionResult> UpdateMalwareBlockerConfig([FromBody] ContentBlockerConfig newConfig)
|
||||
{
|
||||
await DataContext.Lock.WaitAsync();
|
||||
try
|
||||
@@ -495,7 +495,7 @@ public class ConfigurationController : ControllerBase
|
||||
// Validate cron expression if present
|
||||
if (!string.IsNullOrEmpty(newConfig.CronExpression))
|
||||
{
|
||||
CronValidationHelper.ValidateCronExpression(newConfig.CronExpression, JobType.ContentBlocker);
|
||||
CronValidationHelper.ValidateCronExpression(newConfig.CronExpression, JobType.MalwareBlocker);
|
||||
}
|
||||
|
||||
// Get existing config
|
||||
@@ -513,13 +513,13 @@ public class ConfigurationController : ControllerBase
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
// Update the scheduler based on configuration changes
|
||||
await UpdateJobSchedule(oldConfig, JobType.ContentBlocker);
|
||||
await UpdateJobSchedule(oldConfig, JobType.MalwareBlocker);
|
||||
|
||||
return Ok(new { Message = "ContentBlocker configuration updated successfully" });
|
||||
return Ok(new { Message = "MalwareBlocker configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to save ContentBlocker configuration");
|
||||
_logger.LogError(ex, "Failed to save MalwareBlocker configuration");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -87,10 +87,6 @@ public class EventsController : ControllerBase
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
|
||||
events = events
|
||||
.OrderBy(e => e.Timestamp)
|
||||
.ToList();
|
||||
|
||||
// Return paginated result
|
||||
var result = new PaginatedResult<AppEvent>
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public static class LoggingDI
|
||||
const string fileOutputTemplate = $"{{@t:yyyy-MM-dd HH:mm:ss.fff zzz}} [{{@l:u3}}]{jobNameTemplate}{categoryTemplate} {{@m:lj}}\n{{@x}}";
|
||||
|
||||
// Determine job name padding
|
||||
List<string> jobNames = [nameof(JobType.QueueCleaner), nameof(JobType.ContentBlocker), nameof(JobType.DownloadCleaner)];
|
||||
List<string> jobNames = [nameof(JobType.QueueCleaner), nameof(JobType.MalwareBlocker), nameof(JobType.DownloadCleaner)];
|
||||
int jobPadding = jobNames.Max(x => x.Length) + 2;
|
||||
|
||||
// Determine instance name padding
|
||||
|
||||
@@ -27,6 +27,8 @@ public static class MainDI
|
||||
.AddNotifications(configuration)
|
||||
.AddMassTransit(config =>
|
||||
{
|
||||
config.DisableUsageTelemetry();
|
||||
|
||||
config.AddConsumer<DownloadRemoverConsumer<SearchItem>>();
|
||||
config.AddConsumer<DownloadRemoverConsumer<SeriesSearchItem>>();
|
||||
config.AddConsumer<DownloadHunterConsumer<SearchItem>>();
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using Cleanuparr.Application.Features.ContentBlocker;
|
||||
using Cleanuparr.Application.Features.DownloadCleaner;
|
||||
using Cleanuparr.Application.Features.MalwareBlocker;
|
||||
using Cleanuparr.Application.Features.QueueCleaner;
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.Arr;
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadHunter;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadHunter.Interfaces;
|
||||
@@ -11,6 +10,7 @@ using Cleanuparr.Infrastructure.Features.DownloadRemover;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadRemover.Interfaces;
|
||||
using Cleanuparr.Infrastructure.Features.Files;
|
||||
using Cleanuparr.Infrastructure.Features.ItemStriker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.Security;
|
||||
using Cleanuparr.Infrastructure.Interceptors;
|
||||
using Cleanuparr.Infrastructure.Services;
|
||||
@@ -25,34 +25,32 @@ public static class ServicesDI
|
||||
{
|
||||
public static IServiceCollection AddServices(this IServiceCollection services) =>
|
||||
services
|
||||
.AddSingleton<IEncryptionService, AesEncryptionService>()
|
||||
.AddTransient<SensitiveDataJsonConverter>()
|
||||
.AddTransient<EventsContext>()
|
||||
.AddTransient<DataContext>()
|
||||
.AddTransient<EventPublisher>()
|
||||
.AddScoped<IEncryptionService, AesEncryptionService>()
|
||||
.AddScoped<SensitiveDataJsonConverter>()
|
||||
.AddScoped<EventsContext>()
|
||||
.AddScoped<DataContext>()
|
||||
.AddScoped<EventPublisher>()
|
||||
.AddHostedService<EventCleanupService>()
|
||||
// API services
|
||||
.AddScoped<IDryRunInterceptor, DryRunInterceptor>()
|
||||
.AddScoped<CertificateValidationService>()
|
||||
.AddScoped<SonarrClient>()
|
||||
.AddScoped<RadarrClient>()
|
||||
.AddScoped<LidarrClient>()
|
||||
.AddScoped<ReadarrClient>()
|
||||
.AddScoped<WhisparrClient>()
|
||||
.AddScoped<ArrClientFactory>()
|
||||
.AddScoped<QueueCleaner>()
|
||||
.AddScoped<MalwareBlocker>()
|
||||
.AddScoped<DownloadCleaner>()
|
||||
.AddScoped<IQueueItemRemover, QueueItemRemover>()
|
||||
.AddScoped<IDownloadHunter, DownloadHunter>()
|
||||
.AddScoped<IFilenameEvaluator, FilenameEvaluator>()
|
||||
.AddScoped<IHardLinkFileService, HardLinkFileService>()
|
||||
.AddScoped<UnixHardLinkFileService>()
|
||||
.AddScoped<WindowsHardLinkFileService>()
|
||||
.AddScoped<ArrQueueIterator>()
|
||||
.AddScoped<DownloadServiceFactory>()
|
||||
.AddScoped<IStriker, Striker>()
|
||||
.AddSingleton<IJobManagementService, JobManagementService>()
|
||||
// Core services
|
||||
.AddTransient<IDryRunInterceptor, DryRunInterceptor>()
|
||||
.AddTransient<CertificateValidationService>()
|
||||
.AddTransient<SonarrClient>()
|
||||
.AddTransient<RadarrClient>()
|
||||
.AddTransient<LidarrClient>()
|
||||
.AddTransient<ReadarrClient>()
|
||||
.AddTransient<WhisparrClient>()
|
||||
.AddTransient<ArrClientFactory>()
|
||||
.AddTransient<QueueCleaner>()
|
||||
.AddTransient<ContentBlocker>()
|
||||
.AddTransient<DownloadCleaner>()
|
||||
.AddTransient<IQueueItemRemover, QueueItemRemover>()
|
||||
.AddTransient<IDownloadHunter, DownloadHunter>()
|
||||
.AddTransient<IFilenameEvaluator, FilenameEvaluator>()
|
||||
.AddTransient<IHardLinkFileService, HardLinkFileService>()
|
||||
.AddTransient<UnixHardLinkFileService>()
|
||||
.AddTransient<WindowsHardLinkFileService>()
|
||||
.AddTransient<ArrQueueIterator>()
|
||||
.AddTransient<DownloadServiceFactory>()
|
||||
.AddTransient<IStriker, Striker>()
|
||||
.AddSingleton<BlocklistProvider>();
|
||||
}
|
||||
@@ -21,13 +21,16 @@ public static class HostExtensions
|
||||
logger.LogInformation("timezone: {tz}", TimeZoneInfo.Local.DisplayName);
|
||||
|
||||
// Apply db migrations
|
||||
var eventsContext = app.Services.GetRequiredService<EventsContext>();
|
||||
var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
|
||||
await using var eventsContext = scope.ServiceProvider.GetRequiredService<EventsContext>();
|
||||
if ((await eventsContext.Database.GetPendingMigrationsAsync()).Any())
|
||||
{
|
||||
await eventsContext.Database.MigrateAsync();
|
||||
}
|
||||
|
||||
var configContext = app.Services.GetRequiredService<DataContext>();
|
||||
await using var configContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
if ((await configContext.Database.GetPendingMigrationsAsync()).Any())
|
||||
{
|
||||
await configContext.Database.MigrateAsync();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using Cleanuparr.Application.Features.ContentBlocker;
|
||||
using Cleanuparr.Application.Features.DownloadCleaner;
|
||||
using Cleanuparr.Application.Features.MalwareBlocker;
|
||||
using Cleanuparr.Application.Features.QueueCleaner;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
using Cleanuparr.Infrastructure.Features.Jobs;
|
||||
using Cleanuparr.Persistence;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.DownloadCleaner;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.QueueCleaner;
|
||||
using Cleanuparr.Shared.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -22,18 +22,18 @@ namespace Cleanuparr.Api.Jobs;
|
||||
public class BackgroundJobManager : IHostedService
|
||||
{
|
||||
private readonly ISchedulerFactory _schedulerFactory;
|
||||
private readonly DataContext _dataContext;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly ILogger<BackgroundJobManager> _logger;
|
||||
private IScheduler? _scheduler;
|
||||
|
||||
public BackgroundJobManager(
|
||||
ISchedulerFactory schedulerFactory,
|
||||
DataContext dataContext,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
ILogger<BackgroundJobManager> logger
|
||||
)
|
||||
{
|
||||
_schedulerFactory = schedulerFactory;
|
||||
_dataContext = dataContext;
|
||||
_scopeFactory = scopeFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -86,20 +86,24 @@ public class BackgroundJobManager : IHostedService
|
||||
throw new InvalidOperationException("Scheduler not initialized");
|
||||
}
|
||||
|
||||
// Use scoped DataContext to prevent memory leaks
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
await using var dataContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Get configurations from db
|
||||
QueueCleanerConfig queueCleanerConfig = await _dataContext.QueueCleanerConfigs
|
||||
QueueCleanerConfig queueCleanerConfig = await dataContext.QueueCleanerConfigs
|
||||
.AsNoTracking()
|
||||
.FirstAsync(cancellationToken);
|
||||
ContentBlockerConfig contentBlockerConfig = await _dataContext.ContentBlockerConfigs
|
||||
ContentBlockerConfig malwareBlockerConfig = await dataContext.ContentBlockerConfigs
|
||||
.AsNoTracking()
|
||||
.FirstAsync(cancellationToken);
|
||||
DownloadCleanerConfig downloadCleanerConfig = await _dataContext.DownloadCleanerConfigs
|
||||
DownloadCleanerConfig downloadCleanerConfig = await dataContext.DownloadCleanerConfigs
|
||||
.AsNoTracking()
|
||||
.FirstAsync(cancellationToken);
|
||||
|
||||
// Always register jobs, regardless of enabled status
|
||||
await RegisterQueueCleanerJob(queueCleanerConfig, cancellationToken);
|
||||
await RegisterContentBlockerJob(contentBlockerConfig, cancellationToken);
|
||||
await RegisterMalwareBlockerJob(malwareBlockerConfig, cancellationToken);
|
||||
await RegisterDownloadCleanerJob(downloadCleanerConfig, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -123,17 +127,17 @@ public class BackgroundJobManager : IHostedService
|
||||
/// <summary>
|
||||
/// Registers the QueueCleaner job and optionally adds triggers based on configuration.
|
||||
/// </summary>
|
||||
public async Task RegisterContentBlockerJob(
|
||||
public async Task RegisterMalwareBlockerJob(
|
||||
ContentBlockerConfig config,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Always register the job definition
|
||||
await AddJobWithoutTrigger<ContentBlocker>(cancellationToken);
|
||||
await AddJobWithoutTrigger<MalwareBlocker>(cancellationToken);
|
||||
|
||||
// Only add triggers if the job is enabled
|
||||
if (config.Enabled)
|
||||
{
|
||||
await AddTriggersForJob<ContentBlocker>(config, config.CronExpression, cancellationToken);
|
||||
await AddTriggersForJob<MalwareBlocker>(config, config.CronExpression, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +190,7 @@ public class BackgroundJobManager : IHostedService
|
||||
throw new ValidationException($"{cronExpression} should have a fire time of maximum {Constants.TriggerMaxLimit.TotalHours} hours");
|
||||
}
|
||||
|
||||
if (typeof(T) != typeof(ContentBlocker) && triggerValue < Constants.TriggerMinLimit)
|
||||
if (typeof(T) != typeof(MalwareBlocker) && triggerValue < Constants.TriggerMinLimit)
|
||||
{
|
||||
throw new ValidationException($"{cronExpression} should have a fire time of minimum {Constants.TriggerMinLimit.TotalSeconds} seconds");
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ public sealed class GenericJob<T> : IJob
|
||||
where T : IHandler
|
||||
{
|
||||
private readonly ILogger<GenericJob<T>> _logger;
|
||||
private readonly T _handler;
|
||||
|
||||
public GenericJob(ILogger<GenericJob<T>> logger, T handler)
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
public GenericJob(ILogger<GenericJob<T>> logger, IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_handler = handler;
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
@@ -23,7 +23,9 @@ public sealed class GenericJob<T> : IJob
|
||||
|
||||
try
|
||||
{
|
||||
await _handler.ExecuteAsync();
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
var handler = scope.ServiceProvider.GetRequiredService<T>();
|
||||
await handler.ExecuteAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -70,7 +70,7 @@ builder.Services.AddCors(options =>
|
||||
|
||||
// Register services needed for logging first
|
||||
builder.Services
|
||||
.AddTransient<LoggingConfigManager>()
|
||||
.AddScoped<LoggingConfigManager>()
|
||||
.AddSingleton<SignalRLogSink>();
|
||||
|
||||
// Add logging with proper service provider
|
||||
@@ -133,21 +133,25 @@ logger.LogInformation("Server configuration: PORT={port}, BASE_PATH={basePath}",
|
||||
await app.Init();
|
||||
|
||||
// Get LoggingConfigManager (will be created if not already registered)
|
||||
var configManager = app.Services.GetRequiredService<LoggingConfigManager>();
|
||||
|
||||
// Get the dynamic level switch for controlling log levels
|
||||
var levelSwitch = configManager.GetLevelSwitch();
|
||||
var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
|
||||
using (var scope = scopeFactory.CreateScope())
|
||||
{
|
||||
var configManager = scope.ServiceProvider.GetRequiredService<LoggingConfigManager>();
|
||||
|
||||
// Get the dynamic level switch for controlling log levels
|
||||
var levelSwitch = configManager.GetLevelSwitch();
|
||||
|
||||
// Get the SignalRLogSink instance
|
||||
var signalRSink = app.Services.GetRequiredService<SignalRLogSink>();
|
||||
// Get the SignalRLogSink instance
|
||||
var signalRSink = app.Services.GetRequiredService<SignalRLogSink>();
|
||||
|
||||
var logConfig = LoggingDI.GetDefaultLoggerConfiguration();
|
||||
logConfig.MinimumLevel.ControlledBy(levelSwitch);
|
||||
var logConfig = LoggingDI.GetDefaultLoggerConfiguration();
|
||||
logConfig.MinimumLevel.ControlledBy(levelSwitch);
|
||||
|
||||
// Add to Serilog pipeline
|
||||
logConfig.WriteTo.Sink(signalRSink);
|
||||
// Add to Serilog pipeline
|
||||
logConfig.WriteTo.Sink(signalRSink);
|
||||
|
||||
Log.Logger = logConfig.CreateLogger();
|
||||
Log.Logger = logConfig.CreateLogger();
|
||||
}
|
||||
|
||||
// Configure health check endpoints before the API configuration
|
||||
app.MapHealthChecks("/health", new HealthCheckOptions
|
||||
|
||||
@@ -61,8 +61,8 @@ public sealed class DownloadCleaner : GenericHandler
|
||||
|
||||
IReadOnlyList<string> ignoredDownloads = ContextProvider.Get<GeneralConfig>(nameof(GeneralConfig)).IgnoredDownloads;
|
||||
|
||||
// Process each client separately
|
||||
var allDownloads = new List<object>();
|
||||
var downloadServiceToDownloadsMap = new Dictionary<IDownloadService, List<object>>();
|
||||
|
||||
foreach (var downloadService in downloadServices)
|
||||
{
|
||||
try
|
||||
@@ -71,24 +71,24 @@ public sealed class DownloadCleaner : GenericHandler
|
||||
var clientDownloads = await downloadService.GetSeedingDownloads();
|
||||
if (clientDownloads?.Count > 0)
|
||||
{
|
||||
allDownloads.AddRange(clientDownloads);
|
||||
downloadServiceToDownloadsMap[downloadService] = clientDownloads;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to get seeding downloads from download client");
|
||||
_logger.LogError(ex, "Failed to get seeding downloads from download client {clientName}", downloadService.ClientConfig.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (allDownloads.Count == 0)
|
||||
if (downloadServiceToDownloadsMap.Count == 0)
|
||||
{
|
||||
_logger.LogDebug("no seeding downloads found");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogTrace("found {count} seeding downloads", allDownloads.Count);
|
||||
var totalDownloads = downloadServiceToDownloadsMap.Values.Sum(x => x.Count);
|
||||
_logger.LogTrace("found {count} seeding downloads across {clientCount} clients", totalDownloads, downloadServiceToDownloadsMap.Count);
|
||||
|
||||
// List<object>? downloadsToChangeCategory = null;
|
||||
List<Tuple<IDownloadService, List<object>>> downloadServiceWithDownloads = [];
|
||||
|
||||
if (isUnlinkedEnabled)
|
||||
@@ -102,24 +102,23 @@ public sealed class DownloadCleaner : GenericHandler
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to create category for download client");
|
||||
_logger.LogError(ex, "Failed to create category for download client {clientName}", downloadService.ClientConfig.Name);
|
||||
}
|
||||
}
|
||||
|
||||
// Get downloads to change category
|
||||
foreach (var downloadService in downloadServices)
|
||||
foreach (var (downloadService, clientDownloads) in downloadServiceToDownloadsMap)
|
||||
{
|
||||
try
|
||||
{
|
||||
var clientDownloads = downloadService.FilterDownloadsToChangeCategoryAsync(allDownloads, config.UnlinkedCategories);
|
||||
if (clientDownloads?.Count > 0)
|
||||
var downloadsToChangeCategory = downloadService.FilterDownloadsToChangeCategoryAsync(clientDownloads, config.UnlinkedCategories);
|
||||
if (downloadsToChangeCategory?.Count > 0)
|
||||
{
|
||||
downloadServiceWithDownloads.Add(Tuple.Create(downloadService, clientDownloads));
|
||||
downloadServiceWithDownloads.Add(Tuple.Create(downloadService, downloadsToChangeCategory));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to filter downloads for category change");
|
||||
_logger.LogError(ex, "Failed to filter downloads for category change for download client {clientName}", downloadService.ClientConfig.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,16 +157,15 @@ public sealed class DownloadCleaner : GenericHandler
|
||||
return;
|
||||
}
|
||||
|
||||
// Get downloads to clean
|
||||
downloadServiceWithDownloads = [];
|
||||
foreach (var downloadService in downloadServices)
|
||||
foreach (var (downloadService, clientDownloads) in downloadServiceToDownloadsMap)
|
||||
{
|
||||
try
|
||||
{
|
||||
var clientDownloads = downloadService.FilterDownloadsToBeCleanedAsync(allDownloads, config.Categories);
|
||||
if (clientDownloads?.Count > 0)
|
||||
var downloadsToClean = downloadService.FilterDownloadsToBeCleanedAsync(clientDownloads, config.Categories);
|
||||
if (downloadsToClean?.Count > 0)
|
||||
{
|
||||
downloadServiceWithDownloads.Add(Tuple.Create(downloadService, clientDownloads));
|
||||
downloadServiceWithDownloads.Add(Tuple.Create(downloadService, downloadsToClean));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -176,9 +174,6 @@ public sealed class DownloadCleaner : GenericHandler
|
||||
}
|
||||
}
|
||||
|
||||
// release unused objects
|
||||
allDownloads = null;
|
||||
|
||||
_logger.LogInformation("found {count} potential downloads to clean", downloadServiceWithDownloads.Sum(x => x.Item2.Count));
|
||||
|
||||
// Process cleaning for each client
|
||||
|
||||
@@ -3,29 +3,29 @@ using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.Arr;
|
||||
using Cleanuparr.Infrastructure.Features.Arr.Interfaces;
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient;
|
||||
using Cleanuparr.Infrastructure.Features.Jobs;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Helpers;
|
||||
using Cleanuparr.Persistence;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Cleanuparr.Persistence.Models.Configuration.Arr;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.General;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using LogContext = Serilog.Context.LogContext;
|
||||
|
||||
namespace Cleanuparr.Application.Features.ContentBlocker;
|
||||
namespace Cleanuparr.Application.Features.MalwareBlocker;
|
||||
|
||||
public sealed class ContentBlocker : GenericHandler
|
||||
public sealed class MalwareBlocker : GenericHandler
|
||||
{
|
||||
private readonly BlocklistProvider _blocklistProvider;
|
||||
|
||||
public ContentBlocker(
|
||||
ILogger<ContentBlocker> logger,
|
||||
public MalwareBlocker(
|
||||
ILogger<MalwareBlocker> logger,
|
||||
DataContext dataContext,
|
||||
IMemoryCache cache,
|
||||
IBus messageBus,
|
||||
@@ -66,27 +66,27 @@ public sealed class ContentBlocker : GenericHandler
|
||||
var readarrConfig = ContextProvider.Get<ArrConfig>(nameof(InstanceType.Readarr));
|
||||
var whisparrConfig = ContextProvider.Get<ArrConfig>(nameof(InstanceType.Whisparr));
|
||||
|
||||
if (config.Sonarr.Enabled)
|
||||
if (config.Sonarr.Enabled || config.DeleteKnownMalware)
|
||||
{
|
||||
await ProcessArrConfigAsync(sonarrConfig, InstanceType.Sonarr);
|
||||
}
|
||||
|
||||
if (config.Radarr.Enabled)
|
||||
if (config.Radarr.Enabled || config.DeleteKnownMalware)
|
||||
{
|
||||
await ProcessArrConfigAsync(radarrConfig, InstanceType.Radarr);
|
||||
}
|
||||
|
||||
if (config.Lidarr.Enabled)
|
||||
if (config.Lidarr.Enabled || config.DeleteKnownMalware)
|
||||
{
|
||||
await ProcessArrConfigAsync(lidarrConfig, InstanceType.Lidarr);
|
||||
}
|
||||
|
||||
if (config.Readarr.Enabled)
|
||||
if (config.Readarr.Enabled || config.DeleteKnownMalware)
|
||||
{
|
||||
await ProcessArrConfigAsync(readarrConfig, InstanceType.Readarr);
|
||||
}
|
||||
|
||||
if (config.Whisparr.Enabled)
|
||||
if (config.Whisparr.Enabled || config.DeleteKnownMalware)
|
||||
{
|
||||
await ProcessArrConfigAsync(whisparrConfig, InstanceType.Whisparr);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Request;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to the µTorrent Web UI API
|
||||
/// </summary>
|
||||
public sealed class UTorrentRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The API action to perform
|
||||
/// </summary>
|
||||
public string Action { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Authentication token (required for CSRF protection)
|
||||
/// </summary>
|
||||
public string Token { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Additional parameters for the request
|
||||
/// </summary>
|
||||
public List<(string Name, string Value)> Parameters { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the query string for the API call
|
||||
/// </summary>
|
||||
/// <returns>The complete query string including token and action</returns>
|
||||
public string ToQueryString()
|
||||
{
|
||||
var queryParams = new List<string>
|
||||
{
|
||||
$"token={Token}",
|
||||
Action
|
||||
};
|
||||
|
||||
foreach (var param in Parameters)
|
||||
{
|
||||
queryParams.Add($"{Uri.EscapeDataString(param.Name)}={Uri.EscapeDataString(param.Value)}");
|
||||
}
|
||||
|
||||
return string.Join("&", queryParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new request with the specified action
|
||||
/// </summary>
|
||||
/// <param name="action">The API action</param>
|
||||
/// <param name="token">Authentication token</param>
|
||||
/// <returns>A new UTorrentRequest instance</returns>
|
||||
public static UTorrentRequest Create(string action, string token)
|
||||
{
|
||||
return new UTorrentRequest
|
||||
{
|
||||
Action = action,
|
||||
Token = token
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a parameter to the request
|
||||
/// </summary>
|
||||
/// <param name="key">Parameter name</param>
|
||||
/// <param name="value">Parameter value</param>
|
||||
/// <returns>This instance for method chaining</returns>
|
||||
public UTorrentRequest WithParameter(string key, string value)
|
||||
{
|
||||
Parameters.Add((key, value));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Specific response type for file list API calls
|
||||
/// Replaces the generic UTorrentResponse<T> for file listings
|
||||
/// </summary>
|
||||
public sealed class FileListResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Raw file data from the API
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "files")]
|
||||
public object[]? FilesRaw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Torrent hash for which files are listed
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Parsed files as strongly-typed objects
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<UTorrentFile> Files { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Specific response type for label list API calls
|
||||
/// Replaces the generic UTorrentResponse<T> for label listings
|
||||
/// </summary>
|
||||
public sealed class LabelListResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Raw label data from the API
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "label")]
|
||||
public object[][]? LabelsRaw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parsed labels as string list
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<string> Labels { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Specific response type for torrent properties API calls
|
||||
/// Replaces the generic UTorrentResponse<T> for properties retrieval
|
||||
/// </summary>
|
||||
public sealed class PropertiesResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Raw properties data from the API
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "props")]
|
||||
public object[]? PropertiesRaw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parsed properties as strongly-typed object
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public UTorrentProperties Properties { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Specific response type for torrent list API calls
|
||||
/// Replaces the generic UTorrentResponse<T> for torrent listings
|
||||
/// </summary>
|
||||
public sealed class TorrentListResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// µTorrent build number
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "build")]
|
||||
public int Build { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of torrent data from the API
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "torrents")]
|
||||
public object[][]? TorrentsRaw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Label data from the API
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "label")]
|
||||
public object[][]? LabelsRaw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parsed torrents as strongly-typed objects
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<UTorrentItem> Torrents { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Parsed labels as string list
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<string> Labels { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a file within a torrent from µTorrent Web UI API
|
||||
/// Based on the files array structure from the API documentation
|
||||
/// </summary>
|
||||
public sealed class UTorrentFile
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public long Size { get; set; }
|
||||
|
||||
public long Downloaded { get; set; }
|
||||
|
||||
public int Priority { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a torrent from µTorrent Web UI API
|
||||
/// Based on the torrent array structure from the API documentation
|
||||
/// </summary>
|
||||
public sealed class UTorrentItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Torrent hash (index 0)
|
||||
/// </summary>
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Status bitfield (index 1)
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Torrent name (index 2)
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Total size in bytes (index 3)
|
||||
/// </summary>
|
||||
public long Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Progress in permille (1000 = 100%) (index 4)
|
||||
/// </summary>
|
||||
public int Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Downloaded bytes (index 5)
|
||||
/// </summary>
|
||||
public long Downloaded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Uploaded bytes (index 6)
|
||||
/// </summary>
|
||||
public long Uploaded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ratio * 1000 (index 7)
|
||||
/// </summary>
|
||||
public int RatioRaw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Upload speed in bytes/sec (index 8)
|
||||
/// </summary>
|
||||
public int UploadSpeed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Download speed in bytes/sec (index 9)
|
||||
/// </summary>
|
||||
public int DownloadSpeed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ETA in seconds (index 10)
|
||||
/// </summary>
|
||||
public int ETA { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Label (index 11)
|
||||
/// </summary>
|
||||
public string Label { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Connected peers (index 12)
|
||||
/// </summary>
|
||||
public int PeersConnected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Peers in swarm (index 13)
|
||||
/// </summary>
|
||||
public int PeersInSwarm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Connected seeds (index 14)
|
||||
/// </summary>
|
||||
public int SeedsConnected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Seeds in swarm (index 15)
|
||||
/// </summary>
|
||||
public int SeedsInSwarm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Availability (index 16)
|
||||
/// </summary>
|
||||
public int Availability { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Queue order (index 17)
|
||||
/// </summary>
|
||||
public int QueueOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remaining bytes (index 18)
|
||||
/// </summary>
|
||||
public long Remaining { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Download URL (index 19)
|
||||
/// </summary>
|
||||
public string DownloadUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// RSS feed URL (index 20)
|
||||
/// </summary>
|
||||
public string RssFeedUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Status message (index 21)
|
||||
/// </summary>
|
||||
public string StatusMessage { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Stream ID (index 22)
|
||||
/// </summary>
|
||||
public string StreamId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Date added as Unix timestamp (index 23)
|
||||
/// </summary>
|
||||
public long DateAdded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date completed as Unix timestamp (index 24)
|
||||
/// </summary>
|
||||
public long DateCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// App update URL (index 25)
|
||||
/// </summary>
|
||||
public string AppUpdateUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Save path (index 26)
|
||||
/// </summary>
|
||||
public string SavePath { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Calculated ratio value (RatioRaw / 1000.0)
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double Ratio => RatioRaw / 1000.0;
|
||||
|
||||
/// <summary>
|
||||
/// Progress as percentage (0.0 to 1.0)
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double ProgressPercent => Progress / 1000.0;
|
||||
|
||||
/// <summary>
|
||||
/// Date completed as DateTime (or null if not completed)
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DateTime? DateCompletedDateTime =>
|
||||
DateCompleted > 0 ? DateTimeOffset.FromUnixTimeSeconds(DateCompleted).DateTime : null;
|
||||
|
||||
/// <summary>
|
||||
/// Seeding time in seconds (calculated from DateCompleted to now)
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public TimeSpan? SeedingTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DateCompletedDateTime.HasValue)
|
||||
{
|
||||
return DateTime.UtcNow - DateCompletedDateTime.Value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Represents torrent properties from µTorrent Web UI API getprops action
|
||||
/// Based on the properties structure from the API documentation
|
||||
/// </summary>
|
||||
public sealed class UTorrentProperties
|
||||
{
|
||||
/// <summary>
|
||||
/// Torrent hash
|
||||
/// </summary>
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Trackers list (newlines are represented by \r\n)
|
||||
/// </summary>
|
||||
public string Trackers { get; set; } = string.Empty;
|
||||
|
||||
public List<string> TrackerList => Trackers
|
||||
.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => x.Trim())
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||
.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Upload limit in bytes per second
|
||||
/// </summary>
|
||||
public int UploadLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Download limit in bytes per second
|
||||
/// </summary>
|
||||
public int DownloadLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initial seeding / Super seeding
|
||||
/// -1 = Not allowed, 0 = Disabled, 1 = Enabled
|
||||
/// </summary>
|
||||
public int SuperSeed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use DHT
|
||||
/// -1 = Not allowed, 0 = Disabled, 1 = Enabled
|
||||
/// </summary>
|
||||
public int Dht { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use PEX (Peer Exchange)
|
||||
/// -1 = Not allowed (indicates private torrent), 0 = Disabled, 1 = Enabled
|
||||
/// </summary>
|
||||
public int Pex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Override queueing
|
||||
/// -1 = Not allowed, 0 = Disabled, 1 = Enabled
|
||||
/// </summary>
|
||||
public int SeedOverride { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Seed ratio in per mils (1000 = 1.0 ratio)
|
||||
/// </summary>
|
||||
public int SeedRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Seeding time in seconds
|
||||
/// 0 = No minimum seeding time
|
||||
/// </summary>
|
||||
public int SeedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Upload slots
|
||||
/// </summary>
|
||||
public int UploadSlots { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this torrent is private (based on PEX value)
|
||||
/// Private torrents have PEX = -1 (not allowed)
|
||||
/// </summary>
|
||||
public bool IsPrivate => Pex == -1;
|
||||
|
||||
/// <summary>
|
||||
/// Calculated seed ratio value (SeedRatio / 1000.0)
|
||||
/// </summary>
|
||||
public double SeedRatioValue => SeedRatio / 1000.0;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
/// <summary>
|
||||
/// Base response wrapper for µTorrent Web UI API calls
|
||||
/// </summary>
|
||||
public sealed record UTorrentResponse<T>
|
||||
{
|
||||
[JsonProperty(PropertyName = "build")]
|
||||
public int Build { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "label")]
|
||||
public object[][]? Labels { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "torrents")]
|
||||
public T? Torrents { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "torrentp")]
|
||||
public object[]? TorrentProperties { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "files")]
|
||||
public object[]? FilesDto { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<UTorrentFile>? Files
|
||||
{
|
||||
get
|
||||
{
|
||||
if (FilesDto is null || FilesDto.Length < 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var files = new List<UTorrentFile>();
|
||||
|
||||
if (FilesDto[1] is JArray jArray)
|
||||
{
|
||||
foreach (var jToken in jArray)
|
||||
{
|
||||
var fileTokenArray = (JArray)jToken;
|
||||
var fileArray = fileTokenArray.ToObject<object[]>() ?? [];
|
||||
files.Add(new UTorrentFile
|
||||
{
|
||||
Name = fileArray[0].ToString() ?? string.Empty,
|
||||
Size = Convert.ToInt64(fileArray[1]),
|
||||
Downloaded = Convert.ToInt64(fileArray[2]),
|
||||
Priority = Convert.ToInt32(fileArray[3]),
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "props")]
|
||||
public UTorrentProperties[]? Properties { get; set; }
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
public enum DownloadClientTypeName
|
||||
{
|
||||
QBittorrent,
|
||||
qBittorrent,
|
||||
Deluge,
|
||||
Transmission,
|
||||
}
|
||||
uTorrent,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Data.Models.Deluge.Exceptions;
|
||||
namespace Cleanuparr.Domain.Exceptions;
|
||||
|
||||
public class DelugeClientException : Exception
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Data.Models.Deluge.Exceptions;
|
||||
namespace Cleanuparr.Domain.Exceptions;
|
||||
|
||||
public sealed class DelugeLoginException : DelugeClientException
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Data.Models.Deluge.Exceptions;
|
||||
namespace Cleanuparr.Domain.Exceptions;
|
||||
|
||||
public sealed class DelugeLogoutException : DelugeClientException
|
||||
{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Cleanuparr.Domain.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Exception thrown when µTorrent authentication fails
|
||||
/// </summary>
|
||||
public class UTorrentAuthenticationException : UTorrentException
|
||||
{
|
||||
public UTorrentAuthenticationException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public UTorrentAuthenticationException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Cleanuparr.Domain.Exceptions;
|
||||
|
||||
public class UTorrentException : Exception
|
||||
{
|
||||
public UTorrentException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public UTorrentException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Cleanuparr.Domain.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Exception thrown when µTorrent response parsing fails
|
||||
/// </summary>
|
||||
public class UTorrentParsingException : UTorrentException
|
||||
{
|
||||
/// <summary>
|
||||
/// The raw response that failed to parse
|
||||
/// </summary>
|
||||
public string RawResponse { get; }
|
||||
|
||||
public UTorrentParsingException(string message, string rawResponse) : base(message)
|
||||
{
|
||||
RawResponse = rawResponse;
|
||||
}
|
||||
|
||||
public UTorrentParsingException(string message, string rawResponse, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
RawResponse = rawResponse;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
using System.Net;
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using Moq.Protected;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Tests.Verticals.DownloadClient;
|
||||
|
||||
public class UTorrentClientTests
|
||||
{
|
||||
private readonly UTorrentClient _client;
|
||||
private readonly Mock<HttpMessageHandler> _mockHttpHandler;
|
||||
private readonly DownloadClientConfig _config;
|
||||
private readonly Mock<IUTorrentAuthenticator> _mockAuthenticator;
|
||||
private readonly Mock<IUTorrentHttpService> _mockHttpService;
|
||||
private readonly Mock<IUTorrentResponseParser> _mockResponseParser;
|
||||
private readonly Mock<ILogger<UTorrentClient>> _mockLogger;
|
||||
|
||||
public UTorrentClientTests()
|
||||
{
|
||||
_mockHttpHandler = new Mock<HttpMessageHandler>();
|
||||
_mockAuthenticator = new Mock<IUTorrentAuthenticator>();
|
||||
_mockHttpService = new Mock<IUTorrentHttpService>();
|
||||
_mockResponseParser = new Mock<IUTorrentResponseParser>();
|
||||
_mockLogger = new Mock<ILogger<UTorrentClient>>();
|
||||
|
||||
_config = new DownloadClientConfig
|
||||
{
|
||||
Name = "test",
|
||||
Type = DownloadClientType.Torrent,
|
||||
TypeName = DownloadClientTypeName.uTorrent,
|
||||
Host = new Uri("http://localhost:8080"),
|
||||
Username = "admin",
|
||||
Password = "password"
|
||||
};
|
||||
|
||||
_client = new UTorrentClient(
|
||||
_config,
|
||||
_mockAuthenticator.Object,
|
||||
_mockHttpService.Object,
|
||||
_mockResponseParser.Object,
|
||||
_mockLogger.Object
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTorrentFilesAsync_ShouldDeserializeMixedArrayCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var mockResponse = new UTorrentResponse<object>
|
||||
{
|
||||
Build = 30470,
|
||||
FilesDto = new object[]
|
||||
{
|
||||
"F0616FB199B78254474AF6D72705177E71D713ED", // Hash (string)
|
||||
new object[] // File 1
|
||||
{
|
||||
"test name",
|
||||
2604L,
|
||||
0L,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
false,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
0
|
||||
},
|
||||
new object[] // File 2
|
||||
{
|
||||
"Dir1/Dir11/test11.zipx",
|
||||
2604L,
|
||||
0L,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
false,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
0
|
||||
},
|
||||
new object[] // File 3
|
||||
{
|
||||
"Dir1/sample.txt",
|
||||
2604L,
|
||||
0L,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
false,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
0
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Mock the token request
|
||||
var tokenResponse = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Content = new StringContent("<div id='token'>test-token</div>")
|
||||
};
|
||||
tokenResponse.Headers.Add("Set-Cookie", "GUID=test-guid; path=/");
|
||||
|
||||
// Mock the files request
|
||||
var filesResponse = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Content = new StringContent(JsonConvert.SerializeObject(mockResponse))
|
||||
};
|
||||
|
||||
// Setup mock to return different responses based on URL
|
||||
_mockHttpHandler
|
||||
.Protected()
|
||||
.Setup<Task<HttpResponseMessage>>("SendAsync",
|
||||
ItExpr.Is<HttpRequestMessage>(req => req.RequestUri!.AbsolutePath.Contains("token.html")),
|
||||
ItExpr.IsAny<CancellationToken>())
|
||||
.ReturnsAsync(tokenResponse);
|
||||
|
||||
_mockHttpHandler
|
||||
.Protected()
|
||||
.Setup<Task<HttpResponseMessage>>("SendAsync",
|
||||
ItExpr.Is<HttpRequestMessage>(req => req.RequestUri!.AbsolutePath.Contains("gui") && req.RequestUri.Query.Contains("action=getfiles")),
|
||||
ItExpr.IsAny<CancellationToken>())
|
||||
.ReturnsAsync(filesResponse);
|
||||
|
||||
// Act
|
||||
var files = await _client.GetTorrentFilesAsync("test-hash");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(files);
|
||||
Assert.Equal(3, files.Count);
|
||||
|
||||
Assert.Equal("test name", files[0].Name);
|
||||
Assert.Equal(2604L, files[0].Size);
|
||||
Assert.Equal(0L, files[0].Downloaded);
|
||||
Assert.Equal(2, files[0].Priority);
|
||||
Assert.Equal(0, files[0].Index);
|
||||
|
||||
Assert.Equal("Dir1/Dir11/test11.zipx", files[1].Name);
|
||||
Assert.Equal(2604L, files[1].Size);
|
||||
Assert.Equal(0L, files[1].Downloaded);
|
||||
Assert.Equal(2, files[1].Priority);
|
||||
Assert.Equal(1, files[1].Index);
|
||||
|
||||
Assert.Equal("Dir1/sample.txt", files[2].Name);
|
||||
Assert.Equal(2604L, files[2].Size);
|
||||
Assert.Equal(0L, files[2].Downloaded);
|
||||
Assert.Equal(2, files[2].Priority);
|
||||
Assert.Equal(2, files[2].Index);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTorrentFilesAsync_ShouldHandleEmptyResponse()
|
||||
{
|
||||
// Arrange
|
||||
var mockResponse = new UTorrentResponse<object>
|
||||
{
|
||||
Build = 30470,
|
||||
FilesDto = new object[]
|
||||
{
|
||||
"F0616FB199B78254474AF6D72705177E71D713ED" // Only hash, no files
|
||||
}
|
||||
};
|
||||
|
||||
// Mock the token request
|
||||
var tokenResponse = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Content = new StringContent("<div id='token'>test-token</div>")
|
||||
};
|
||||
tokenResponse.Headers.Add("Set-Cookie", "GUID=test-guid; path=/");
|
||||
|
||||
// Mock the files request
|
||||
var filesResponse = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Content = new StringContent(JsonConvert.SerializeObject(mockResponse))
|
||||
};
|
||||
|
||||
// Setup mock to return different responses based on URL
|
||||
_mockHttpHandler
|
||||
.Protected()
|
||||
.Setup<Task<HttpResponseMessage>>("SendAsync",
|
||||
ItExpr.Is<HttpRequestMessage>(req => req.RequestUri!.AbsolutePath.Contains("token.html")),
|
||||
ItExpr.IsAny<CancellationToken>())
|
||||
.ReturnsAsync(tokenResponse);
|
||||
|
||||
_mockHttpHandler
|
||||
.Protected()
|
||||
.Setup<Task<HttpResponseMessage>>("SendAsync",
|
||||
ItExpr.Is<HttpRequestMessage>(req => req.RequestUri!.AbsolutePath.Contains("gui") && req.RequestUri.Query.Contains("action=getfiles")),
|
||||
ItExpr.IsAny<CancellationToken>())
|
||||
.ReturnsAsync(filesResponse);
|
||||
|
||||
// Act
|
||||
var files = await _client.GetTorrentFilesAsync("test-hash");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(files);
|
||||
Assert.Empty(files);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTorrentFilesAsync_ShouldHandleNullResponse()
|
||||
{
|
||||
// Arrange
|
||||
var mockResponse = new UTorrentResponse<object>
|
||||
{
|
||||
Build = 30470,
|
||||
FilesDto = null
|
||||
};
|
||||
|
||||
// Mock the token request
|
||||
var tokenResponse = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Content = new StringContent("<div id='token'>test-token</div>")
|
||||
};
|
||||
tokenResponse.Headers.Add("Set-Cookie", "GUID=test-guid; path=/");
|
||||
|
||||
// Mock the files request
|
||||
var filesResponse = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Content = new StringContent(JsonConvert.SerializeObject(mockResponse))
|
||||
};
|
||||
|
||||
// Setup mock to return different responses based on URL
|
||||
_mockHttpHandler
|
||||
.Protected()
|
||||
.Setup<Task<HttpResponseMessage>>("SendAsync",
|
||||
ItExpr.Is<HttpRequestMessage>(req => req.RequestUri!.AbsolutePath.Contains("token.html")),
|
||||
ItExpr.IsAny<CancellationToken>())
|
||||
.ReturnsAsync(tokenResponse);
|
||||
|
||||
_mockHttpHandler
|
||||
.Protected()
|
||||
.Setup<Task<HttpResponseMessage>>("SendAsync",
|
||||
ItExpr.Is<HttpRequestMessage>(req => req.RequestUri!.AbsolutePath.Contains("gui") && req.RequestUri.Query.Contains("action=getfiles")),
|
||||
ItExpr.IsAny<CancellationToken>())
|
||||
.ReturnsAsync(filesResponse);
|
||||
|
||||
// Act
|
||||
var files = await _client.GetTorrentFilesAsync("test-hash");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(files);
|
||||
Assert.Empty(files);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Tests.Verticals.ContentBlocker;
|
||||
namespace Cleanuparr.Infrastructure.Tests.Verticals.MalwareBlocker;
|
||||
|
||||
public class FilenameEvaluatorFixture
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using Cleanuparr.Domain.Enums;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Tests.Verticals.ContentBlocker;
|
||||
namespace Cleanuparr.Infrastructure.Tests.Verticals.MalwareBlocker;
|
||||
|
||||
public class FilenameEvaluatorTests : IClassFixture<FilenameEvaluatorFixture>
|
||||
{
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FLM.QBittorrent" Version="1.0.1" />
|
||||
<PackageReference Include="FLM.QBittorrent" Version="1.0.3.1-alpha" />
|
||||
<PackageReference Include="FLM.Transmission" Version="1.0.3" />
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
<PackageReference Include="MassTransit.Abstractions" Version="8.4.1" />
|
||||
|
||||
@@ -11,15 +11,15 @@ namespace Cleanuparr.Infrastructure.Events;
|
||||
/// </summary>
|
||||
public class EventCleanupService : BackgroundService
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogger<EventCleanupService> _logger;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly TimeSpan _cleanupInterval = TimeSpan.FromHours(4); // Run every 4 hours
|
||||
private readonly int _retentionDays = 30; // Keep events for 30 days
|
||||
|
||||
public EventCleanupService(IServiceProvider serviceProvider, ILogger<EventCleanupService> logger)
|
||||
public EventCleanupService(ILogger<EventCleanupService> logger, IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_logger = logger;
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@@ -58,7 +58,7 @@ public class EventCleanupService : BackgroundService
|
||||
{
|
||||
try
|
||||
{
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
var context = scope.ServiceProvider.GetRequiredService<EventsContext>();
|
||||
|
||||
var cutoffDate = DateTime.UtcNow.AddDays(-_retentionDays);
|
||||
|
||||
@@ -4,7 +4,6 @@ using Cleanuparr.Domain.Entities.Deluge.Response;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient.Deluge.Extensions;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Data.Models.Deluge.Exceptions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.Deluge;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Cleanuparr.Domain.Entities.Deluge.Response;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.Files;
|
||||
using Cleanuparr.Infrastructure.Features.ItemStriker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Http;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Infrastructure.Interceptors;
|
||||
|
||||
@@ -4,7 +4,7 @@ using Cleanuparr.Domain.Entities.Deluge.Response;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Extensions;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.Deluge;
|
||||
@@ -35,9 +35,9 @@ public partial class DelugeService
|
||||
|
||||
result.IsPrivate = download.Private;
|
||||
|
||||
var contentBlockerConfig = ContextProvider.Get<ContentBlockerConfig>();
|
||||
var malwareBlockerConfig = ContextProvider.Get<ContentBlockerConfig>();
|
||||
|
||||
if (contentBlockerConfig.IgnorePrivate && download.Private)
|
||||
if (malwareBlockerConfig.IgnorePrivate && download.Private)
|
||||
{
|
||||
// ignore private trackers
|
||||
_logger.LogDebug("skip files check | download is private | {name}", download.Name);
|
||||
@@ -69,6 +69,7 @@ public partial class DelugeService
|
||||
BlocklistType blocklistType = _blocklistProvider.GetBlocklistType(instanceType);
|
||||
ConcurrentBag<string> patterns = _blocklistProvider.GetPatterns(instanceType);
|
||||
ConcurrentBag<Regex> regexes = _blocklistProvider.GetRegexes(instanceType);
|
||||
ConcurrentBag<string> malwarePatterns = _blocklistProvider.GetMalwarePatterns();
|
||||
|
||||
ProcessFiles(contents.Contents, (name, file) =>
|
||||
{
|
||||
@@ -80,7 +81,7 @@ public partial class DelugeService
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsDefinitelyMalware(name))
|
||||
if (malwareBlockerConfig.DeleteKnownMalware && _filenameEvaluator.IsKnownMalware(name, malwarePatterns))
|
||||
{
|
||||
_logger.LogInformation("malware file found | {file} | {title}", file.Path, download.Name);
|
||||
result.ShouldRemove = true;
|
||||
|
||||
@@ -2,10 +2,10 @@ using Cleanuparr.Domain.Entities;
|
||||
using Cleanuparr.Domain.Entities.Cache;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Infrastructure.Features.Files;
|
||||
using Cleanuparr.Infrastructure.Features.ItemStriker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Helpers;
|
||||
using Cleanuparr.Infrastructure.Http;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
@@ -100,16 +100,6 @@ public abstract class DownloadService : IDownloadService
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract Task<BlockFilesResult> BlockUnwantedFilesAsync(string hash, IReadOnlyList<string> ignoredDownloads);
|
||||
|
||||
protected bool IsDefinitelyMalware(string filename)
|
||||
{
|
||||
if (filename.Contains("thepirateheaven.org", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void ResetStalledStrikesOnProgress(string hash, long downloaded)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.Files;
|
||||
using Cleanuparr.Infrastructure.Features.ItemStriker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Http;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Infrastructure.Interceptors;
|
||||
@@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging;
|
||||
using DelugeService = Cleanuparr.Infrastructure.Features.DownloadClient.Deluge.DelugeService;
|
||||
using QBitService = Cleanuparr.Infrastructure.Features.DownloadClient.QBittorrent.QBitService;
|
||||
using TransmissionService = Cleanuparr.Infrastructure.Features.DownloadClient.Transmission.TransmissionService;
|
||||
using UTorrentService = Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent.UTorrentService;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient;
|
||||
|
||||
@@ -20,12 +21,13 @@ namespace Cleanuparr.Infrastructure.Features.DownloadClient;
|
||||
/// </summary>
|
||||
public sealed class DownloadServiceFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogger<DownloadServiceFactory> _logger;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public DownloadServiceFactory(
|
||||
IServiceProvider serviceProvider,
|
||||
ILogger<DownloadServiceFactory> logger)
|
||||
ILogger<DownloadServiceFactory> logger,
|
||||
IServiceProvider serviceProvider
|
||||
)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_logger = logger;
|
||||
@@ -45,9 +47,10 @@ public sealed class DownloadServiceFactory
|
||||
|
||||
return downloadClientConfig.TypeName switch
|
||||
{
|
||||
DownloadClientTypeName.QBittorrent => CreateQBitService(downloadClientConfig),
|
||||
DownloadClientTypeName.qBittorrent => CreateQBitService(downloadClientConfig),
|
||||
DownloadClientTypeName.Deluge => CreateDelugeService(downloadClientConfig),
|
||||
DownloadClientTypeName.Transmission => CreateTransmissionService(downloadClientConfig),
|
||||
DownloadClientTypeName.uTorrent => CreateUTorrentService(downloadClientConfig),
|
||||
_ => throw new NotSupportedException($"Download client type {downloadClientConfig.TypeName} is not supported")
|
||||
};
|
||||
}
|
||||
@@ -114,4 +117,26 @@ public sealed class DownloadServiceFactory
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
private UTorrentService CreateUTorrentService(DownloadClientConfig downloadClientConfig)
|
||||
{
|
||||
var logger = _serviceProvider.GetRequiredService<ILogger<UTorrentService>>();
|
||||
var cache = _serviceProvider.GetRequiredService<IMemoryCache>();
|
||||
var filenameEvaluator = _serviceProvider.GetRequiredService<IFilenameEvaluator>();
|
||||
var striker = _serviceProvider.GetRequiredService<IStriker>();
|
||||
var dryRunInterceptor = _serviceProvider.GetRequiredService<IDryRunInterceptor>();
|
||||
var hardLinkFileService = _serviceProvider.GetRequiredService<IHardLinkFileService>();
|
||||
var httpClientProvider = _serviceProvider.GetRequiredService<IDynamicHttpClientProvider>();
|
||||
var eventPublisher = _serviceProvider.GetRequiredService<EventPublisher>();
|
||||
var blocklistProvider = _serviceProvider.GetRequiredService<BlocklistProvider>();
|
||||
var loggerFactory = _serviceProvider.GetRequiredService<ILoggerFactory>();
|
||||
|
||||
// Create the UTorrentService instance
|
||||
UTorrentService service = new(
|
||||
logger, cache, filenameEvaluator, striker, dryRunInterceptor,
|
||||
hardLinkFileService, httpClientProvider, eventPublisher, blocklistProvider, downloadClientConfig, loggerFactory
|
||||
);
|
||||
|
||||
return service;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.Files;
|
||||
using Cleanuparr.Infrastructure.Features.ItemStriker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Http;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Infrastructure.Interceptors;
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Text.RegularExpressions;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Extensions;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using QBittorrent.Client;
|
||||
|
||||
@@ -39,7 +39,7 @@ public partial class QBitService
|
||||
|
||||
if (torrentProperties is null)
|
||||
{
|
||||
_logger.LogDebug("failed to find torrent properties {name}", download.Name);
|
||||
_logger.LogError("Failed to find torrent properties {name}", download.Name);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ public partial class QBitService
|
||||
|
||||
result.IsPrivate = isPrivate;
|
||||
|
||||
var contentBlockerConfig = ContextProvider.Get<ContentBlockerConfig>();
|
||||
var malwareBlockerConfig = ContextProvider.Get<ContentBlockerConfig>();
|
||||
|
||||
if (contentBlockerConfig.IgnorePrivate && isPrivate)
|
||||
if (malwareBlockerConfig.IgnorePrivate && isPrivate)
|
||||
{
|
||||
// ignore private trackers
|
||||
_logger.LogDebug("skip files check | download is private | {name}", download.Name);
|
||||
@@ -60,9 +60,9 @@ public partial class QBitService
|
||||
|
||||
IReadOnlyList<TorrentContent>? files = await _client.GetTorrentContentsAsync(hash);
|
||||
|
||||
if (files is null)
|
||||
if (files?.Count is null or 0)
|
||||
{
|
||||
_logger.LogDebug("torrent {hash} has no files", hash);
|
||||
_logger.LogDebug("skip files check | no files found | {name}", download.Name);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ public partial class QBitService
|
||||
BlocklistType blocklistType = _blocklistProvider.GetBlocklistType(instanceType);
|
||||
ConcurrentBag<string> patterns = _blocklistProvider.GetPatterns(instanceType);
|
||||
ConcurrentBag<Regex> regexes = _blocklistProvider.GetRegexes(instanceType);
|
||||
ConcurrentBag<string> malwarePatterns = _blocklistProvider.GetMalwarePatterns();
|
||||
|
||||
foreach (TorrentContent file in files)
|
||||
{
|
||||
@@ -85,7 +86,7 @@ public partial class QBitService
|
||||
|
||||
totalFiles++;
|
||||
|
||||
if (IsDefinitelyMalware(file.Name))
|
||||
if (malwareBlockerConfig.DeleteKnownMalware && _filenameEvaluator.IsKnownMalware(file.Name, malwarePatterns))
|
||||
{
|
||||
_logger.LogInformation("malware file found | {file} | {title}", file.Name, download.Name);
|
||||
result.ShouldRemove = true;
|
||||
|
||||
@@ -12,7 +12,7 @@ public partial class QBitService
|
||||
/// <inheritdoc/>
|
||||
public override async Task<List<object>?> GetSeedingDownloads()
|
||||
{
|
||||
var torrentList = await _client.GetTorrentListAsync(new TorrentListQuery { Filter = TorrentListFilter.Seeding });
|
||||
var torrentList = await _client.GetTorrentListAsync(new TorrentListQuery { Filter = TorrentListFilter.Completed });
|
||||
return torrentList?.Where(x => !string.IsNullOrEmpty(x.Hash))
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
@@ -97,7 +97,7 @@ public partial class QBitService
|
||||
|
||||
if (torrentProperties is null)
|
||||
{
|
||||
_logger.LogDebug("failed to find torrent properties | {name}", download.Name);
|
||||
_logger.LogError("Failed to find torrent properties | {name}", download.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public partial class QBitService
|
||||
|
||||
if (torrentProperties is null)
|
||||
{
|
||||
_logger.LogDebug("failed to find torrent properties {hash}", download.Name);
|
||||
_logger.LogError("Failed to find torrent properties for {name}", download.Name);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -89,32 +89,32 @@ public partial class QBitService
|
||||
|
||||
if (queueCleanerConfig.Slow.MaxStrikes is 0)
|
||||
{
|
||||
_logger.LogDebug("skip slow check | max strikes is 0 | {name}", download.Name);
|
||||
_logger.LogTrace("skip slow check | max strikes is 0 | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (download.State is not (TorrentState.Downloading or TorrentState.ForcedDownload))
|
||||
{
|
||||
_logger.LogDebug("skip slow check | download is in {state} state | {name}", download.State, download.Name);
|
||||
_logger.LogTrace("skip slow check | download is in {state} state | {name}", download.State, download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (download.DownloadSpeed <= 0)
|
||||
{
|
||||
_logger.LogDebug("skip slow check | download speed is 0 | {name}", download.Name);
|
||||
_logger.LogTrace("skip slow check | download speed is 0 | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (queueCleanerConfig.Slow.IgnorePrivate && isPrivate)
|
||||
{
|
||||
// ignore private trackers
|
||||
_logger.LogDebug("skip slow check | download is private | {name}", download.Name);
|
||||
_logger.LogTrace("skip slow check | download is private | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (download.Size > (queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue))
|
||||
{
|
||||
_logger.LogDebug("skip slow check | download is too large | {name}", download.Name);
|
||||
_logger.LogTrace("skip slow check | download is too large | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public partial class QBitService
|
||||
|
||||
if (queueCleanerConfig.Stalled.MaxStrikes is 0 && queueCleanerConfig.Stalled.DownloadingMetadataMaxStrikes is 0)
|
||||
{
|
||||
_logger.LogDebug("skip stalled check | max strikes is 0 | {name}", torrent.Name);
|
||||
_logger.LogTrace("skip stalled check | max strikes is 0 | {name}", torrent.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public partial class QBitService
|
||||
and not TorrentState.ForcedFetchingMetadata)
|
||||
{
|
||||
// ignore other states
|
||||
_logger.LogDebug("skip stalled check | download is in {state} state | {name}", torrent.State, torrent.Name);
|
||||
_logger.LogTrace("skip stalled check | download is in {state} state | {name}", torrent.State, torrent.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public partial class QBitService
|
||||
if (queueCleanerConfig.Stalled.IgnorePrivate && isPrivate)
|
||||
{
|
||||
// ignore private trackers
|
||||
_logger.LogDebug("skip stalled check | download is private | {name}", torrent.Name);
|
||||
_logger.LogTrace("skip stalled check | download is private | {name}", torrent.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -175,7 +175,7 @@ public partial class QBitService
|
||||
StrikeType.DownloadingMetadata), DeleteReason.DownloadingMetadata);
|
||||
}
|
||||
|
||||
_logger.LogDebug("skip stalled check | download is not stalled | {name}", torrent.Name);
|
||||
_logger.LogTrace("skip stalled check | download is not stalled | {name}", torrent.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
using Cleanuparr.Infrastructure.Features.Files;
|
||||
using Cleanuparr.Infrastructure.Features.ItemStriker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Http;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Infrastructure.Interceptors;
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Text.RegularExpressions;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Extensions;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Transmission.API.RPC.Entity;
|
||||
|
||||
@@ -40,9 +40,9 @@ public partial class TransmissionService
|
||||
bool isPrivate = download.IsPrivate ?? false;
|
||||
result.IsPrivate = isPrivate;
|
||||
|
||||
var contentBlockerConfig = ContextProvider.Get<ContentBlockerConfig>();
|
||||
var malwareBlockerConfig = ContextProvider.Get<ContentBlockerConfig>();
|
||||
|
||||
if (contentBlockerConfig.IgnorePrivate && isPrivate)
|
||||
if (malwareBlockerConfig.IgnorePrivate && isPrivate)
|
||||
{
|
||||
// ignore private trackers
|
||||
_logger.LogDebug("skip files check | download is private | {name}", download.Name);
|
||||
@@ -57,6 +57,7 @@ public partial class TransmissionService
|
||||
BlocklistType blocklistType = _blocklistProvider.GetBlocklistType(instanceType);
|
||||
ConcurrentBag<string> patterns = _blocklistProvider.GetPatterns(instanceType);
|
||||
ConcurrentBag<Regex> regexes = _blocklistProvider.GetRegexes(instanceType);
|
||||
ConcurrentBag<string> malwarePatterns = _blocklistProvider.GetMalwarePatterns();
|
||||
|
||||
for (int i = 0; i < download.Files.Length; i++)
|
||||
{
|
||||
@@ -68,7 +69,7 @@ public partial class TransmissionService
|
||||
|
||||
totalFiles++;
|
||||
|
||||
if (IsDefinitelyMalware(download.Files[i].Name))
|
||||
if (malwareBlockerConfig.DeleteKnownMalware && _filenameEvaluator.IsKnownMalware(download.Files[i].Name, malwarePatterns))
|
||||
{
|
||||
_logger.LogInformation("malware file found | {file} | {title}", download.Files[i].Name, download.Name);
|
||||
result.ShouldRemove = true;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
using Cleanuparr.Infrastructure.Services;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for µTorrent entities and status checking
|
||||
/// </summary>
|
||||
public static class UTorrentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the torrent is currently seeding
|
||||
/// </summary>
|
||||
public static bool IsSeeding(this UTorrentItem item)
|
||||
{
|
||||
return IsDownloading(item.Status) && item.DateCompleted > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the torrent is currently downloading
|
||||
/// </summary>
|
||||
public static bool IsDownloading(this UTorrentItem item)
|
||||
{
|
||||
return IsDownloading(item.Status);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the status indicates downloading
|
||||
/// </summary>
|
||||
public static bool IsDownloading(int status)
|
||||
{
|
||||
return (status & UTorrentStatus.Started) != 0 &&
|
||||
(status & UTorrentStatus.Checked) != 0 &&
|
||||
(status & UTorrentStatus.Error) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a torrent should be ignored based on the ignored patterns
|
||||
/// </summary>
|
||||
public static bool ShouldIgnore(this UTorrentItem download, IReadOnlyList<string> ignoredDownloads)
|
||||
{
|
||||
foreach (string value in ignoredDownloads)
|
||||
{
|
||||
if (download.Hash.Equals(value, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (download.Label.Equals(value, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool ShouldIgnore(this string tracker, IReadOnlyList<string> ignoredDownloads)
|
||||
{
|
||||
string? trackerUrl = UriService.GetDomain(tracker);
|
||||
|
||||
if (trackerUrl is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (string value in ignoredDownloads)
|
||||
{
|
||||
if (trackerUrl.EndsWith(value, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for µTorrent authentication management with caching support
|
||||
/// Handles token management and session state with multi-client support
|
||||
/// </summary>
|
||||
public interface IUTorrentAuthenticator
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures that the client is authenticated and the token is valid
|
||||
/// </summary>
|
||||
/// <returns>True if authentication is successful</returns>
|
||||
Task<bool> EnsureAuthenticatedAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid authentication token, refreshing if necessary
|
||||
/// </summary>
|
||||
/// <returns>Valid authentication token</returns>
|
||||
Task<string> GetValidTokenAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid GUID cookie, refreshing if necessary
|
||||
/// </summary>
|
||||
/// <returns>Valid GUID cookie</returns>
|
||||
Task<string> GetValidGuidCookieAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Forces a refresh of the authentication session
|
||||
/// </summary>
|
||||
Task RefreshSessionAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Invalidates the cached authentication session
|
||||
/// </summary>
|
||||
Task InvalidateSessionAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the client is currently authenticated
|
||||
/// </summary>
|
||||
bool IsAuthenticated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the GUID cookie for the current session
|
||||
/// </summary>
|
||||
string GuidCookie { get; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Request;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for raw HTTP communication with µTorrent Web UI API
|
||||
/// Handles low-level HTTP requests and authentication token retrieval
|
||||
/// </summary>
|
||||
public interface IUTorrentHttpService
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends a raw HTTP request to the µTorrent API
|
||||
/// </summary>
|
||||
/// <param name="request">The request to send</param>
|
||||
/// <param name="guidCookie">The GUID cookie for authentication</param>
|
||||
/// <returns>Raw JSON response from the API</returns>
|
||||
Task<string> SendRawRequestAsync(UTorrentRequest request, string guidCookie);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves authentication token and GUID cookie from µTorrent
|
||||
/// </summary>
|
||||
/// <returns>Tuple containing the authentication token and GUID cookie</returns>
|
||||
Task<(string token, string guidCookie)> GetTokenAndCookieAsync();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for parsing µTorrent API responses
|
||||
/// Provides endpoint-specific parsing methods for different response types
|
||||
/// </summary>
|
||||
public interface IUTorrentResponseParser
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses a torrent list response from JSON
|
||||
/// </summary>
|
||||
/// <param name="json">Raw JSON response from the API</param>
|
||||
/// <returns>Parsed torrent list response</returns>
|
||||
TorrentListResponse ParseTorrentList(string json);
|
||||
|
||||
/// <summary>
|
||||
/// Parses a file list response from JSON
|
||||
/// </summary>
|
||||
/// <param name="json">Raw JSON response from the API</param>
|
||||
/// <returns>Parsed file list response</returns>
|
||||
FileListResponse ParseFileList(string json);
|
||||
|
||||
/// <summary>
|
||||
/// Parses a properties response from JSON
|
||||
/// </summary>
|
||||
/// <param name="json">Raw JSON response from the API</param>
|
||||
/// <returns>Parsed properties response</returns>
|
||||
PropertiesResponse ParseProperties(string json);
|
||||
|
||||
/// <summary>
|
||||
/// Parses a label list response from JSON
|
||||
/// </summary>
|
||||
/// <param name="json">Raw JSON response from the API</param>
|
||||
/// <returns>Parsed label list response</returns>
|
||||
LabelListResponse ParseLabelList(string json);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for µTorrent download service
|
||||
/// </summary>
|
||||
public interface IUTorrentService : IDownloadService
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Represents cached authentication data for a µTorrent client instance
|
||||
/// </summary>
|
||||
public sealed class UTorrentAuthCache
|
||||
{
|
||||
public string AuthToken { get; init; } = string.Empty;
|
||||
public string GuidCookie { get; init; } = string.Empty;
|
||||
public DateTime CreatedAt { get; init; }
|
||||
public DateTime ExpiresAt { get; init; }
|
||||
|
||||
public bool IsValid => DateTime.UtcNow < ExpiresAt &&
|
||||
!string.IsNullOrEmpty(AuthToken) &&
|
||||
!string.IsNullOrEmpty(GuidCookie);
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
using Cleanuparr.Infrastructure.Helpers;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Cleanuparr.Shared.Helpers;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of µTorrent authentication management with IMemoryCache-based token sharing
|
||||
/// Handles concurrent authentication requests and provides thread-safe token caching per client
|
||||
/// </summary>
|
||||
public class UTorrentAuthenticator : IUTorrentAuthenticator
|
||||
{
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly IUTorrentHttpService _httpService;
|
||||
private readonly DownloadClientConfig _config;
|
||||
private readonly ILogger<UTorrentAuthenticator> _logger;
|
||||
|
||||
// Use a static concurrent dictionary to ensure same client instances share the same semaphore
|
||||
// This prevents multiple instances of the same client from authenticating simultaneously
|
||||
private readonly SemaphoreSlim _authSemaphore;
|
||||
private readonly string _clientKey;
|
||||
|
||||
// Cache configuration - conservative timings to avoid token expiration issues
|
||||
private static readonly TimeSpan TokenExpiryDuration = TimeSpan.FromMinutes(20);
|
||||
private static readonly TimeSpan CacheAbsoluteExpiration = TimeSpan.FromMinutes(25);
|
||||
|
||||
public UTorrentAuthenticator(
|
||||
IMemoryCache cache,
|
||||
IUTorrentHttpService httpService,
|
||||
DownloadClientConfig config,
|
||||
ILogger<UTorrentAuthenticator> logger)
|
||||
{
|
||||
_cache = cache;
|
||||
_httpService = httpService;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
|
||||
// Create unique client key based on connection details
|
||||
// This ensures different µTorrent instances don't share auth tokens
|
||||
_clientKey = GetClientKey();
|
||||
|
||||
// Get or create semaphore for this specific client configuration
|
||||
if (_cache.TryGetValue<SemaphoreSlim>(_clientKey, out var authSemaphore) && authSemaphore is not null)
|
||||
{
|
||||
_authSemaphore = authSemaphore;
|
||||
return;
|
||||
}
|
||||
|
||||
_authSemaphore = new SemaphoreSlim(1, 1);
|
||||
_cache.Set(_clientKey, _authSemaphore, Constants.DefaultCacheEntryOptions);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsAuthenticated
|
||||
{
|
||||
get
|
||||
{
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
return _cache.TryGetValue(cacheKey, out UTorrentAuthCache? cachedAuth) &&
|
||||
cachedAuth?.IsValid == true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string GuidCookie
|
||||
{
|
||||
get
|
||||
{
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
if (_cache.TryGetValue(cacheKey, out UTorrentAuthCache? cachedAuth) &&
|
||||
cachedAuth?.IsValid == true)
|
||||
{
|
||||
return cachedAuth.GuidCookie;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<bool> EnsureAuthenticatedAsync()
|
||||
{
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
|
||||
// Fast path: Check if we have valid cached auth
|
||||
if (_cache.TryGetValue(cacheKey, out UTorrentAuthCache? cachedAuth) &&
|
||||
cachedAuth?.IsValid == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Slow path: Need to refresh authentication with concurrency control
|
||||
return await RefreshAuthenticationWithLockAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<string> GetValidTokenAsync()
|
||||
{
|
||||
if (!await EnsureAuthenticatedAsync())
|
||||
{
|
||||
throw new UTorrentAuthenticationException($"Failed to authenticate with µTorrent client '{_config.Name}'");
|
||||
}
|
||||
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
if (_cache.TryGetValue(cacheKey, out UTorrentAuthCache? cachedAuth) &&
|
||||
cachedAuth?.IsValid == true)
|
||||
{
|
||||
return cachedAuth.AuthToken;
|
||||
}
|
||||
|
||||
throw new UTorrentAuthenticationException($"Authentication token not available for µTorrent client '{_config.Name}'");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<string> GetValidGuidCookieAsync()
|
||||
{
|
||||
if (!await EnsureAuthenticatedAsync())
|
||||
{
|
||||
throw new UTorrentAuthenticationException($"Failed to authenticate with µTorrent client '{_config.Name}'");
|
||||
}
|
||||
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
if (_cache.TryGetValue(cacheKey, out UTorrentAuthCache? cachedAuth) &&
|
||||
cachedAuth?.IsValid == true)
|
||||
{
|
||||
return cachedAuth.GuidCookie;
|
||||
}
|
||||
|
||||
throw new UTorrentAuthenticationException($"GUID cookie not available for µTorrent client '{_config.Name}'");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task RefreshSessionAsync()
|
||||
{
|
||||
const int maxRetries = 3;
|
||||
var retryCount = 0;
|
||||
var backoffDelay = TimeSpan.FromMilliseconds(500);
|
||||
|
||||
while (retryCount < maxRetries)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (token, guidCookie) = await _httpService.GetTokenAndCookieAsync();
|
||||
|
||||
var authCache = new UTorrentAuthCache
|
||||
{
|
||||
AuthToken = token,
|
||||
GuidCookie = guidCookie,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ExpiresAt = DateTime.UtcNow.Add(TokenExpiryDuration)
|
||||
};
|
||||
|
||||
// Cache with both sliding and absolute expiration
|
||||
var cacheOptions = new MemoryCacheEntryOptions
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = CacheAbsoluteExpiration,
|
||||
SlidingExpiration = TokenExpiryDuration,
|
||||
Priority = CacheItemPriority.High
|
||||
};
|
||||
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
_cache.Set(cacheKey, authCache, cacheOptions);
|
||||
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) when (retryCount < maxRetries - 1)
|
||||
{
|
||||
retryCount++;
|
||||
_logger.LogWarning(ex, "Authentication attempt {Attempt} failed for µTorrent client '{ClientName}', retrying in {Delay}ms",
|
||||
retryCount, _config.Name, backoffDelay.TotalMilliseconds);
|
||||
|
||||
await Task.Delay(backoffDelay);
|
||||
backoffDelay = TimeSpan.FromMilliseconds(backoffDelay.TotalMilliseconds * 1.5); // Exponential backoff
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Invalidate any existing cache entry on failure
|
||||
await InvalidateSessionAsync();
|
||||
throw new UTorrentAuthenticationException($"Failed to refresh authentication session after {maxRetries} attempts: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task InvalidateSessionAsync()
|
||||
{
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
_cache.Remove(cacheKey);
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes authentication with concurrency control to prevent multiple simultaneous auth requests
|
||||
/// </summary>
|
||||
private async Task<bool> RefreshAuthenticationWithLockAsync()
|
||||
{
|
||||
var cacheKey = CacheKeys.UTorrent.GetAuthTokenKey(_clientKey);
|
||||
|
||||
// Wait for our turn to authenticate (per client instance)
|
||||
await _authSemaphore.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
// Double-check: another thread might have refreshed while we were waiting
|
||||
if (_cache.TryGetValue(cacheKey, out UTorrentAuthCache? cachedAuth) &&
|
||||
cachedAuth?.IsValid == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Actually refresh the authentication
|
||||
await RefreshSessionAsync();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to refresh authentication for µTorrent client '{ClientName}'", _config.Name);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_authSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a unique client key based on connection details
|
||||
/// This ensures different µTorrent instances don't share auth tokens
|
||||
/// </summary>
|
||||
private string GetClientKey()
|
||||
{
|
||||
return _config.Url.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Request;
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
public sealed class UTorrentClient
|
||||
{
|
||||
private readonly DownloadClientConfig _config;
|
||||
private readonly IUTorrentAuthenticator _authenticator;
|
||||
private readonly IUTorrentHttpService _httpService;
|
||||
private readonly IUTorrentResponseParser _responseParser;
|
||||
private readonly ILogger<UTorrentClient> _logger;
|
||||
|
||||
public UTorrentClient(
|
||||
DownloadClientConfig config,
|
||||
IUTorrentAuthenticator authenticator,
|
||||
IUTorrentHttpService httpService,
|
||||
IUTorrentResponseParser responseParser,
|
||||
ILogger<UTorrentClient> logger
|
||||
)
|
||||
{
|
||||
_config = config;
|
||||
_authenticator = authenticator;
|
||||
_httpService = httpService;
|
||||
_responseParser = responseParser;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Authenticates with µTorrent and retrieves the authentication token
|
||||
/// </summary>
|
||||
/// <returns>True if authentication was successful</returns>
|
||||
public async Task<bool> LoginAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Use the cache-aware authentication
|
||||
var token = await _authenticator.GetValidTokenAsync();
|
||||
return !string.IsNullOrEmpty(token);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Login failed for µTorrent client '{ClientName}'", _config.Name);
|
||||
throw new UTorrentException($"Failed to authenticate with µTorrent: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the authentication and basic API connectivity
|
||||
/// </summary>
|
||||
/// <returns>True if authentication and basic API call works</returns>
|
||||
public async Task<bool> TestConnectionAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var torrents = await GetTorrentsAsync();
|
||||
return true; // If we can get torrents, authentication is working
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all torrents from µTorrent
|
||||
/// </summary>
|
||||
/// <returns>List of torrents</returns>
|
||||
public async Task<List<UTorrentItem>> GetTorrentsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = UTorrentRequestFactory.CreateTorrentListRequest();
|
||||
var json = await SendAuthenticatedRequestAsync(request);
|
||||
var response = _responseParser.ParseTorrentList(json);
|
||||
return response.Torrents;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to get torrents from µTorrent client '{ClientName}'", _config.Name);
|
||||
throw new UTorrentException($"Failed to get torrents: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific torrent by hash
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <returns>The torrent or null if not found</returns>
|
||||
public async Task<UTorrentItem?> GetTorrentAsync(string hash)
|
||||
{
|
||||
try
|
||||
{
|
||||
var torrents = await GetTorrentsAsync();
|
||||
return torrents.FirstOrDefault(t =>
|
||||
string.Equals(t.Hash, hash, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to get torrent {Hash} from µTorrent client '{ClientName}'", hash, _config.Name);
|
||||
throw new UTorrentException($"Failed to get torrent {hash}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets files for a specific torrent
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <returns>List of files in the torrent</returns>
|
||||
public async Task<List<UTorrentFile>?> GetTorrentFilesAsync(string hash)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = UTorrentRequestFactory.CreateFileListRequest(hash);
|
||||
var json = await SendAuthenticatedRequestAsync(request);
|
||||
var response = _responseParser.ParseFileList(json);
|
||||
return response.Files;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to get files for torrent {Hash} from µTorrent client '{ClientName}'", hash, _config.Name);
|
||||
throw new UTorrentException($"Failed to get files for torrent {hash}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets torrent properties including private/public status
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <returns>UTorrentProperties object or null if not found</returns>
|
||||
public async Task<UTorrentProperties> GetTorrentPropertiesAsync(string hash)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = UTorrentRequestFactory.CreatePropertiesRequest(hash);
|
||||
var json = await SendAuthenticatedRequestAsync(request);
|
||||
var response = _responseParser.ParseProperties(json);
|
||||
return response.Properties;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to get properties for torrent {Hash} from µTorrent client '{ClientName}'", hash, _config.Name);
|
||||
throw new UTorrentException($"Failed to get properties for torrent {hash}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all labels from µTorrent
|
||||
/// </summary>
|
||||
/// <returns>List of label names</returns>
|
||||
public async Task<List<string>> GetLabelsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = UTorrentRequestFactory.CreateLabelListRequest();
|
||||
var json = await SendAuthenticatedRequestAsync(request);
|
||||
var response = _responseParser.ParseLabelList(json);
|
||||
return response.Labels;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to get labels from µTorrent client '{ClientName}'", _config.Name);
|
||||
throw new UTorrentException($"Failed to get labels: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the label for a torrent
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <param name="label">Label to set</param>
|
||||
public async Task SetTorrentLabelAsync(string hash, string label)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = UTorrentRequestFactory.CreateSetLabelRequest(hash, label);
|
||||
await SendAuthenticatedRequestAsync(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to set label '{Label}' for torrent {Hash} in µTorrent client '{ClientName}'", label, hash, _config.Name);
|
||||
throw new UTorrentException($"Failed to set label '{label}' for torrent {hash}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets file priorities for a torrent
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <param name="fileIndexes">Index of the file to set priority for</param>
|
||||
/// <param name="priority">File priority (0=skip, 1=low, 2=normal, 3=high)</param>
|
||||
public async Task SetFilesPriorityAsync(string hash, List<int> fileIndexes, int priority)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = UTorrentRequestFactory.CreateSetFilePrioritiesRequest(hash, fileIndexes, priority);
|
||||
await SendAuthenticatedRequestAsync(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to set file priority for torrent {Hash} in µTorrent client '{ClientName}'", hash, _config.Name);
|
||||
throw new UTorrentException($"Failed to set file priority for torrent {hash}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes torrents from µTorrent
|
||||
/// </summary>
|
||||
/// <param name="hashes">List of torrent hashes to remove</param>
|
||||
public async Task RemoveTorrentsAsync(List<string> hashes)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var hash in hashes)
|
||||
{
|
||||
var request = UTorrentRequestFactory.CreateRemoveTorrentWithDataRequest(hash);
|
||||
await SendAuthenticatedRequestAsync(request);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to remove torrents from µTorrent client '{ClientName}'", _config.Name);
|
||||
throw new UTorrentException($"Failed to remove torrents: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new label in µTorrent
|
||||
/// </summary>
|
||||
/// <param name="label">Label name to create</param>
|
||||
public static async Task CreateLabel(string label)
|
||||
{
|
||||
// µTorrent doesn't have an explicit "create label" API
|
||||
// Labels are created automatically when you assign them to a torrent
|
||||
// So this is a no-op for µTorrent
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an authenticated request to the µTorrent API
|
||||
/// Handles automatic authentication and retry logic
|
||||
/// </summary>
|
||||
/// <param name="request">The request to send</param>
|
||||
/// <returns>Raw JSON response from the API</returns>
|
||||
private async Task<string> SendAuthenticatedRequestAsync(UTorrentRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get valid token and cookie from cache-aware authenticator
|
||||
var token = await _authenticator.GetValidTokenAsync();
|
||||
var guidCookie = await _authenticator.GetValidGuidCookieAsync();
|
||||
|
||||
request.Token = token;
|
||||
|
||||
return await _httpService.SendRawRequestAsync(request, guidCookie);
|
||||
}
|
||||
catch (UTorrentAuthenticationException)
|
||||
{
|
||||
// On authentication failure, invalidate cache and retry once
|
||||
try
|
||||
{
|
||||
await _authenticator.InvalidateSessionAsync();
|
||||
var token = await _authenticator.GetValidTokenAsync();
|
||||
var guidCookie = await _authenticator.GetValidGuidCookieAsync();
|
||||
|
||||
request.Token = token;
|
||||
|
||||
return await _httpService.SendRawRequestAsync(request, guidCookie);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Authentication retry failed for µTorrent client '{ClientName}'", _config.Name);
|
||||
throw new UTorrentAuthenticationException($"Authentication retry failed: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Request;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of HTTP service for µTorrent Web UI API communication
|
||||
/// Handles low-level HTTP requests and authentication token retrieval
|
||||
/// </summary>
|
||||
public class UTorrentHttpService : IUTorrentHttpService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly DownloadClientConfig _config;
|
||||
private readonly ILogger<UTorrentHttpService> _logger;
|
||||
|
||||
// Regex pattern to extract token from µTorrent Web UI HTML
|
||||
private static readonly Regex TokenRegex = new(@"<div[^>]*id=['""]token['""][^>]*>([^<]+)</div>",
|
||||
RegexOptions.IgnoreCase);
|
||||
|
||||
public UTorrentHttpService(
|
||||
HttpClient httpClient,
|
||||
DownloadClientConfig config,
|
||||
ILogger<UTorrentHttpService> logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<string> SendRawRequestAsync(UTorrentRequest request, string guidCookie)
|
||||
{
|
||||
if (string.IsNullOrEmpty(guidCookie))
|
||||
{
|
||||
throw new UTorrentAuthenticationException("GUID cookie is required for API requests");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var queryString = request.ToQueryString();
|
||||
UriBuilder uriBuilder = new UriBuilder(_config.Url)
|
||||
{
|
||||
Query = queryString
|
||||
};
|
||||
uriBuilder.Path = $"{uriBuilder.Path.TrimEnd('/')}/gui/";
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, uriBuilder.Uri);
|
||||
httpRequest.Headers.Add("Cookie", guidCookie);
|
||||
|
||||
var credentials = Convert.ToBase64String(
|
||||
Encoding.UTF8.GetBytes($"{_config.Username}:{_config.Password}"));
|
||||
httpRequest.Headers.Add("Authorization", $"Basic {credentials}");
|
||||
|
||||
var response = await _httpClient.SendAsync(httpRequest);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
_logger.LogError("UTorrent API request failed: {StatusCode} - {Content}", response.StatusCode, errorContent);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
throw new UTorrentAuthenticationException("Authentication failed - invalid credentials or token expired");
|
||||
}
|
||||
|
||||
throw new UTorrentException($"HTTP request failed: {response.StatusCode} - {errorContent}");
|
||||
}
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (string.IsNullOrEmpty(jsonResponse))
|
||||
{
|
||||
throw new UTorrentException("Empty response received from µTorrent API");
|
||||
}
|
||||
|
||||
return jsonResponse;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "HTTP request failed for UTorrent API: {Action}", request.Action);
|
||||
throw new UTorrentException($"HTTP request failed: {ex.Message}", ex);
|
||||
}
|
||||
catch (TaskCanceledException ex)
|
||||
{
|
||||
_logger.LogError(ex, "HTTP request timeout for UTorrent API: {Action}", request.Action);
|
||||
throw new UTorrentException($"HTTP request timeout: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<(string token, string guidCookie)> GetTokenAndCookieAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
UriBuilder uriBuilder = new UriBuilder(_config.Url);
|
||||
uriBuilder.Path = $"{uriBuilder.Path.TrimEnd('/')}/gui/token.html";
|
||||
|
||||
var credentials = Convert.ToBase64String(
|
||||
Encoding.UTF8.GetBytes($"{_config.Username}:{_config.Password}"));
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, uriBuilder.Uri);
|
||||
request.Headers.Add("Authorization", $"Basic {credentials}");
|
||||
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
_logger.LogError("Failed to retrieve authentication token: {StatusCode} - {Content}",
|
||||
response.StatusCode, errorContent);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
throw new UTorrentAuthenticationException("Authentication failed - check username and password");
|
||||
}
|
||||
|
||||
throw new UTorrentException($"Token retrieval failed: {response.StatusCode} - {errorContent}");
|
||||
}
|
||||
|
||||
var html = await response.Content.ReadAsStringAsync();
|
||||
|
||||
// Extract token from HTML
|
||||
var tokenMatch = TokenRegex.Match(html);
|
||||
if (!tokenMatch.Success)
|
||||
{
|
||||
_logger.LogError("Failed to extract token from HTML response: {Html}", html);
|
||||
throw new UTorrentAuthenticationException("Failed to extract authentication token from response");
|
||||
}
|
||||
|
||||
var token = tokenMatch.Groups[1].Value;
|
||||
|
||||
// Extract GUID from cookies
|
||||
var guidCookie = ExtractGuidCookie(response.Headers);
|
||||
|
||||
if (string.IsNullOrEmpty(guidCookie))
|
||||
{
|
||||
throw new UTorrentAuthenticationException("Failed to extract GUID cookie from response");
|
||||
}
|
||||
|
||||
return (token, guidCookie);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "HTTP request failed while retrieving authentication token");
|
||||
throw new UTorrentAuthenticationException($"Token retrieval failed: {ex.Message}", ex);
|
||||
}
|
||||
catch (TaskCanceledException ex)
|
||||
{
|
||||
_logger.LogError(ex, "HTTP request timeout while retrieving authentication token");
|
||||
throw new UTorrentAuthenticationException($"Token retrieval timeout: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the GUID cookie from HTTP response headers
|
||||
/// </summary>
|
||||
/// <param name="headers">HTTP response headers</param>
|
||||
/// <returns>GUID cookie string or empty string if not found</returns>
|
||||
private static string ExtractGuidCookie(System.Net.Http.Headers.HttpResponseHeaders headers)
|
||||
{
|
||||
if (!headers.TryGetValues("Set-Cookie", out var cookies))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
foreach (var cookie in cookies)
|
||||
{
|
||||
if (cookie.Contains("GUID="))
|
||||
{
|
||||
return cookie.Split(';')[0]; // Get just the GUID part, ignore expires, path, etc.
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Request;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Factory for creating type-safe UTorrent API requests
|
||||
/// Provides specific methods for each supported API endpoint
|
||||
/// </summary>
|
||||
public static class UTorrentRequestFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a request to get the list of all torrents
|
||||
/// </summary>
|
||||
/// <returns>Request for torrent list API call</returns>
|
||||
public static UTorrentRequest CreateTorrentListRequest()
|
||||
{
|
||||
return UTorrentRequest.Create("list=1", string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a request to get files for a specific torrent
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <returns>Request for file list API call</returns>
|
||||
public static UTorrentRequest CreateFileListRequest(string hash)
|
||||
{
|
||||
return UTorrentRequest.Create("action=getfiles", string.Empty)
|
||||
.WithParameter("hash", hash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a request to get properties for a specific torrent
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <returns>Request for properties API call</returns>
|
||||
public static UTorrentRequest CreatePropertiesRequest(string hash)
|
||||
{
|
||||
return UTorrentRequest.Create("action=getprops", string.Empty)
|
||||
.WithParameter("hash", hash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a request to get all labels
|
||||
/// </summary>
|
||||
/// <returns>Request for label list API call</returns>
|
||||
public static UTorrentRequest CreateLabelListRequest()
|
||||
{
|
||||
return UTorrentRequest.Create("list=1", string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a request to remove a torrent and its data
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <returns>Request for remove torrent with data API call</returns>
|
||||
public static UTorrentRequest CreateRemoveTorrentWithDataRequest(string hash)
|
||||
{
|
||||
return UTorrentRequest.Create("action=removedatatorrent", string.Empty)
|
||||
.WithParameter("hash", hash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a request to set file priorities for a torrent
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <param name="fileIndexes"></param>
|
||||
/// <param name="filePriority"></param>
|
||||
/// <returns>Request for set file priorities API call</returns>
|
||||
public static UTorrentRequest CreateSetFilePrioritiesRequest(string hash, List<int> fileIndexes, int filePriority)
|
||||
{
|
||||
var request = UTorrentRequest.Create("action=setprio", string.Empty)
|
||||
.WithParameter("hash", hash)
|
||||
.WithParameter("p", filePriority.ToString());
|
||||
|
||||
foreach (int fileIndex in fileIndexes)
|
||||
{
|
||||
request.WithParameter("f", fileIndex.ToString());
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a request to set a torrent's label
|
||||
/// </summary>
|
||||
/// <param name="hash">Torrent hash</param>
|
||||
/// <param name="label">Label to set</param>
|
||||
/// <returns>Request for set label API call</returns>
|
||||
public static UTorrentRequest CreateSetLabelRequest(string hash, string label)
|
||||
{
|
||||
return UTorrentRequest.Create("action=setprops", string.Empty)
|
||||
.WithParameter("hash", hash)
|
||||
.WithParameter("s", "label")
|
||||
.WithParameter("v", label);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of µTorrent response parser
|
||||
/// Handles endpoint-specific parsing of API responses with proper error handling
|
||||
/// </summary>
|
||||
public class UTorrentResponseParser : IUTorrentResponseParser
|
||||
{
|
||||
private readonly ILogger<UTorrentResponseParser> _logger;
|
||||
|
||||
public UTorrentResponseParser(ILogger<UTorrentResponseParser> logger)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TorrentListResponse ParseTorrentList(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<TorrentListResponse>(json);
|
||||
|
||||
if (response == null)
|
||||
{
|
||||
throw new UTorrentParsingException("Failed to deserialize torrent list response", json);
|
||||
}
|
||||
|
||||
// Parse torrents
|
||||
if (response.TorrentsRaw != null)
|
||||
{
|
||||
foreach (var data in response.TorrentsRaw)
|
||||
{
|
||||
if (data is { Length: >= 27 })
|
||||
{
|
||||
response.Torrents.Add(new UTorrentItem
|
||||
{
|
||||
Hash = data[0].ToString() ?? string.Empty,
|
||||
Status = Convert.ToInt32(data[1]),
|
||||
Name = data[2].ToString() ?? string.Empty,
|
||||
Size = Convert.ToInt64(data[3]),
|
||||
Progress = Convert.ToInt32(data[4]),
|
||||
Downloaded = Convert.ToInt64(data[5]),
|
||||
Uploaded = Convert.ToInt64(data[6]),
|
||||
RatioRaw = Convert.ToInt32(data[7]),
|
||||
UploadSpeed = Convert.ToInt32(data[8]),
|
||||
DownloadSpeed = Convert.ToInt32(data[9]),
|
||||
ETA = Convert.ToInt32(data[10]),
|
||||
Label = data[11].ToString() ?? string.Empty,
|
||||
PeersConnected = Convert.ToInt32(data[12]),
|
||||
PeersInSwarm = Convert.ToInt32(data[13]),
|
||||
SeedsConnected = Convert.ToInt32(data[14]),
|
||||
SeedsInSwarm = Convert.ToInt32(data[15]),
|
||||
Availability = Convert.ToInt32(data[16]),
|
||||
QueueOrder = Convert.ToInt32(data[17]),
|
||||
Remaining = Convert.ToInt64(data[18]),
|
||||
DownloadUrl = data[19].ToString() ?? string.Empty,
|
||||
RssFeedUrl = data[20].ToString() ?? string.Empty,
|
||||
StatusMessage = data[21].ToString() ?? string.Empty,
|
||||
StreamId = data[22].ToString() ?? string.Empty,
|
||||
DateAdded = Convert.ToInt64(data[23]),
|
||||
DateCompleted = Convert.ToInt64(data[24]),
|
||||
AppUpdateUrl = data[25].ToString() ?? string.Empty,
|
||||
SavePath = data[26].ToString() ?? string.Empty
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse labels
|
||||
if (response.LabelsRaw != null)
|
||||
{
|
||||
foreach (var labelData in response.LabelsRaw)
|
||||
{
|
||||
if (labelData is { Length: > 0 })
|
||||
{
|
||||
var labelName = labelData[0].ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(labelName))
|
||||
{
|
||||
response.Labels.Add(labelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to parse torrent list JSON response");
|
||||
throw new UTorrentParsingException($"Failed to parse torrent list response: {ex.Message}", json, ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error parsing torrent list response");
|
||||
throw new UTorrentParsingException($"Unexpected error parsing torrent list response: {ex.Message}", json, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public FileListResponse ParseFileList(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var rawResponse = JsonConvert.DeserializeObject<FileListResponse>(json);
|
||||
|
||||
if (rawResponse == null)
|
||||
{
|
||||
throw new UTorrentParsingException("Failed to deserialize file list response", json);
|
||||
}
|
||||
|
||||
var response = new FileListResponse();
|
||||
|
||||
// Parse files from the nested array structure
|
||||
if (rawResponse.FilesRaw is { Length: >= 2 })
|
||||
{
|
||||
response.Hash = rawResponse.FilesRaw[0].ToString() ?? string.Empty;
|
||||
|
||||
if (rawResponse.FilesRaw[1] is JArray jArray)
|
||||
{
|
||||
foreach (var jToken in jArray)
|
||||
{
|
||||
if (jToken is JArray fileArray)
|
||||
{
|
||||
var fileData = fileArray.ToObject<object[]>() ?? Array.Empty<object>();
|
||||
|
||||
if (fileData.Length >= 4)
|
||||
{
|
||||
response.Files.Add(new UTorrentFile
|
||||
{
|
||||
Name = fileData[0]?.ToString() ?? string.Empty,
|
||||
Size = Convert.ToInt64(fileData[1]),
|
||||
Downloaded = Convert.ToInt64(fileData[2]),
|
||||
Priority = Convert.ToInt32(fileData[3]),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to parse file list JSON response");
|
||||
throw new UTorrentParsingException($"Failed to parse file list response: {ex.Message}", json, ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error parsing file list response");
|
||||
throw new UTorrentParsingException($"Unexpected error parsing file list response: {ex.Message}", json, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PropertiesResponse ParseProperties(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var rawResponse = JsonConvert.DeserializeObject<PropertiesResponse>(json);
|
||||
|
||||
if (rawResponse == null)
|
||||
{
|
||||
throw new UTorrentParsingException("Failed to deserialize properties response", json);
|
||||
}
|
||||
|
||||
var response = new PropertiesResponse();
|
||||
|
||||
// Parse properties from the array structure
|
||||
if (rawResponse.PropertiesRaw is { Length: > 0 })
|
||||
{
|
||||
response.Properties = JsonConvert.DeserializeObject<UTorrentProperties>(rawResponse.PropertiesRaw.FirstOrDefault()?.ToString());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to parse properties JSON response");
|
||||
throw new UTorrentParsingException($"Failed to parse properties response: {ex.Message}", json, ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error parsing properties response");
|
||||
throw new UTorrentParsingException($"Unexpected error parsing properties response: {ex.Message}", json, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public LabelListResponse ParseLabelList(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<LabelListResponse>(json);
|
||||
|
||||
if (response == null)
|
||||
{
|
||||
throw new UTorrentParsingException("Failed to deserialize label list response", json);
|
||||
}
|
||||
|
||||
// Parse labels
|
||||
if (response.LabelsRaw != null)
|
||||
{
|
||||
foreach (var labelData in response.LabelsRaw)
|
||||
{
|
||||
if (labelData is { Length: > 0 })
|
||||
{
|
||||
var labelName = labelData[0]?.ToString();
|
||||
if (!string.IsNullOrEmpty(labelName))
|
||||
{
|
||||
response.Labels.Add(labelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to parse label list JSON response");
|
||||
throw new UTorrentParsingException($"Failed to parse label list response: {ex.Message}", json, ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error parsing label list response");
|
||||
throw new UTorrentParsingException($"Unexpected error parsing label list response: {ex.Message}", json, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using Cleanuparr.Infrastructure.Events;
|
||||
using Cleanuparr.Infrastructure.Features.Files;
|
||||
using Cleanuparr.Infrastructure.Features.ItemStriker;
|
||||
using Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
using Cleanuparr.Infrastructure.Http;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Infrastructure.Interceptors;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// µTorrent download service implementation
|
||||
/// Provides business logic layer on top of UTorrentClient
|
||||
/// </summary>
|
||||
public partial class UTorrentService : DownloadService, IUTorrentService
|
||||
{
|
||||
private readonly UTorrentClient _client;
|
||||
|
||||
public UTorrentService(
|
||||
ILogger<UTorrentService> logger,
|
||||
IMemoryCache cache,
|
||||
IFilenameEvaluator filenameEvaluator,
|
||||
IStriker striker,
|
||||
IDryRunInterceptor dryRunInterceptor,
|
||||
IHardLinkFileService hardLinkFileService,
|
||||
IDynamicHttpClientProvider httpClientProvider,
|
||||
EventPublisher eventPublisher,
|
||||
BlocklistProvider blocklistProvider,
|
||||
DownloadClientConfig downloadClientConfig,
|
||||
ILoggerFactory loggerFactory
|
||||
) : base(
|
||||
logger, cache,
|
||||
filenameEvaluator, striker, dryRunInterceptor, hardLinkFileService,
|
||||
httpClientProvider, eventPublisher, blocklistProvider, downloadClientConfig
|
||||
)
|
||||
{
|
||||
// Create the new layered client with dependency injection
|
||||
var httpService = new UTorrentHttpService(_httpClient, downloadClientConfig, loggerFactory.CreateLogger<UTorrentHttpService>());
|
||||
var authenticator = new UTorrentAuthenticator(
|
||||
cache,
|
||||
httpService,
|
||||
downloadClientConfig,
|
||||
loggerFactory.CreateLogger<UTorrentAuthenticator>()
|
||||
);
|
||||
var responseParser = new UTorrentResponseParser(loggerFactory.CreateLogger<UTorrentResponseParser>());
|
||||
|
||||
_client = new UTorrentClient(
|
||||
downloadClientConfig,
|
||||
authenticator,
|
||||
httpService,
|
||||
responseParser,
|
||||
loggerFactory.CreateLogger<UTorrentClient>()
|
||||
);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Authenticates with µTorrent Web UI
|
||||
/// </summary>
|
||||
public override async Task LoginAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var loginSuccess = await _client.LoginAsync();
|
||||
|
||||
if (!loginSuccess)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to authenticate with µTorrent Web UI");
|
||||
}
|
||||
|
||||
_logger.LogDebug("Successfully logged in to µTorrent client {clientId}", _downloadClientConfig.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to login to µTorrent client {clientId}", _downloadClientConfig.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs health check for µTorrent service
|
||||
/// </summary>
|
||||
public override async Task<HealthCheckResult> HealthCheckAsync()
|
||||
{
|
||||
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
|
||||
try
|
||||
{
|
||||
// Test authentication and basic connectivity
|
||||
await _client.LoginAsync();
|
||||
|
||||
// Test API connectivity with a simple request
|
||||
var connectionOk = await _client.TestConnectionAsync();
|
||||
if (!connectionOk)
|
||||
{
|
||||
throw new InvalidOperationException("API connection test failed");
|
||||
}
|
||||
|
||||
_logger.LogDebug("Health check: Successfully connected to µTorrent client {clientId}", _downloadClientConfig.Id);
|
||||
|
||||
stopwatch.Stop();
|
||||
|
||||
return new HealthCheckResult
|
||||
{
|
||||
IsHealthy = true,
|
||||
ResponseTime = stopwatch.Elapsed
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
stopwatch.Stop();
|
||||
|
||||
_logger.LogError(ex, "Health check failed for µTorrent client {clientId}", _downloadClientConfig.Id);
|
||||
|
||||
return new HealthCheckResult
|
||||
{
|
||||
IsHealthy = false,
|
||||
ResponseTime = stopwatch.Elapsed,
|
||||
ErrorMessage = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.RegularExpressions;
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Extensions;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent.Extensions;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
public partial class UTorrentService
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override async Task<BlockFilesResult> BlockUnwantedFilesAsync(string hash, IReadOnlyList<string> ignoredDownloads)
|
||||
{
|
||||
hash = hash.ToLowerInvariant();
|
||||
|
||||
UTorrentItem? download = await _client.GetTorrentAsync(hash);
|
||||
BlockFilesResult result = new();
|
||||
|
||||
if (download?.Hash is null)
|
||||
{
|
||||
_logger.LogDebug("Failed to find torrent {hash} in the download client", hash);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.Found = true;
|
||||
|
||||
var properties = await _client.GetTorrentPropertiesAsync(hash);
|
||||
result.IsPrivate = properties.IsPrivate;
|
||||
|
||||
if (ignoredDownloads.Count > 0 &&
|
||||
(download.ShouldIgnore(ignoredDownloads) || properties.TrackerList.Any(x => x.ShouldIgnore(ignoredDownloads))))
|
||||
{
|
||||
_logger.LogInformation("skip | download is ignored | {name}", download.Name);
|
||||
return result;
|
||||
}
|
||||
|
||||
var malwareBlockerConfig = ContextProvider.Get<ContentBlockerConfig>();
|
||||
|
||||
if (malwareBlockerConfig.IgnorePrivate && result.IsPrivate)
|
||||
{
|
||||
// ignore private trackers
|
||||
_logger.LogDebug("skip files check | download is private | {name}", download.Name);
|
||||
return result;
|
||||
}
|
||||
|
||||
List<UTorrentFile>? files = await _client.GetTorrentFilesAsync(hash);
|
||||
|
||||
if (files?.Count is null or 0)
|
||||
{
|
||||
_logger.LogDebug("skip files check | no files found | {name}", download.Name);
|
||||
return result;
|
||||
}
|
||||
|
||||
List<int> fileIndexes = new(files.Count);
|
||||
long totalUnwantedFiles = 0;
|
||||
|
||||
InstanceType instanceType = (InstanceType)ContextProvider.Get<object>(nameof(InstanceType));
|
||||
BlocklistType blocklistType = _blocklistProvider.GetBlocklistType(instanceType);
|
||||
ConcurrentBag<string> patterns = _blocklistProvider.GetPatterns(instanceType);
|
||||
ConcurrentBag<Regex> regexes = _blocklistProvider.GetRegexes(instanceType);
|
||||
ConcurrentBag<string> malwarePatterns = _blocklistProvider.GetMalwarePatterns();
|
||||
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
if (malwareBlockerConfig.DeleteKnownMalware && _filenameEvaluator.IsKnownMalware(files[i].Name, malwarePatterns))
|
||||
{
|
||||
_logger.LogInformation("malware file found | {file} | {title}", files[i].Name, download.Name);
|
||||
result.ShouldRemove = true;
|
||||
result.DeleteReason = DeleteReason.MalwareFileFound;
|
||||
return result;
|
||||
}
|
||||
|
||||
var file = files[i];
|
||||
|
||||
if (file.Priority == 0) // Already skipped
|
||||
{
|
||||
totalUnwantedFiles++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file.Priority != 0 && !_filenameEvaluator.IsValid(file.Name, blocklistType, patterns, regexes))
|
||||
{
|
||||
totalUnwantedFiles++;
|
||||
fileIndexes.Add(i);
|
||||
_logger.LogInformation("unwanted file found | {file}", file.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (fileIndexes.Count is 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
_logger.LogDebug("changing priorities | torrent {hash}", hash);
|
||||
|
||||
if (totalUnwantedFiles == files.Count)
|
||||
{
|
||||
_logger.LogDebug("All files are blocked for {name}", download.Name);
|
||||
result.ShouldRemove = true;
|
||||
result.DeleteReason = DeleteReason.AllFilesBlocked;
|
||||
}
|
||||
|
||||
await _dryRunInterceptor.InterceptAsync(ChangeFilesPriority, hash, fileIndexes);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual async Task ChangeFilesPriority(string hash, List<int> fileIndexes)
|
||||
{
|
||||
await _client.SetFilesPriorityAsync(hash, fileIndexes, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Extensions;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent.Extensions;
|
||||
using Cleanuparr.Persistence.Models.Configuration.DownloadCleaner;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
public partial class UTorrentService
|
||||
{
|
||||
public override async Task<List<object>?> GetSeedingDownloads()
|
||||
{
|
||||
var torrents = await _client.GetTorrentsAsync();
|
||||
return torrents
|
||||
.Where(x => !string.IsNullOrEmpty(x.Hash))
|
||||
.Where(x => x.IsSeeding())
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public override List<object>? FilterDownloadsToBeCleanedAsync(List<object>? downloads, List<CleanCategory> categories) =>
|
||||
downloads
|
||||
?.Cast<UTorrentItem>()
|
||||
.Where(x => categories.Any(cat => cat.Name.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase)))
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
|
||||
public override List<object>? FilterDownloadsToChangeCategoryAsync(List<object>? downloads, List<string> categories) =>
|
||||
downloads
|
||||
?.Cast<UTorrentItem>()
|
||||
.Where(x => !string.IsNullOrEmpty(x.Hash))
|
||||
.Where(x => categories.Any(cat => cat.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase)))
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task CleanDownloadsAsync(List<object>? downloads, List<CleanCategory> categoriesToClean, HashSet<string> excludedHashes,
|
||||
IReadOnlyList<string> ignoredDownloads)
|
||||
{
|
||||
if (downloads?.Count is null or 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (UTorrentItem download in downloads.Cast<UTorrentItem>())
|
||||
{
|
||||
if (string.IsNullOrEmpty(download.Hash))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
_logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
var properties = await _client.GetTorrentPropertiesAsync(download.Hash);
|
||||
|
||||
if (ignoredDownloads.Count > 0 &&
|
||||
(download.ShouldIgnore(ignoredDownloads) || properties.TrackerList.Any(x => x.ShouldIgnore(ignoredDownloads))))
|
||||
{
|
||||
_logger.LogInformation("skip | download is ignored | {name}", download.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
CleanCategory? category = categoriesToClean
|
||||
.FirstOrDefault(x => x.Name.Equals(download.Label, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (category is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var downloadCleanerConfig = ContextProvider.Get<DownloadCleanerConfig>(nameof(DownloadCleanerConfig));
|
||||
|
||||
if (!downloadCleanerConfig.DeletePrivate && properties.IsPrivate)
|
||||
{
|
||||
_logger.LogDebug("skip | download is private | {name}", download.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
ContextProvider.Set("downloadName", download.Name);
|
||||
ContextProvider.Set("hash", download.Hash);
|
||||
|
||||
TimeSpan? seedingTime = download.SeedingTime;
|
||||
if (seedingTime == null)
|
||||
{
|
||||
_logger.LogDebug("skip | could not determine seeding time | {name}", download.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
SeedingCheckResult result = ShouldCleanDownload(download.Ratio, seedingTime.Value, category);
|
||||
|
||||
if (!result.ShouldClean)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await _dryRunInterceptor.InterceptAsync(DeleteDownload, download.Hash);
|
||||
|
||||
_logger.LogInformation(
|
||||
"download cleaned | {reason} reached | {name}",
|
||||
result.Reason is CleanReason.MaxRatioReached
|
||||
? "MAX_RATIO & MIN_SEED_TIME"
|
||||
: "MAX_SEED_TIME",
|
||||
download.Name
|
||||
);
|
||||
|
||||
await _eventPublisher.PublishDownloadCleaned(download.Ratio, seedingTime.Value, category.Name, result.Reason);
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task CreateCategoryAsync(string name)
|
||||
{
|
||||
var existingLabels = await _client.GetLabelsAsync();
|
||||
|
||||
if (existingLabels.Contains(name, StringComparer.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("Creating category {name}", name);
|
||||
|
||||
await _dryRunInterceptor.InterceptAsync(CreateLabel, name);
|
||||
}
|
||||
|
||||
public override async Task ChangeCategoryForNoHardLinksAsync(List<object>? downloads, HashSet<string> excludedHashes, IReadOnlyList<string> ignoredDownloads)
|
||||
{
|
||||
if (downloads?.Count is null or 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var downloadCleanerConfig = ContextProvider.Get<DownloadCleanerConfig>(nameof(DownloadCleanerConfig));
|
||||
|
||||
if (!string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir))
|
||||
{
|
||||
_hardLinkFileService.PopulateFileCounts(downloadCleanerConfig.UnlinkedIgnoredRootDir);
|
||||
}
|
||||
|
||||
foreach (UTorrentItem download in downloads.Cast<UTorrentItem>())
|
||||
{
|
||||
if (string.IsNullOrEmpty(download.Hash) || string.IsNullOrEmpty(download.Name) || string.IsNullOrEmpty(download.Label))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
_logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
var properties = await _client.GetTorrentPropertiesAsync(download.Hash);
|
||||
|
||||
if (ignoredDownloads.Count > 0 &&
|
||||
(download.ShouldIgnore(ignoredDownloads) || properties.TrackerList.Any(x => x.ShouldIgnore(ignoredDownloads))))
|
||||
{
|
||||
_logger.LogInformation("skip | download is ignored | {name}", download.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
ContextProvider.Set("downloadName", download.Name);
|
||||
ContextProvider.Set("hash", download.Hash);
|
||||
|
||||
List<UTorrentFile>? files = await _client.GetTorrentFilesAsync(download.Hash);
|
||||
|
||||
bool hasHardlinks = false;
|
||||
|
||||
foreach (var file in files ?? [])
|
||||
{
|
||||
string filePath = string.Join(Path.DirectorySeparatorChar, Path.Combine(download.SavePath, file.Name).Split(['\\', '/']));
|
||||
|
||||
if (file.Priority <= 0)
|
||||
{
|
||||
_logger.LogDebug("skip | file is not downloaded | {file}", filePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
long hardlinkCount = _hardLinkFileService
|
||||
.GetHardLinkCount(filePath, !string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir));
|
||||
|
||||
if (hardlinkCount < 0)
|
||||
{
|
||||
_logger.LogDebug("skip | could not get file properties | {file}", filePath);
|
||||
hasHardlinks = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (hardlinkCount > 0)
|
||||
{
|
||||
hasHardlinks = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasHardlinks)
|
||||
{
|
||||
_logger.LogDebug("skip | download has hardlinks | {name}", download.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
//TODO change label on download object
|
||||
await _dryRunInterceptor.InterceptAsync(ChangeLabel, download.Hash, downloadCleanerConfig.UnlinkedTargetCategory);
|
||||
|
||||
await _eventPublisher.PublishCategoryChanged(download.Label, downloadCleanerConfig.UnlinkedTargetCategory);
|
||||
|
||||
_logger.LogInformation("category changed for {name}", download.Name);
|
||||
|
||||
download.Label = downloadCleanerConfig.UnlinkedTargetCategory;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task DeleteDownload(string hash)
|
||||
{
|
||||
hash = hash.ToLowerInvariant();
|
||||
|
||||
await _client.RemoveTorrentsAsync([hash]);
|
||||
}
|
||||
|
||||
protected async Task CreateLabel(string name)
|
||||
{
|
||||
await UTorrentClient.CreateLabel(name);
|
||||
}
|
||||
|
||||
protected virtual async Task ChangeLabel(string hash, string newLabel)
|
||||
{
|
||||
await _client.SetTorrentLabelAsync(hash, newLabel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
using Cleanuparr.Domain.Entities;
|
||||
using Cleanuparr.Domain.Entities.UTorrent.Response;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Features.Context;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent.Extensions;
|
||||
using Cleanuparr.Persistence.Models.Configuration.QueueCleaner;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
public partial class UTorrentService
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override async Task<DownloadCheckResult> ShouldRemoveFromArrQueueAsync(string hash, IReadOnlyList<string> ignoredDownloads)
|
||||
{
|
||||
List<UTorrentFile>? files = null;
|
||||
DownloadCheckResult result = new();
|
||||
|
||||
UTorrentItem? download = await _client.GetTorrentAsync(hash);
|
||||
|
||||
if (download?.Hash is null)
|
||||
{
|
||||
_logger.LogDebug("Failed to find torrent {hash} in the download client", hash);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.Found = true;
|
||||
|
||||
var properties = await _client.GetTorrentPropertiesAsync(hash);
|
||||
result.IsPrivate = properties.IsPrivate;
|
||||
|
||||
if (ignoredDownloads.Count > 0 &&
|
||||
(download.ShouldIgnore(ignoredDownloads) || properties.TrackerList.Any(x => x.ShouldIgnore(ignoredDownloads))))
|
||||
{
|
||||
_logger.LogInformation("skip | download is ignored | {name}", download.Name);
|
||||
return result;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
files = await _client.GetTorrentFilesAsync(hash);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_logger.LogDebug(exception, "Failed to get files for torrent {hash} in the download client", hash);
|
||||
}
|
||||
|
||||
bool shouldRemove = files?.Count > 0;
|
||||
|
||||
foreach (var file in files ?? [])
|
||||
{
|
||||
if (file.Priority > 0) // 0 = skip, >0 = wanted
|
||||
{
|
||||
shouldRemove = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldRemove)
|
||||
{
|
||||
// remove if all files are unwanted
|
||||
_logger.LogDebug("all files are unwanted | removing download | {name}", download.Name);
|
||||
result.ShouldRemove = true;
|
||||
result.DeleteReason = DeleteReason.AllFilesSkipped;
|
||||
return result;
|
||||
}
|
||||
|
||||
// remove if download is stuck
|
||||
(result.ShouldRemove, result.DeleteReason) = await EvaluateDownloadRemoval(download, result.IsPrivate);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<(bool, DeleteReason)> EvaluateDownloadRemoval(UTorrentItem torrent, bool isPrivate)
|
||||
{
|
||||
(bool ShouldRemove, DeleteReason Reason) result = await CheckIfSlow(torrent, isPrivate);
|
||||
|
||||
if (result.ShouldRemove)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return await CheckIfStuck(torrent, isPrivate);
|
||||
}
|
||||
|
||||
private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfSlow(UTorrentItem download, bool isPrivate)
|
||||
{
|
||||
var queueCleanerConfig = ContextProvider.Get<QueueCleanerConfig>(nameof(QueueCleanerConfig));
|
||||
|
||||
if (queueCleanerConfig.Slow.MaxStrikes is 0)
|
||||
{
|
||||
_logger.LogTrace("skip slow check | max strikes is 0 | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (!download.IsDownloading())
|
||||
{
|
||||
_logger.LogTrace("skip slow check | download is in {state} state | {name}", download.StatusMessage, download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (download.DownloadSpeed <= 0)
|
||||
{
|
||||
_logger.LogTrace("skip slow check | download speed is 0 | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (queueCleanerConfig.Slow.IgnorePrivate && isPrivate)
|
||||
{
|
||||
// ignore private trackers
|
||||
_logger.LogTrace("skip slow check | download is private | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (download.Size > (queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue))
|
||||
{
|
||||
_logger.LogTrace("skip slow check | download is too large | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
ByteSize minSpeed = queueCleanerConfig.Slow.MinSpeedByteSize;
|
||||
ByteSize currentSpeed = new ByteSize(download.DownloadSpeed);
|
||||
SmartTimeSpan maxTime = SmartTimeSpan.FromHours(queueCleanerConfig.Slow.MaxTime);
|
||||
SmartTimeSpan currentTime = SmartTimeSpan.FromSeconds(download.ETA);
|
||||
|
||||
return await CheckIfSlow(
|
||||
download.Hash,
|
||||
download.Name,
|
||||
minSpeed,
|
||||
currentSpeed,
|
||||
maxTime,
|
||||
currentTime
|
||||
);
|
||||
}
|
||||
|
||||
private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfStuck(UTorrentItem download, bool isPrivate)
|
||||
{
|
||||
var queueCleanerConfig = ContextProvider.Get<QueueCleanerConfig>(nameof(QueueCleanerConfig));
|
||||
|
||||
if (queueCleanerConfig.Stalled.MaxStrikes is 0)
|
||||
{
|
||||
_logger.LogTrace("skip stalled check | max strikes is 0 | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (queueCleanerConfig.Stalled.IgnorePrivate && isPrivate)
|
||||
{
|
||||
_logger.LogDebug("skip stalled check | download is private | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (!download.IsDownloading())
|
||||
{
|
||||
_logger.LogTrace("skip stalled check | download is in {state} state | {name}", download.StatusMessage, download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (download.DateCompleted > 0)
|
||||
{
|
||||
_logger.LogTrace("skip stalled check | download is completed | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
if (download.DownloadSpeed > 0 || download.ETA > 0)
|
||||
{
|
||||
_logger.LogTrace("skip stalled check | download is not stalled | {name}", download.Name);
|
||||
return (false, DeleteReason.None);
|
||||
}
|
||||
|
||||
ResetStalledStrikesOnProgress(download.Hash, download.Downloaded);
|
||||
|
||||
return (await _striker.StrikeAndCheckLimit(download.Hash, download.Name, queueCleanerConfig.Stalled.MaxStrikes, StrikeType.Stalled), DeleteReason.Stalled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Cleanuparr.Infrastructure.Features.DownloadClient.UTorrent;
|
||||
|
||||
/// <summary>
|
||||
/// µTorrent status bitfield constants
|
||||
/// Based on the µTorrent Web UI API documentation
|
||||
/// </summary>
|
||||
public static class UTorrentStatus
|
||||
{
|
||||
public const int Started = 1; // 1 << 0
|
||||
public const int Checking = 2; // 1 << 1
|
||||
public const int StartAfterCheck = 4; // 1 << 2
|
||||
public const int Checked = 8; // 1 << 3
|
||||
public const int Error = 16; // 1 << 4
|
||||
public const int Paused = 32; // 1 << 5
|
||||
public const int Queued = 64; // 1 << 6
|
||||
public const int Loaded = 128; // 1 << 7
|
||||
}
|
||||
@@ -9,9 +9,9 @@ using Cleanuparr.Infrastructure.Features.DownloadRemover.Models;
|
||||
using Cleanuparr.Persistence;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Cleanuparr.Persistence.Models.Configuration.Arr;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.DownloadCleaner;
|
||||
using Cleanuparr.Persistence.Models.Configuration.General;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.QueueCleaner;
|
||||
using Data.Models.Arr;
|
||||
using MassTransit;
|
||||
|
||||
@@ -6,35 +6,37 @@ using System.Text.RegularExpressions;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Helpers;
|
||||
using Cleanuparr.Persistence;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.QueueCleaner;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Cleanuparr.Shared.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
namespace Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
|
||||
public sealed class BlocklistProvider
|
||||
{
|
||||
private readonly ILogger<BlocklistProvider> _logger;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly Dictionary<InstanceType, string> _configHashes = new();
|
||||
private static DateTime _lastLoadTime = DateTime.MinValue;
|
||||
private const int LoadIntervalHours = 4;
|
||||
private readonly Dictionary<string, DateTime> _lastLoadTimes = new();
|
||||
private const int DefaultLoadIntervalHours = 4;
|
||||
private const int FastLoadIntervalMinutes = 5;
|
||||
private const string MalwareListUrl = "https://cleanuparr.pages.dev/static/known_malware_file_name_patterns";
|
||||
private const string MalwareListKey = "MALWARE_PATTERNS";
|
||||
|
||||
public BlocklistProvider(
|
||||
ILogger<BlocklistProvider> logger,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
IMemoryCache cache,
|
||||
IHttpClientFactory httpClientFactory
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
_scopeFactory = scopeFactory;
|
||||
_cache = cache;
|
||||
_httpClient = httpClientFactory.CreateClient(Constants.HttpClientWithRetryName);
|
||||
}
|
||||
@@ -43,80 +45,92 @@ public sealed class BlocklistProvider
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataContext = _serviceProvider.GetRequiredService<DataContext>();
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
await using var dataContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
int changedCount = 0;
|
||||
var contentBlockerConfig = await dataContext.ContentBlockerConfigs
|
||||
var malwareBlockerConfig = await dataContext.ContentBlockerConfigs
|
||||
.AsNoTracking()
|
||||
.FirstAsync();
|
||||
bool shouldReload = false;
|
||||
|
||||
if (_lastLoadTime.AddHours(LoadIntervalHours) < DateTime.UtcNow)
|
||||
{
|
||||
shouldReload = true;
|
||||
_lastLoadTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
if (!contentBlockerConfig.Enabled)
|
||||
if (!malwareBlockerConfig.Enabled)
|
||||
{
|
||||
_logger.LogDebug("Content blocker is disabled, skipping blocklist loading");
|
||||
_logger.LogDebug("Malware Blocker is disabled, skipping blocklist loading");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check and update Sonarr blocklist if needed
|
||||
string sonarrHash = GenerateSettingsHash(contentBlockerConfig.Sonarr);
|
||||
if (shouldReload || !_configHashes.TryGetValue(InstanceType.Sonarr, out string? oldSonarrHash) || sonarrHash != oldSonarrHash)
|
||||
string sonarrHash = GenerateSettingsHash(malwareBlockerConfig.Sonarr);
|
||||
var sonarrInterval = GetLoadInterval(malwareBlockerConfig.Sonarr.BlocklistPath);
|
||||
var sonarrIdentifier = $"Sonarr_{malwareBlockerConfig.Sonarr.BlocklistPath}";
|
||||
if (ShouldReloadBlocklist(sonarrIdentifier, sonarrInterval) || !_configHashes.TryGetValue(InstanceType.Sonarr, out string? oldSonarrHash) || sonarrHash != oldSonarrHash)
|
||||
{
|
||||
_logger.LogDebug("Loading Sonarr blocklist");
|
||||
|
||||
await LoadPatternsAndRegexesAsync(contentBlockerConfig.Sonarr, InstanceType.Sonarr);
|
||||
await LoadPatternsAndRegexesAsync(malwareBlockerConfig.Sonarr, InstanceType.Sonarr);
|
||||
_configHashes[InstanceType.Sonarr] = sonarrHash;
|
||||
_lastLoadTimes[sonarrIdentifier] = DateTime.UtcNow;
|
||||
changedCount++;
|
||||
}
|
||||
|
||||
// Check and update Radarr blocklist if needed
|
||||
string radarrHash = GenerateSettingsHash(contentBlockerConfig.Radarr);
|
||||
if (shouldReload || !_configHashes.TryGetValue(InstanceType.Radarr, out string? oldRadarrHash) || radarrHash != oldRadarrHash)
|
||||
string radarrHash = GenerateSettingsHash(malwareBlockerConfig.Radarr);
|
||||
var radarrInterval = GetLoadInterval(malwareBlockerConfig.Radarr.BlocklistPath);
|
||||
var radarrIdentifier = $"Radarr_{malwareBlockerConfig.Radarr.BlocklistPath}";
|
||||
if (ShouldReloadBlocklist(radarrIdentifier, radarrInterval) || !_configHashes.TryGetValue(InstanceType.Radarr, out string? oldRadarrHash) || radarrHash != oldRadarrHash)
|
||||
{
|
||||
_logger.LogDebug("Loading Radarr blocklist");
|
||||
|
||||
await LoadPatternsAndRegexesAsync(contentBlockerConfig.Radarr, InstanceType.Radarr);
|
||||
await LoadPatternsAndRegexesAsync(malwareBlockerConfig.Radarr, InstanceType.Radarr);
|
||||
_configHashes[InstanceType.Radarr] = radarrHash;
|
||||
_lastLoadTimes[radarrIdentifier] = DateTime.UtcNow;
|
||||
changedCount++;
|
||||
}
|
||||
|
||||
// Check and update Lidarr blocklist if needed
|
||||
string lidarrHash = GenerateSettingsHash(contentBlockerConfig.Lidarr);
|
||||
if (shouldReload || !_configHashes.TryGetValue(InstanceType.Lidarr, out string? oldLidarrHash) || lidarrHash != oldLidarrHash)
|
||||
string lidarrHash = GenerateSettingsHash(malwareBlockerConfig.Lidarr);
|
||||
var lidarrInterval = GetLoadInterval(malwareBlockerConfig.Lidarr.BlocklistPath);
|
||||
var lidarrIdentifier = $"Lidarr_{malwareBlockerConfig.Lidarr.BlocklistPath}";
|
||||
if (ShouldReloadBlocklist(lidarrIdentifier, lidarrInterval) || !_configHashes.TryGetValue(InstanceType.Lidarr, out string? oldLidarrHash) || lidarrHash != oldLidarrHash)
|
||||
{
|
||||
_logger.LogDebug("Loading Lidarr blocklist");
|
||||
|
||||
await LoadPatternsAndRegexesAsync(contentBlockerConfig.Lidarr, InstanceType.Lidarr);
|
||||
await LoadPatternsAndRegexesAsync(malwareBlockerConfig.Lidarr, InstanceType.Lidarr);
|
||||
_configHashes[InstanceType.Lidarr] = lidarrHash;
|
||||
_lastLoadTimes[lidarrIdentifier] = DateTime.UtcNow;
|
||||
changedCount++;
|
||||
}
|
||||
|
||||
// Check and update Lidarr blocklist if needed
|
||||
string readarrHash = GenerateSettingsHash(contentBlockerConfig.Readarr);
|
||||
if (shouldReload || !_configHashes.TryGetValue(InstanceType.Readarr, out string? oldReadarrHash) || readarrHash != oldReadarrHash)
|
||||
// Check and update Readarr blocklist if needed
|
||||
string readarrHash = GenerateSettingsHash(malwareBlockerConfig.Readarr);
|
||||
var readarrInterval = GetLoadInterval(malwareBlockerConfig.Readarr.BlocklistPath);
|
||||
var readarrIdentifier = $"Readarr_{malwareBlockerConfig.Readarr.BlocklistPath}";
|
||||
if (ShouldReloadBlocklist(readarrIdentifier, readarrInterval) || !_configHashes.TryGetValue(InstanceType.Readarr, out string? oldReadarrHash) || readarrHash != oldReadarrHash)
|
||||
{
|
||||
_logger.LogDebug("Loading Readarr blocklist");
|
||||
|
||||
await LoadPatternsAndRegexesAsync(contentBlockerConfig.Readarr, InstanceType.Readarr);
|
||||
await LoadPatternsAndRegexesAsync(malwareBlockerConfig.Readarr, InstanceType.Readarr);
|
||||
_configHashes[InstanceType.Readarr] = readarrHash;
|
||||
_lastLoadTimes[readarrIdentifier] = DateTime.UtcNow;
|
||||
changedCount++;
|
||||
}
|
||||
|
||||
// Check and update Whisparr blocklist if needed
|
||||
string whisparrHash = GenerateSettingsHash(contentBlockerConfig.Whisparr);
|
||||
if (shouldReload || !_configHashes.TryGetValue(InstanceType.Whisparr, out string? oldWhisparrHash) || whisparrHash != oldWhisparrHash)
|
||||
string whisparrHash = GenerateSettingsHash(malwareBlockerConfig.Whisparr);
|
||||
var whisparrInterval = GetLoadInterval(malwareBlockerConfig.Whisparr.BlocklistPath);
|
||||
var whisparrIdentifier = $"Whisparr_{malwareBlockerConfig.Whisparr.BlocklistPath}";
|
||||
if (ShouldReloadBlocklist(whisparrIdentifier, whisparrInterval) || !_configHashes.TryGetValue(InstanceType.Whisparr, out string? oldWhisparrHash) || whisparrHash != oldWhisparrHash)
|
||||
{
|
||||
_logger.LogDebug("Loading Whisparr blocklist");
|
||||
|
||||
await LoadPatternsAndRegexesAsync(contentBlockerConfig.Whisparr, InstanceType.Whisparr);
|
||||
await LoadPatternsAndRegexesAsync(malwareBlockerConfig.Whisparr, InstanceType.Whisparr);
|
||||
_configHashes[InstanceType.Whisparr] = whisparrHash;
|
||||
_lastLoadTimes[whisparrIdentifier] = DateTime.UtcNow;
|
||||
changedCount++;
|
||||
}
|
||||
|
||||
// Always check and update malware patterns
|
||||
await LoadMalwarePatternsAsync();
|
||||
|
||||
if (changedCount > 0)
|
||||
{
|
||||
_logger.LogInformation("Successfully loaded {count} blocklists", changedCount);
|
||||
@@ -153,6 +167,77 @@ public sealed class BlocklistProvider
|
||||
|
||||
return regexes ?? [];
|
||||
}
|
||||
|
||||
public ConcurrentBag<string> GetMalwarePatterns()
|
||||
{
|
||||
_cache.TryGetValue(CacheKeys.KnownMalwarePatterns(), out ConcurrentBag<string>? patterns);
|
||||
|
||||
return patterns ?? [];
|
||||
}
|
||||
|
||||
private TimeSpan GetLoadInterval(string? path)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path) && Uri.TryCreate(path, UriKind.Absolute, out var uri))
|
||||
{
|
||||
if (uri.Host.Equals("cleanuparr.pages.dev", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return TimeSpan.FromMinutes(FastLoadIntervalMinutes);
|
||||
}
|
||||
|
||||
return TimeSpan.FromHours(DefaultLoadIntervalHours);
|
||||
}
|
||||
|
||||
// If fast load interval for local files
|
||||
return TimeSpan.FromMinutes(FastLoadIntervalMinutes);
|
||||
}
|
||||
|
||||
private bool ShouldReloadBlocklist(string identifier, TimeSpan interval)
|
||||
{
|
||||
if (!_lastLoadTimes.TryGetValue(identifier, out DateTime lastLoad))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return DateTime.UtcNow - lastLoad >= interval;
|
||||
}
|
||||
|
||||
private async Task LoadMalwarePatternsAsync()
|
||||
{
|
||||
var malwareInterval = TimeSpan.FromMinutes(FastLoadIntervalMinutes);
|
||||
|
||||
if (!ShouldReloadBlocklist(MalwareListKey, malwareInterval))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("Loading malware patterns");
|
||||
|
||||
string[] filePatterns = await ReadContentAsync(MalwareListUrl);
|
||||
|
||||
long startTime = Stopwatch.GetTimestamp();
|
||||
ParallelOptions options = new() { MaxDegreeOfParallelism = 5 };
|
||||
ConcurrentBag<string> patterns = [];
|
||||
|
||||
Parallel.ForEach(filePatterns, options, pattern =>
|
||||
{
|
||||
patterns.Add(pattern);
|
||||
});
|
||||
|
||||
TimeSpan elapsed = Stopwatch.GetElapsedTime(startTime);
|
||||
|
||||
_cache.Set(CacheKeys.KnownMalwarePatterns(), patterns);
|
||||
_lastLoadTimes[MalwareListKey] = DateTime.UtcNow;
|
||||
|
||||
_logger.LogDebug("loaded {count} known malware patterns", patterns.Count);
|
||||
_logger.LogDebug("malware patterns loaded in {elapsed} ms", elapsed.TotalMilliseconds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to load malware patterns from {url}", MalwareListUrl);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadPatternsAndRegexesAsync(BlocklistSettings blocklistSettings, InstanceType instanceType)
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Text.RegularExpressions;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
namespace Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
|
||||
public class FilenameEvaluator : IFilenameEvaluator
|
||||
{
|
||||
@@ -20,6 +20,16 @@ public class FilenameEvaluator : IFilenameEvaluator
|
||||
return IsValidAgainstPatterns(filename, type, patterns) && IsValidAgainstRegexes(filename, type, regexes);
|
||||
}
|
||||
|
||||
public bool IsKnownMalware(string filename, ConcurrentBag<string> malwarePatterns)
|
||||
{
|
||||
if (malwarePatterns.Count is 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return malwarePatterns.Any(pattern => filename.Contains(pattern, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
private static bool IsValidAgainstPatterns(string filename, BlocklistType type, ConcurrentBag<string> patterns)
|
||||
{
|
||||
if (patterns.Count is 0)
|
||||
@@ -2,9 +2,11 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Features.ContentBlocker;
|
||||
namespace Cleanuparr.Infrastructure.Features.MalwareBlocker;
|
||||
|
||||
public interface IFilenameEvaluator
|
||||
{
|
||||
bool IsValid(string filename, BlocklistType type, ConcurrentBag<string> patterns, ConcurrentBag<Regex> regexes);
|
||||
|
||||
bool IsKnownMalware(string filename, ConcurrentBag<string> malwarePatterns);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Infrastructure.Features.DownloadClient;
|
||||
using Cleanuparr.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -13,9 +12,8 @@ namespace Cleanuparr.Infrastructure.Health;
|
||||
public class HealthCheckService : IHealthCheckService
|
||||
{
|
||||
private readonly ILogger<HealthCheckService> _logger;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly DownloadServiceFactory _downloadServiceFactory;
|
||||
private readonly Dictionary<Guid, HealthStatus> _healthStatuses = new();
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly object _lockObject = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -25,12 +23,11 @@ public class HealthCheckService : IHealthCheckService
|
||||
|
||||
public HealthCheckService(
|
||||
ILogger<HealthCheckService> logger,
|
||||
IServiceProvider serviceProvider,
|
||||
DownloadServiceFactory downloadServiceFactory)
|
||||
IServiceScopeFactory scopeFactory
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
_downloadServiceFactory = downloadServiceFactory;
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -40,7 +37,8 @@ public class HealthCheckService : IHealthCheckService
|
||||
|
||||
try
|
||||
{
|
||||
var dataContext = _serviceProvider.GetRequiredService<DataContext>();
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
await using var dataContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Get the client configuration
|
||||
var downloadClientConfig = await dataContext.DownloadClients
|
||||
@@ -63,7 +61,8 @@ public class HealthCheckService : IHealthCheckService
|
||||
}
|
||||
|
||||
// Get the client instance
|
||||
var client = _downloadServiceFactory.GetDownloadService(downloadClientConfig);
|
||||
var downloadServiceFactory = scope.ServiceProvider.GetRequiredService<DownloadServiceFactory>();
|
||||
var client = downloadServiceFactory.GetDownloadService(downloadClientConfig);
|
||||
|
||||
// Execute the health check
|
||||
var healthResult = await client.HealthCheckAsync();
|
||||
@@ -107,7 +106,8 @@ public class HealthCheckService : IHealthCheckService
|
||||
|
||||
try
|
||||
{
|
||||
var dataContext = _serviceProvider.GetRequiredService<DataContext>();
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
await using var dataContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Get all enabled client configurations
|
||||
var enabledClients = await dataContext.DownloadClients
|
||||
|
||||
@@ -10,9 +10,17 @@ public static class CacheKeys
|
||||
public static string BlocklistPatterns(InstanceType instanceType) => $"{instanceType.ToString()}_patterns";
|
||||
public static string BlocklistRegexes(InstanceType instanceType) => $"{instanceType.ToString()}_regexes";
|
||||
|
||||
public static string KnownMalwarePatterns() => "KNOWN_MALWARE_PATTERNS";
|
||||
|
||||
public static string StrikeItem(string hash, StrikeType strikeType) => $"item_{hash}_{strikeType.ToString()}";
|
||||
|
||||
public static string IgnoredDownloads(string name) => $"{name}_ignored";
|
||||
|
||||
public static string DownloadMarkedForRemoval(string hash, Uri url) => $"remove_{hash.ToLowerInvariant()}_{url}";
|
||||
|
||||
public static class UTorrent
|
||||
{
|
||||
public static string GetAuthTokenKey(string clientId) => $"utorrent:auth:token:{clientId}";
|
||||
public static string GetGuidCookieKey(string clientId) => $"utorrent:auth:cookie:{clientId}";
|
||||
}
|
||||
}
|
||||
@@ -13,16 +13,16 @@ namespace Cleanuparr.Infrastructure.Http;
|
||||
public class DynamicHttpClientProvider : IDynamicHttpClientProvider
|
||||
{
|
||||
private readonly ILogger<DynamicHttpClientProvider> _logger;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly IDynamicHttpClientFactory _dynamicHttpClientFactory;
|
||||
|
||||
public DynamicHttpClientProvider(
|
||||
ILogger<DynamicHttpClientProvider> logger,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
IDynamicHttpClientFactory dynamicHttpClientFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
_scopeFactory = scopeFactory;
|
||||
_dynamicHttpClientFactory = dynamicHttpClientFactory;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ public class DynamicHttpClientProvider : IDynamicHttpClientProvider
|
||||
/// <returns>A configured HttpClient instance</returns>
|
||||
private HttpClient CreateGenericClient(DownloadClientConfig downloadClientConfig)
|
||||
{
|
||||
var dataContext = _serviceProvider.GetRequiredService<DataContext>();
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
using var dataContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
var httpConfig = dataContext.GeneralConfigs.First();
|
||||
var clientName = GetClientName(downloadClientConfig);
|
||||
|
||||
|
||||
@@ -13,16 +13,17 @@ namespace Cleanuparr.Infrastructure.Http.DynamicHttpClientSystem;
|
||||
/// </summary>
|
||||
public class DynamicHttpClientConfiguration : IConfigureNamedOptions<HttpClientFactoryOptions>
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
public DynamicHttpClientConfiguration(IServiceProvider serviceProvider)
|
||||
public DynamicHttpClientConfiguration(IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public void Configure(string name, HttpClientFactoryOptions options)
|
||||
{
|
||||
var configStore = _serviceProvider.GetRequiredService<IHttpClientConfigStore>();
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var configStore = scope.ServiceProvider.GetRequiredService<IHttpClientConfigStore>();
|
||||
|
||||
if (!configStore.TryGetConfiguration(name, out HttpClientConfig? config))
|
||||
return;
|
||||
@@ -48,7 +49,8 @@ public class DynamicHttpClientConfiguration : IConfigureNamedOptions<HttpClientF
|
||||
|
||||
private void ConfigureHandler(HttpMessageHandlerBuilder builder, HttpClientConfig config)
|
||||
{
|
||||
var certValidationService = _serviceProvider.GetRequiredService<CertificateValidationService>();
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var certValidationService = scope.ServiceProvider.GetRequiredService<CertificateValidationService>();
|
||||
|
||||
switch (config.Type)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Cleanuparr.Persistence;
|
||||
using Cleanuparr.Shared.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DelugeService = Cleanuparr.Infrastructure.Features.DownloadClient.Deluge.DelugeService;
|
||||
@@ -13,24 +14,27 @@ namespace Cleanuparr.Infrastructure.Http.DynamicHttpClientSystem;
|
||||
public class HttpClientConfigurationService : IHostedService
|
||||
{
|
||||
private readonly IDynamicHttpClientFactory _clientFactory;
|
||||
private readonly DataContext _dataContext;
|
||||
private readonly ILogger<HttpClientConfigurationService> _logger;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
public HttpClientConfigurationService(
|
||||
IDynamicHttpClientFactory clientFactory,
|
||||
DataContext dataContext,
|
||||
ILogger<HttpClientConfigurationService> logger)
|
||||
ILogger<HttpClientConfigurationService> logger,
|
||||
IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_clientFactory = clientFactory;
|
||||
_dataContext = dataContext;
|
||||
_logger = logger;
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _dataContext.GeneralConfigs
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
await using var dataContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
var config = await dataContext.GeneralConfigs
|
||||
.AsNoTracking()
|
||||
.FirstAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
# Enhanced Logging System
|
||||
|
||||
## Overview
|
||||
|
||||
The enhanced logging system provides a structured approach to logging with the following features:
|
||||
|
||||
- **Category-based logging**: Organize logs by functional areas (SYSTEM, API, JOBS, etc.)
|
||||
- **Job name context**: Add job name to logs for background operations
|
||||
- **Instance context**: Add instance names (Sonarr, Radarr, etc.) to relevant logs
|
||||
- **Multiple output targets**: Console, files, and real-time SignalR streaming
|
||||
- **Category-specific log files**: Separate log files for different categories
|
||||
|
||||
## Using the Logging System
|
||||
|
||||
### Adding Category to Logs
|
||||
|
||||
```csharp
|
||||
// Using category constants
|
||||
logger.WithCategory(LoggingCategoryConstants.System)
|
||||
.LogInformation("This is a system log");
|
||||
|
||||
// Using direct category name
|
||||
logger.WithCategory("API")
|
||||
.LogInformation("This is an API log");
|
||||
```
|
||||
|
||||
### Adding Job Name Context
|
||||
|
||||
```csharp
|
||||
logger.WithCategory(LoggingCategoryConstants.Jobs)
|
||||
.WithJob("ContentBlocker")
|
||||
.LogInformation("Starting content blocking job");
|
||||
```
|
||||
|
||||
### Adding Instance Name Context
|
||||
|
||||
```csharp
|
||||
logger.WithCategory(LoggingCategoryConstants.Sonarr)
|
||||
.WithInstance("Sonarr")
|
||||
.LogInformation("Processing Sonarr data");
|
||||
```
|
||||
|
||||
### Combined Context Example
|
||||
|
||||
```csharp
|
||||
logger.WithCategory(LoggingCategoryConstants.Jobs)
|
||||
.WithJob("QueueCleaner")
|
||||
.WithInstance("Radarr")
|
||||
.LogInformation("Cleaning Radarr queue");
|
||||
```
|
||||
|
||||
## Log Storage
|
||||
|
||||
Logs are stored in the following locations:
|
||||
|
||||
- **Main log file**: `{config_path}/logs/Cleanuparr-.txt`
|
||||
- **Category logs**: `{config_path}/logs/{category}-.txt` (e.g., `system-.txt`, `api-.txt`)
|
||||
|
||||
The log files use rolling file behavior:
|
||||
- Daily rotation
|
||||
- 10MB size limit for main log files
|
||||
- 5MB size limit for category-specific logs
|
||||
|
||||
## SignalR Integration
|
||||
|
||||
The logging system includes real-time streaming via SignalR:
|
||||
|
||||
- **Hub URL**: `/hubs/logs`
|
||||
- **Hub class**: `LogHub`
|
||||
- **Event name**: `ReceiveLog`
|
||||
|
||||
### Requesting Recent Logs
|
||||
|
||||
When a client connects, it can request recent logs from the buffer:
|
||||
|
||||
```javascript
|
||||
await connection.invoke("RequestRecentLogs");
|
||||
```
|
||||
|
||||
### Log Message Format
|
||||
|
||||
Each log message contains:
|
||||
- `timestamp`: The time the log was created
|
||||
- `level`: Log level (Information, Warning, Error, etc.)
|
||||
- `message`: The log message text
|
||||
- `exception`: Exception details (if present)
|
||||
- `category`: The log category
|
||||
- `jobName`: The job name (if present)
|
||||
- `instanceName`: The instance name (if present)
|
||||
|
||||
## How It All Works
|
||||
|
||||
1. The logging system is initialized during application startup
|
||||
2. Logs are written to the console in real-time
|
||||
3. Logs are written to files based on their category
|
||||
4. Logs are buffered and sent to connected SignalR clients
|
||||
5. New clients can request recent logs from the buffer
|
||||
|
||||
## Configuration Options
|
||||
|
||||
The logging configuration is loaded from the `Logging` section in appsettings.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": "Information",
|
||||
"SignalR": {
|
||||
"Enabled": true,
|
||||
"BufferSize": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Standard Categories
|
||||
|
||||
Use the `LoggingCategoryConstants` class to ensure consistent category naming:
|
||||
|
||||
- `LoggingCategoryConstants.System`: System-level logs
|
||||
- `LoggingCategoryConstants.Api`: API-related logs
|
||||
- `LoggingCategoryConstants.Jobs`: Job execution logs
|
||||
- `LoggingCategoryConstants.Notifications`: User notification logs
|
||||
- `LoggingCategoryConstants.Sonarr`: Sonarr-related logs
|
||||
- `LoggingCategoryConstants.Radarr`: Radarr-related logs
|
||||
- `LoggingCategoryConstants.Lidarr`: Lidarr-related logs
|
||||
@@ -6,6 +6,6 @@ namespace Cleanuparr.Infrastructure.Models;
|
||||
public enum JobType
|
||||
{
|
||||
QueueCleaner,
|
||||
ContentBlocker,
|
||||
MalwareBlocker,
|
||||
DownloadCleaner
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public static class CronValidationHelper
|
||||
throw new ValidationException($"{cronExpression} should have a fire time of maximum {Constants.TriggerMaxLimit.TotalHours} hours");
|
||||
}
|
||||
|
||||
if (jobType is not JobType.ContentBlocker && triggerValue < Constants.TriggerMinLimit)
|
||||
if (jobType is not JobType.MalwareBlocker && triggerValue < Constants.TriggerMinLimit)
|
||||
{
|
||||
throw new ValidationException($"{cronExpression} should have a fire time of minimum {Constants.TriggerMinLimit.TotalSeconds} seconds");
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Persistence.Converters;
|
||||
using Cleanuparr.Persistence.Models.Configuration;
|
||||
using Cleanuparr.Persistence.Models.Configuration.Arr;
|
||||
using Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.DownloadCleaner;
|
||||
using Cleanuparr.Persistence.Models.Configuration.General;
|
||||
using Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
using Cleanuparr.Persistence.Models.Configuration.Notification;
|
||||
using Cleanuparr.Persistence.Models.Configuration.QueueCleaner;
|
||||
using Cleanuparr.Shared.Helpers;
|
||||
|
||||
645
code/backend/Cleanuparr.Persistence/Migrations/Data/20250801143446_AddKnownMalwareOption.Designer.cs
generated
Normal file
645
code/backend/Cleanuparr.Persistence/Migrations/Data/20250801143446_AddKnownMalwareOption.Designer.cs
generated
Normal file
@@ -0,0 +1,645 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cleanuparr.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Cleanuparr.Persistence.Migrations.Data
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20250801143446_AddKnownMalwareOption")]
|
||||
partial class AddKnownMalwareOption
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.6");
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.Arr.ArrConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<short>("FailedImportMaxStrikes")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("failed_import_max_strikes");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("type");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_arr_configs");
|
||||
|
||||
b.ToTable("arr_configs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.Arr.ArrInstance", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("ApiKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("api_key");
|
||||
|
||||
b.Property<Guid>("ArrConfigId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("arr_config_id");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("enabled");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("url");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_arr_instances");
|
||||
|
||||
b.HasIndex("ArrConfigId")
|
||||
.HasDatabaseName("ix_arr_instances_arr_config_id");
|
||||
|
||||
b.ToTable("arr_instances", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.ContentBlocker.ContentBlockerConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("CronExpression")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("cron_expression");
|
||||
|
||||
b.Property<bool>("DeleteKnownMalware")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("delete_known_malware");
|
||||
|
||||
b.Property<bool>("DeletePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("delete_private");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("enabled");
|
||||
|
||||
b.Property<bool>("IgnorePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("ignore_private");
|
||||
|
||||
b.Property<bool>("UseAdvancedScheduling")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("use_advanced_scheduling");
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("Lidarr", "Cleanuparr.Persistence.Models.Configuration.ContentBlocker.ContentBlockerConfig.Lidarr#BlocklistSettings", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("BlocklistPath")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("lidarr_blocklist_path");
|
||||
|
||||
b1.Property<string>("BlocklistType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("lidarr_blocklist_type");
|
||||
|
||||
b1.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("lidarr_enabled");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("Radarr", "Cleanuparr.Persistence.Models.Configuration.ContentBlocker.ContentBlockerConfig.Radarr#BlocklistSettings", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("BlocklistPath")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("radarr_blocklist_path");
|
||||
|
||||
b1.Property<string>("BlocklistType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("radarr_blocklist_type");
|
||||
|
||||
b1.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("radarr_enabled");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("Readarr", "Cleanuparr.Persistence.Models.Configuration.ContentBlocker.ContentBlockerConfig.Readarr#BlocklistSettings", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("BlocklistPath")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("readarr_blocklist_path");
|
||||
|
||||
b1.Property<string>("BlocklistType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("readarr_blocklist_type");
|
||||
|
||||
b1.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("readarr_enabled");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("Sonarr", "Cleanuparr.Persistence.Models.Configuration.ContentBlocker.ContentBlockerConfig.Sonarr#BlocklistSettings", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("BlocklistPath")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("sonarr_blocklist_path");
|
||||
|
||||
b1.Property<string>("BlocklistType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("sonarr_blocklist_type");
|
||||
|
||||
b1.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("sonarr_enabled");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("Whisparr", "Cleanuparr.Persistence.Models.Configuration.ContentBlocker.ContentBlockerConfig.Whisparr#BlocklistSettings", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("BlocklistPath")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("whisparr_blocklist_path");
|
||||
|
||||
b1.Property<int>("BlocklistType")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("whisparr_blocklist_type");
|
||||
|
||||
b1.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("whisparr_enabled");
|
||||
});
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_content_blocker_configs");
|
||||
|
||||
b.ToTable("content_blocker_configs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.DownloadCleaner.CleanCategory", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("DownloadCleanerConfigId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("download_cleaner_config_id");
|
||||
|
||||
b.Property<double>("MaxRatio")
|
||||
.HasColumnType("REAL")
|
||||
.HasColumnName("max_ratio");
|
||||
|
||||
b.Property<double>("MaxSeedTime")
|
||||
.HasColumnType("REAL")
|
||||
.HasColumnName("max_seed_time");
|
||||
|
||||
b.Property<double>("MinSeedTime")
|
||||
.HasColumnType("REAL")
|
||||
.HasColumnName("min_seed_time");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_clean_categories");
|
||||
|
||||
b.HasIndex("DownloadCleanerConfigId")
|
||||
.HasDatabaseName("ix_clean_categories_download_cleaner_config_id");
|
||||
|
||||
b.ToTable("clean_categories", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.DownloadCleaner.DownloadCleanerConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("CronExpression")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("cron_expression");
|
||||
|
||||
b.Property<bool>("DeletePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("delete_private");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("enabled");
|
||||
|
||||
b.PrimitiveCollection<string>("UnlinkedCategories")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("unlinked_categories");
|
||||
|
||||
b.Property<bool>("UnlinkedEnabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("unlinked_enabled");
|
||||
|
||||
b.Property<string>("UnlinkedIgnoredRootDir")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("unlinked_ignored_root_dir");
|
||||
|
||||
b.Property<string>("UnlinkedTargetCategory")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("unlinked_target_category");
|
||||
|
||||
b.Property<bool>("UnlinkedUseTag")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("unlinked_use_tag");
|
||||
|
||||
b.Property<bool>("UseAdvancedScheduling")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("use_advanced_scheduling");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_download_cleaner_configs");
|
||||
|
||||
b.ToTable("download_cleaner_configs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.DownloadClientConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("enabled");
|
||||
|
||||
b.Property<string>("Host")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("host");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("password");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("type");
|
||||
|
||||
b.Property<string>("TypeName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("type_name");
|
||||
|
||||
b.Property<string>("UrlBase")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("url_base");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_download_clients");
|
||||
|
||||
b.ToTable("download_clients", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.General.GeneralConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<bool>("DisplaySupportBanner")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("display_support_banner");
|
||||
|
||||
b.Property<bool>("DryRun")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("dry_run");
|
||||
|
||||
b.Property<string>("EncryptionKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("encryption_key");
|
||||
|
||||
b.Property<string>("HttpCertificateValidation")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("http_certificate_validation");
|
||||
|
||||
b.Property<ushort>("HttpMaxRetries")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("http_max_retries");
|
||||
|
||||
b.Property<ushort>("HttpTimeout")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("http_timeout");
|
||||
|
||||
b.PrimitiveCollection<string>("IgnoredDownloads")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("ignored_downloads");
|
||||
|
||||
b.Property<string>("LogLevel")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("log_level");
|
||||
|
||||
b.Property<ushort>("SearchDelay")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("search_delay");
|
||||
|
||||
b.Property<bool>("SearchEnabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("search_enabled");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_general_configs");
|
||||
|
||||
b.ToTable("general_configs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.Notification.AppriseConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("FullUrl")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("full_url");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<bool>("OnCategoryChanged")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_category_changed");
|
||||
|
||||
b.Property<bool>("OnDownloadCleaned")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_download_cleaned");
|
||||
|
||||
b.Property<bool>("OnFailedImportStrike")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_failed_import_strike");
|
||||
|
||||
b.Property<bool>("OnQueueItemDeleted")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_queue_item_deleted");
|
||||
|
||||
b.Property<bool>("OnSlowStrike")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_slow_strike");
|
||||
|
||||
b.Property<bool>("OnStalledStrike")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_stalled_strike");
|
||||
|
||||
b.Property<string>("Tags")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("tags");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_apprise_configs");
|
||||
|
||||
b.ToTable("apprise_configs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.Notification.NotifiarrConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("ApiKey")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("api_key");
|
||||
|
||||
b.Property<string>("ChannelId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("channel_id");
|
||||
|
||||
b.Property<bool>("OnCategoryChanged")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_category_changed");
|
||||
|
||||
b.Property<bool>("OnDownloadCleaned")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_download_cleaned");
|
||||
|
||||
b.Property<bool>("OnFailedImportStrike")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_failed_import_strike");
|
||||
|
||||
b.Property<bool>("OnQueueItemDeleted")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_queue_item_deleted");
|
||||
|
||||
b.Property<bool>("OnSlowStrike")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_slow_strike");
|
||||
|
||||
b.Property<bool>("OnStalledStrike")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("on_stalled_strike");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_notifiarr_configs");
|
||||
|
||||
b.ToTable("notifiarr_configs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.QueueCleaner.QueueCleanerConfig", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("CronExpression")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("cron_expression");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("enabled");
|
||||
|
||||
b.Property<bool>("UseAdvancedScheduling")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("use_advanced_scheduling");
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("FailedImport", "Cleanuparr.Persistence.Models.Configuration.QueueCleaner.QueueCleanerConfig.FailedImport#FailedImportConfig", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<bool>("DeletePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("failed_import_delete_private");
|
||||
|
||||
b1.Property<bool>("IgnorePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("failed_import_ignore_private");
|
||||
|
||||
b1.PrimitiveCollection<string>("IgnoredPatterns")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("failed_import_ignored_patterns");
|
||||
|
||||
b1.Property<ushort>("MaxStrikes")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("failed_import_max_strikes");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("Slow", "Cleanuparr.Persistence.Models.Configuration.QueueCleaner.QueueCleanerConfig.Slow#SlowConfig", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<bool>("DeletePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("slow_delete_private");
|
||||
|
||||
b1.Property<string>("IgnoreAboveSize")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("slow_ignore_above_size");
|
||||
|
||||
b1.Property<bool>("IgnorePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("slow_ignore_private");
|
||||
|
||||
b1.Property<ushort>("MaxStrikes")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("slow_max_strikes");
|
||||
|
||||
b1.Property<double>("MaxTime")
|
||||
.HasColumnType("REAL")
|
||||
.HasColumnName("slow_max_time");
|
||||
|
||||
b1.Property<string>("MinSpeed")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("slow_min_speed");
|
||||
|
||||
b1.Property<bool>("ResetStrikesOnProgress")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("slow_reset_strikes_on_progress");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("Stalled", "Cleanuparr.Persistence.Models.Configuration.QueueCleaner.QueueCleanerConfig.Stalled#StalledConfig", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<bool>("DeletePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("stalled_delete_private");
|
||||
|
||||
b1.Property<ushort>("DownloadingMetadataMaxStrikes")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("stalled_downloading_metadata_max_strikes");
|
||||
|
||||
b1.Property<bool>("IgnorePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("stalled_ignore_private");
|
||||
|
||||
b1.Property<ushort>("MaxStrikes")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("stalled_max_strikes");
|
||||
|
||||
b1.Property<bool>("ResetStrikesOnProgress")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("stalled_reset_strikes_on_progress");
|
||||
});
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_queue_cleaner_configs");
|
||||
|
||||
b.ToTable("queue_cleaner_configs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.Arr.ArrInstance", b =>
|
||||
{
|
||||
b.HasOne("Cleanuparr.Persistence.Models.Configuration.Arr.ArrConfig", "ArrConfig")
|
||||
.WithMany("Instances")
|
||||
.HasForeignKey("ArrConfigId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_arr_instances_arr_configs_arr_config_id");
|
||||
|
||||
b.Navigation("ArrConfig");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.DownloadCleaner.CleanCategory", b =>
|
||||
{
|
||||
b.HasOne("Cleanuparr.Persistence.Models.Configuration.DownloadCleaner.DownloadCleanerConfig", "DownloadCleanerConfig")
|
||||
.WithMany("Categories")
|
||||
.HasForeignKey("DownloadCleanerConfigId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_clean_categories_download_cleaner_configs_download_cleaner_config_id");
|
||||
|
||||
b.Navigation("DownloadCleanerConfig");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.Arr.ArrConfig", b =>
|
||||
{
|
||||
b.Navigation("Instances");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cleanuparr.Persistence.Models.Configuration.DownloadCleaner.DownloadCleanerConfig", b =>
|
||||
{
|
||||
b.Navigation("Categories");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Cleanuparr.Persistence.Migrations.Data
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddKnownMalwareOption : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "delete_known_malware",
|
||||
table: "content_blocker_configs",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "delete_known_malware",
|
||||
table: "content_blocker_configs");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,10 @@ namespace Cleanuparr.Persistence.Migrations.Data
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("cron_expression");
|
||||
|
||||
b.Property<bool>("DeleteKnownMalware")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("delete_known_malware");
|
||||
|
||||
b.Property<bool>("DeletePrivate")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("delete_private");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
|
||||
namespace Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
namespace Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
|
||||
/// <summary>
|
||||
/// Settings for a blocklist
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using ValidationException = System.ComponentModel.DataAnnotations.ValidationException;
|
||||
|
||||
namespace Cleanuparr.Persistence.Models.Configuration.ContentBlocker;
|
||||
namespace Cleanuparr.Persistence.Models.Configuration.MalwareBlocker;
|
||||
|
||||
public sealed record ContentBlockerConfig : IJobConfig
|
||||
{
|
||||
@@ -19,6 +19,8 @@ public sealed record ContentBlockerConfig : IJobConfig
|
||||
public bool IgnorePrivate { get; set; }
|
||||
|
||||
public bool DeletePrivate { get; set; }
|
||||
|
||||
public bool DeleteKnownMalware { get; set; }
|
||||
|
||||
public BlocklistSettings Sonarr { get; set; } = new();
|
||||
|
||||
@@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Cleanuparr.Shared.Helpers;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace Cleanuparr.Shared.Helpers;
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
@@ -7,4 +9,9 @@ public static class Constants
|
||||
public static readonly TimeSpan CacheLimitBuffer = TimeSpan.FromHours(2);
|
||||
|
||||
public const string HttpClientWithRetryName = "retry";
|
||||
|
||||
public static readonly MemoryCacheEntryOptions DefaultCacheEntryOptions = new()
|
||||
{
|
||||
SlidingExpiration = TimeSpan.FromMinutes(10)
|
||||
};
|
||||
}
|
||||
@@ -6,11 +6,28 @@ export const routes: Routes = [
|
||||
{ path: 'dashboard', loadComponent: () => import('./dashboard/dashboard-page/dashboard-page.component').then(m => m.DashboardPageComponent) },
|
||||
{ path: 'logs', loadComponent: () => import('./logging/logs-viewer/logs-viewer.component').then(m => m.LogsViewerComponent) },
|
||||
{ path: 'events', loadComponent: () => import('./events/events-viewer/events-viewer.component').then(m => m.EventsViewerComponent) },
|
||||
|
||||
{
|
||||
path: 'settings',
|
||||
loadComponent: () => import('./settings/settings-page/settings-page.component').then(m => m.SettingsPageComponent),
|
||||
path: 'general-settings',
|
||||
loadComponent: () => import('./settings/general-settings/general-settings.component').then(m => m.GeneralSettingsComponent),
|
||||
canDeactivate: [pendingChangesGuard]
|
||||
},
|
||||
{
|
||||
path: 'queue-cleaner',
|
||||
loadComponent: () => import('./settings/queue-cleaner/queue-cleaner-settings.component').then(m => m.QueueCleanerSettingsComponent),
|
||||
canDeactivate: [pendingChangesGuard]
|
||||
},
|
||||
{
|
||||
path: 'malware-blocker',
|
||||
loadComponent: () => import('./settings/malware-blocker/malware-blocker-settings.component').then(m => m.MalwareBlockerSettingsComponent),
|
||||
canDeactivate: [pendingChangesGuard]
|
||||
},
|
||||
{
|
||||
path: 'download-cleaner',
|
||||
loadComponent: () => import('./settings/download-cleaner/download-cleaner-settings.component').then(m => m.DownloadCleanerSettingsComponent),
|
||||
canDeactivate: [pendingChangesGuard]
|
||||
},
|
||||
|
||||
{ path: 'sonarr', loadComponent: () => import('./settings/sonarr/sonarr-settings.component').then(m => m.SonarrSettingsComponent) },
|
||||
{ path: 'radarr', loadComponent: () => import('./settings/radarr/radarr-settings.component').then(m => m.RadarrSettingsComponent) },
|
||||
{ path: 'lidarr', loadComponent: () => import('./settings/lidarr/lidarr-settings.component').then(m => m.LidarrSettingsComponent) },
|
||||
|
||||
@@ -2,7 +2,7 @@ import { HttpClient } from "@angular/common/http";
|
||||
import { Injectable, inject } from "@angular/core";
|
||||
import { Observable, catchError, map, throwError } from "rxjs";
|
||||
import { JobSchedule, QueueCleanerConfig, ScheduleUnit } from "../../shared/models/queue-cleaner-config.model";
|
||||
import { ContentBlockerConfig, JobSchedule as ContentBlockerJobSchedule, ScheduleUnit as ContentBlockerScheduleUnit } from "../../shared/models/content-blocker-config.model";
|
||||
import { MalwareBlockerConfig as MalwareBlockerConfig, JobSchedule as MalwareBlockerJobSchedule, ScheduleUnit as MalwareBlockerScheduleUnit } from "../../shared/models/malware-blocker-config.model";
|
||||
import { SonarrConfig } from "../../shared/models/sonarr-config.model";
|
||||
import { RadarrConfig } from "../../shared/models/radarr-config.model";
|
||||
import { LidarrConfig } from "../../shared/models/lidarr-config.model";
|
||||
@@ -81,15 +81,15 @@ export class ConfigurationService {
|
||||
/**
|
||||
* Get content blocker configuration
|
||||
*/
|
||||
getContentBlockerConfig(): Observable<ContentBlockerConfig> {
|
||||
return this.http.get<ContentBlockerConfig>(this.ApplicationPathService.buildApiUrl('/configuration/content_blocker')).pipe(
|
||||
getMalwareBlockerConfig(): Observable<MalwareBlockerConfig> {
|
||||
return this.http.get<MalwareBlockerConfig>(this.ApplicationPathService.buildApiUrl('/configuration/malware_blocker')).pipe(
|
||||
map((response) => {
|
||||
response.jobSchedule = this.tryExtractContentBlockerJobScheduleFromCron(response.cronExpression);
|
||||
response.jobSchedule = this.tryExtractMalwareBlockerJobScheduleFromCron(response.cronExpression);
|
||||
return response;
|
||||
}),
|
||||
catchError((error) => {
|
||||
console.error("Error fetching content blocker config:", error);
|
||||
return throwError(() => new Error("Failed to load content blocker configuration"));
|
||||
console.error("Error fetching Malware Blocker config:", error);
|
||||
return throwError(() => new Error("Failed to load Malware Blocker configuration"));
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -97,14 +97,14 @@ export class ConfigurationService {
|
||||
/**
|
||||
* Update content blocker configuration
|
||||
*/
|
||||
updateContentBlockerConfig(config: ContentBlockerConfig): Observable<void> {
|
||||
updateMalwareBlockerConfig(config: MalwareBlockerConfig): Observable<void> {
|
||||
// Generate cron expression if using basic scheduling
|
||||
if (!config.useAdvancedScheduling && config.jobSchedule) {
|
||||
config.cronExpression = this.convertContentBlockerJobScheduleToCron(config.jobSchedule);
|
||||
config.cronExpression = this.convertMalwareBlockerJobScheduleToCron(config.jobSchedule);
|
||||
}
|
||||
return this.http.put<void>(this.ApplicationPathService.buildApiUrl('/configuration/content_blocker'), config).pipe(
|
||||
return this.http.put<void>(this.ApplicationPathService.buildApiUrl('/configuration/malware_blocker'), config).pipe(
|
||||
catchError((error) => {
|
||||
console.error("Error updating content blocker config:", error);
|
||||
console.error("Error updating Malware Blocker config:", error);
|
||||
const errorMessage = ErrorHandlerUtil.extractErrorMessage(error);
|
||||
return throwError(() => new Error(errorMessage));
|
||||
})
|
||||
@@ -188,10 +188,10 @@ export class ConfigurationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to extract a ContentBlockerJobSchedule from a cron expression
|
||||
* Try to extract a MalwareBlockerJobSchedule from a cron expression
|
||||
* Only handles the simple cases we're generating
|
||||
*/
|
||||
private tryExtractContentBlockerJobScheduleFromCron(cronExpression: string): ContentBlockerJobSchedule | undefined {
|
||||
private tryExtractMalwareBlockerJobScheduleFromCron(cronExpression: string): MalwareBlockerJobSchedule | undefined {
|
||||
// Patterns we support:
|
||||
// Seconds: */n * * ? * * * or 0/n * * ? * * * (Quartz.NET format)
|
||||
// Minutes: 0 */n * ? * * * or 0 0/n * ? * * * (Quartz.NET format)
|
||||
@@ -205,7 +205,7 @@ export class ConfigurationService {
|
||||
if ((parts[0].startsWith("*/") || parts[0].startsWith("0/")) && parts[1] === "*") {
|
||||
const seconds = parseInt(parts[0].substring(2));
|
||||
if (!isNaN(seconds) && seconds > 0 && seconds < 60) {
|
||||
return { every: seconds, type: ContentBlockerScheduleUnit.Seconds };
|
||||
return { every: seconds, type: MalwareBlockerScheduleUnit.Seconds };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ export class ConfigurationService {
|
||||
if (parts[0] === "0" && (parts[1].startsWith("*/") || parts[1].startsWith("0/"))) {
|
||||
const minutes = parseInt(parts[1].substring(2));
|
||||
if (!isNaN(minutes) && minutes > 0 && minutes < 60) {
|
||||
return { every: minutes, type: ContentBlockerScheduleUnit.Minutes };
|
||||
return { every: minutes, type: MalwareBlockerScheduleUnit.Minutes };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ export class ConfigurationService {
|
||||
if (parts[0] === "0" && parts[1] === "0" && (parts[2].startsWith("*/") || parts[2].startsWith("0/"))) {
|
||||
const hours = parseInt(parts[2].substring(2));
|
||||
if (!isNaN(hours) && hours > 0 && hours < 24) {
|
||||
return { every: hours, type: ContentBlockerScheduleUnit.Hours };
|
||||
return { every: hours, type: MalwareBlockerScheduleUnit.Hours };
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -232,27 +232,27 @@ export class ConfigurationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ContentBlockerJobSchedule to a cron expression
|
||||
* Convert a MalwareBlockerJobSchedule to a cron expression
|
||||
*/
|
||||
private convertContentBlockerJobScheduleToCron(schedule: ContentBlockerJobSchedule): string {
|
||||
private convertMalwareBlockerJobScheduleToCron(schedule: MalwareBlockerJobSchedule): string {
|
||||
if (!schedule || schedule.every <= 0) {
|
||||
return "0/5 * * * * ?"; // Default: every 5 seconds (Quartz.NET format)
|
||||
}
|
||||
|
||||
switch (schedule.type) {
|
||||
case ContentBlockerScheduleUnit.Seconds:
|
||||
case MalwareBlockerScheduleUnit.Seconds:
|
||||
if (schedule.every < 60) {
|
||||
return `0/${schedule.every} * * ? * * *`; // Quartz.NET format
|
||||
}
|
||||
break;
|
||||
|
||||
case ContentBlockerScheduleUnit.Minutes:
|
||||
case MalwareBlockerScheduleUnit.Minutes:
|
||||
if (schedule.every < 60) {
|
||||
return `0 0/${schedule.every} * ? * * *`; // Quartz.NET format
|
||||
}
|
||||
break;
|
||||
|
||||
case ContentBlockerScheduleUnit.Hours:
|
||||
case MalwareBlockerScheduleUnit.Hours:
|
||||
if (schedule.every < 24) {
|
||||
return `0 0 0/${schedule.every} ? * * *`; // Quartz.NET format
|
||||
}
|
||||
|
||||
@@ -63,14 +63,15 @@ export class DocumentationService {
|
||||
'unlinkedIgnoredRootDir': 'ignored-root-directory',
|
||||
'unlinkedCategories': 'unlinked-categories'
|
||||
},
|
||||
'content-blocker': {
|
||||
'enabled': 'enable-content-blocker',
|
||||
'malware-blocker': {
|
||||
'enabled': 'enable-malware-blocker',
|
||||
'useAdvancedScheduling': 'scheduling-mode',
|
||||
'cronExpression': 'cron-expression',
|
||||
'jobSchedule.every': 'run-schedule',
|
||||
'jobSchedule.type': 'run-schedule',
|
||||
'ignorePrivate': 'ignore-private',
|
||||
'deletePrivate': 'delete-private',
|
||||
'deleteKnownMalware': 'delete-known-malware',
|
||||
'sonarr.enabled': 'enable-sonarr-blocklist',
|
||||
'sonarr.blocklistPath': 'sonarr-blocklist-path',
|
||||
'sonarr.blocklistType': 'sonarr-blocklist-type',
|
||||
@@ -84,7 +85,7 @@ export class DocumentationService {
|
||||
'download-client': {
|
||||
'enabled': 'enable-download-client',
|
||||
'name': 'client-name',
|
||||
'type': 'client-type',
|
||||
'typeName': 'client-type',
|
||||
'host': 'client-host',
|
||||
'urlBase': 'url-base-path',
|
||||
'username': 'username',
|
||||
|
||||
@@ -10,115 +10,105 @@
|
||||
</div>
|
||||
|
||||
<!-- Sidebar Navigation -->
|
||||
<nav class="nav-menu">
|
||||
<!-- Project Sponsors Link -->
|
||||
<a href="https://cleanuparr.github.io/Cleanuparr/support" class="nav-item sponsor-link" target="_blank" rel="noopener noreferrer">
|
||||
<!-- Show loading skeleton while determining navigation state -->
|
||||
<nav class="nav-menu" *ngIf="!isNavigationReady">
|
||||
<div class="nav-skeleton">
|
||||
<div class="skeleton-item"
|
||||
*ngFor="let item of getSkeletonItems()"
|
||||
[class.sponsor-skeleton]="item.isSponsor">
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Show actual navigation when ready -->
|
||||
<nav class="nav-menu"
|
||||
*ngIf="isNavigationReady"
|
||||
[@staggerItems]>
|
||||
<!-- Project Sponsors Link (always visible) -->
|
||||
<a href="https://cleanuparr.github.io/Cleanuparr/support"
|
||||
class="nav-item sponsor-link"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
<div class="nav-icon-wrapper heart-icon">
|
||||
<i class="pi pi-heart"></i>
|
||||
</div>
|
||||
<span>Become A Sponsor</span>
|
||||
</a>
|
||||
|
||||
<a [routerLink]="['/dashboard']" class="nav-item" [class.active]="router.url.includes('/dashboard')" (click)="onNavItemClick()">
|
||||
<!-- Go Back button (shown when not at root level) -->
|
||||
<div class="nav-item go-back-button"
|
||||
*ngIf="canGoBack"
|
||||
(click)="goBack()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-home"></i>
|
||||
<i class="pi pi-arrow-left"></i>
|
||||
</div>
|
||||
<span>Dashboard</span>
|
||||
</a>
|
||||
|
||||
<!-- Settings Group -->
|
||||
<div class="nav-group">
|
||||
<div class="nav-group-title">Settings</div>
|
||||
<a [routerLink]="['/sonarr']" class="nav-item" [class.active]="router.url.includes('/sonarr')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-play-circle"></i>
|
||||
</div>
|
||||
<span>Sonarr</span>
|
||||
</a>
|
||||
<a [routerLink]="['/radarr']" class="nav-item" [class.active]="router.url.includes('/radarr')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-play-circle"></i>
|
||||
</div>
|
||||
<span>Radarr</span>
|
||||
</a>
|
||||
<a [routerLink]="['/lidarr']" class="nav-item" [class.active]="router.url.includes('/lidarr')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-bolt"></i>
|
||||
</div>
|
||||
<span>Lidarr</span>
|
||||
</a>
|
||||
<a [routerLink]="['/readarr']" class="nav-item" [class.active]="router.url.includes('/readarr')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-book"></i>
|
||||
</div>
|
||||
<span>Readarr</span>
|
||||
</a>
|
||||
<a [routerLink]="['/whisparr']" class="nav-item" [class.active]="router.url.includes('/whisparr')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-lock"></i>
|
||||
</div>
|
||||
<span>Whisparr</span>
|
||||
</a>
|
||||
<a [routerLink]="['/download-clients']" class="nav-item" [class.active]="router.url.includes('/download-clients')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-download"></i>
|
||||
</div>
|
||||
<span>Download Clients</span>
|
||||
</a>
|
||||
<a [routerLink]="['/settings']" class="nav-item" [class.active]="router.url.includes('/settings')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-trash"></i>
|
||||
</div>
|
||||
<span>Cleanup</span>
|
||||
</a>
|
||||
<a [routerLink]="['/notifications']" class="nav-item" [class.active]="router.url.includes('/notifications')" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-bell"></i>
|
||||
</div>
|
||||
<span>Notifications</span>
|
||||
</a>
|
||||
<span>Go Back</span>
|
||||
</div>
|
||||
|
||||
<!-- Activity Group -->
|
||||
<div class="nav-group">
|
||||
<div class="nav-group-title">Activity</div>
|
||||
<ng-container *ngFor="let item of menuItems">
|
||||
<ng-container *ngIf="!['Dashboard', 'Settings'].includes(item.label)">
|
||||
<a [routerLink]="item.route" class="nav-item" [class.active]="router.url.includes(item.route)" (click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i [class]="item.icon"></i>
|
||||
</div>
|
||||
<span>{{ item.label }}</span>
|
||||
</a>
|
||||
</ng-container>
|
||||
|
||||
<!-- Breadcrumb (optional, for better UX) -->
|
||||
<div class="breadcrumb"
|
||||
*ngIf="navigationBreadcrumb.length > 0">
|
||||
<span *ngFor="let crumb of navigationBreadcrumb; let last = last; trackBy: trackByBreadcrumb">
|
||||
{{ crumb.label }}
|
||||
<i class="pi pi-chevron-right" *ngIf="!last"></i>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Navigation items container with container-level animation -->
|
||||
<div class="navigation-items-container"
|
||||
[@navigationContainer]="navigationStateKey">
|
||||
<!-- Current level navigation items -->
|
||||
<ng-container *ngFor="let item of currentNavigation; trackBy: trackByItemId">
|
||||
<!-- Section headers for top-level sections -->
|
||||
<div
|
||||
class="nav-section-header"
|
||||
*ngIf="item.isHeader">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i [class]="item.icon"></i>
|
||||
</div>
|
||||
<span>{{ item.label }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Items with children (drill-down) - exclude top-level items -->
|
||||
<div
|
||||
class="nav-item nav-parent"
|
||||
*ngIf="item.children && item.children.length > 0 && !item.topLevel"
|
||||
(click)="navigateToLevel(item)">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i [class]="item.icon"></i>
|
||||
</div>
|
||||
<span>{{ item.label }}</span>
|
||||
<div class="nav-chevron">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Direct navigation items -->
|
||||
<a
|
||||
[routerLink]="item.route"
|
||||
class="nav-item"
|
||||
*ngIf="!item.children && item.route && !item.isHeader"
|
||||
[class.active]="router.url.includes(item.route)"
|
||||
(click)="onNavItemClick()">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i [class]="item.icon"></i>
|
||||
</div>
|
||||
<span>{{ item.label }}</span>
|
||||
<span class="nav-badge" *ngIf="item.badge">{{ item.badge }}</span>
|
||||
</a>
|
||||
|
||||
<!-- External links -->
|
||||
<a
|
||||
[href]="item.href"
|
||||
class="nav-item"
|
||||
*ngIf="!item.children && item.isExternal && !item.isHeader"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i [class]="item.icon"></i>
|
||||
</div>
|
||||
<span>{{ item.label }}</span>
|
||||
</a>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
||||
<!-- Resources Group -->
|
||||
<div class="nav-group">
|
||||
<div class="nav-group-title">Resources</div>
|
||||
<a href="https://github.com/Cleanuparr/Cleanuparr/issues" class="nav-item" target="_blank" rel="noopener noreferrer">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-github"></i>
|
||||
</div>
|
||||
<span>Issues and requests</span>
|
||||
</a>
|
||||
|
||||
<a href="https://discord.gg/SCtMCgtsc4" class="nav-item" target="_blank" rel="noopener noreferrer">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-discord"></i>
|
||||
</div>
|
||||
<span>Discord</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="nav-group">
|
||||
<div class="nav-group-title">Recommended apps</div>
|
||||
<a href="https://github.com/plexguide/Huntarr.io" class="nav-item" target="_blank" rel="noopener noreferrer">
|
||||
<div class="nav-icon-wrapper">
|
||||
<i class="pi pi-github"></i>
|
||||
</div>
|
||||
<span>Huntarr</span>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
// Main container stability
|
||||
:host {
|
||||
display: block;
|
||||
height: 100%;
|
||||
overflow: hidden; // Prevent scrolling
|
||||
position: relative;
|
||||
}
|
||||
|
||||
// Logo container
|
||||
.logo-container {
|
||||
display: flex;
|
||||
@@ -50,7 +58,69 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
gap: 1rem;
|
||||
gap: 0; // Remove gap to prevent layout shifts
|
||||
transition: opacity 0.2s ease;
|
||||
|
||||
// Prevent horizontal scrolling
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
|
||||
// Fixed minimum height to prevent jumping
|
||||
min-height: 400px;
|
||||
|
||||
// Navigation items container for smooth animations
|
||||
.navigation-items-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px; // Consistent spacing between navigation items
|
||||
position: relative; // Ensure proper stacking context for animations
|
||||
width: 100%; // Take full width of parent
|
||||
}
|
||||
|
||||
// Loading skeleton
|
||||
.nav-skeleton {
|
||||
padding: 0;
|
||||
|
||||
.skeleton-item {
|
||||
height: 60px; // Match actual nav-item height
|
||||
padding: 10px 20px; // Match nav-item padding
|
||||
margin-bottom: 8px; // Match nav-item spacing
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 6px;
|
||||
background: linear-gradient(90deg, var(--surface-200) 25%, var(--surface-300) 50%, var(--surface-200) 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: skeleton-loading 1.5s infinite;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&.sponsor-skeleton {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
// Add fake icon and text areas to match real content
|
||||
&::before {
|
||||
content: '';
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
background: var(--surface-300);
|
||||
margin-right: 15px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
height: 20px;
|
||||
background: var(--surface-300);
|
||||
border-radius: 4px;
|
||||
flex: 1;
|
||||
max-width: 120px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sponsor link
|
||||
.sponsor-link {
|
||||
@@ -67,20 +137,78 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nav groups
|
||||
.nav-group {
|
||||
|
||||
// Go back button styling
|
||||
.go-back-button {
|
||||
background-color: var(--surface-200);
|
||||
border: 1px solid var(--surface-300);
|
||||
margin-bottom: 15px;
|
||||
cursor: pointer;
|
||||
|
||||
.nav-group-title {
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
color: var(--text-color-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 2px;
|
||||
padding: 0 20px 8px;
|
||||
margin: 5px 0;
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
&:hover {
|
||||
transform: translateX(2px);
|
||||
background-color: var(--surface-300);
|
||||
|
||||
.nav-icon-wrapper i {
|
||||
transform: translateX(-2px);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Breadcrumb styling
|
||||
.breadcrumb {
|
||||
padding: 8px 20px;
|
||||
font-size: 12px;
|
||||
color: var(--text-color-secondary);
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
margin-bottom: 10px;
|
||||
overflow: hidden;
|
||||
transition: all 0.25s ease;
|
||||
|
||||
span {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
i {
|
||||
margin: 0 8px;
|
||||
font-size: 10px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
}
|
||||
|
||||
// Section headers for top-level sections
|
||||
.nav-section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px 20px 4px;
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
margin: 15px 0 8px 0;
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
|
||||
.nav-icon-wrapper {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-right: 12px;
|
||||
border-radius: 4px;
|
||||
background: var(--surface-200);
|
||||
flex-shrink: 0;
|
||||
|
||||
i {
|
||||
font-size: 12px;
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +222,12 @@
|
||||
border-radius: 0 6px 6px 0;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: all 0.2s ease;
|
||||
transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
|
||||
margin-bottom: 8px; // Consistent spacing instead of gap
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.nav-icon-wrapper {
|
||||
width: 40px;
|
||||
@@ -106,17 +239,33 @@
|
||||
border-radius: 8px;
|
||||
background: var(--surface-card);
|
||||
border: 1px solid var(--surface-border);
|
||||
transition: all 0.2s ease;
|
||||
transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
|
||||
flex-shrink: 0; // Prevent icon from shrinking
|
||||
|
||||
i {
|
||||
font-size: 20px;
|
||||
color: var(--text-color-secondary);
|
||||
transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
|
||||
}
|
||||
}
|
||||
|
||||
span {
|
||||
white-space: nowrap;
|
||||
font-size: 14px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
flex: 1; // Take available space
|
||||
}
|
||||
|
||||
.nav-badge {
|
||||
margin-left: auto;
|
||||
background-color: var(--primary-color);
|
||||
color: var(--primary-color-text);
|
||||
border-radius: 12px;
|
||||
padding: 2px 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&::before {
|
||||
@@ -131,7 +280,9 @@
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateX(4px);
|
||||
background-color: var(--surface-hover);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
|
||||
.nav-icon-wrapper {
|
||||
background-color: rgba(var(--primary-500-rgb), 0.1);
|
||||
@@ -161,6 +312,38 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parent navigation items (with children)
|
||||
.nav-parent {
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
|
||||
.nav-chevron {
|
||||
margin-left: auto;
|
||||
opacity: 0.6;
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
|
||||
flex-shrink: 0;
|
||||
|
||||
i {
|
||||
font-size: 16px;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover .nav-chevron i {
|
||||
transform: translateX(3px) scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loading skeleton animation
|
||||
@keyframes skeleton-loading {
|
||||
0% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Animation keyframes
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Component, Input, inject, Output, EventEmitter } from '@angular/core';
|
||||
import { Component, Input, inject, Output, EventEmitter, OnInit, OnChanges, SimpleChanges, OnDestroy } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { Router, RouterLink, NavigationEnd } from '@angular/router';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { trigger, state, style, transition, animate, query, stagger } from '@angular/animations';
|
||||
|
||||
interface MenuItem {
|
||||
label: string;
|
||||
@@ -10,6 +13,24 @@ interface MenuItem {
|
||||
badge?: string;
|
||||
}
|
||||
|
||||
interface NavigationItem {
|
||||
id: string;
|
||||
label: string;
|
||||
icon: string;
|
||||
route?: string; // For direct navigation items
|
||||
children?: NavigationItem[]; // For parent items with sub-menus
|
||||
isExternal?: boolean; // For external links
|
||||
href?: string; // For external URLs
|
||||
badge?: string; // For notification badges
|
||||
topLevel?: boolean; // If true, shows children directly on top level instead of drill-down
|
||||
isHeader?: boolean; // If true, renders as a section header (non-clickable)
|
||||
}
|
||||
|
||||
interface RouteMapping {
|
||||
route: string;
|
||||
navigationPath: string[]; // Array of navigation item IDs leading to this route
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidebar-content',
|
||||
standalone: true,
|
||||
@@ -19,9 +40,37 @@ interface MenuItem {
|
||||
ButtonModule
|
||||
],
|
||||
templateUrl: './sidebar-content.component.html',
|
||||
styleUrl: './sidebar-content.component.scss'
|
||||
styleUrl: './sidebar-content.component.scss',
|
||||
animations: [
|
||||
trigger('staggerItems', [
|
||||
transition(':enter', [
|
||||
query(':enter', [
|
||||
style({ transform: 'translateX(30px)', opacity: 0 }),
|
||||
stagger('50ms', [
|
||||
animate('300ms cubic-bezier(0.4, 0.0, 0.2, 1)', style({ transform: 'translateX(0)', opacity: 1 }))
|
||||
])
|
||||
], { optional: true })
|
||||
])
|
||||
]),
|
||||
// Container-level navigation animation (replaces individual item animations)
|
||||
trigger('navigationContainer', [
|
||||
transition('* => *', [
|
||||
style({ transform: 'translateX(100%)', opacity: 0 }),
|
||||
animate('300ms cubic-bezier(0.4, 0.0, 0.2, 1)',
|
||||
style({ transform: 'translateX(0)', opacity: 1 })
|
||||
)
|
||||
])
|
||||
]),
|
||||
// Simple fade in animation for initial load
|
||||
trigger('fadeIn', [
|
||||
transition(':enter', [
|
||||
style({ opacity: 0 }),
|
||||
animate('200ms ease-out', style({ opacity: 1 }))
|
||||
])
|
||||
])
|
||||
]
|
||||
})
|
||||
export class SidebarContentComponent {
|
||||
export class SidebarContentComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@Input() menuItems: MenuItem[] = [];
|
||||
@Input() isMobile = false;
|
||||
@Output() navItemClicked = new EventEmitter<void>();
|
||||
@@ -29,6 +78,404 @@ export class SidebarContentComponent {
|
||||
// Inject router for active route styling
|
||||
public router = inject(Router);
|
||||
|
||||
// New properties for drill-down navigation
|
||||
navigationData: NavigationItem[] = [];
|
||||
currentNavigation: NavigationItem[] = [];
|
||||
navigationBreadcrumb: NavigationItem[] = [];
|
||||
canGoBack = false;
|
||||
|
||||
// Pre-rendering optimization properties
|
||||
isNavigationReady = false;
|
||||
private hasInitialized = false;
|
||||
|
||||
// Animation trigger property - changes to force re-render and trigger animations
|
||||
navigationStateKey = 0;
|
||||
|
||||
// Route synchronization properties
|
||||
private routerSubscription?: Subscription;
|
||||
private routeMappings: RouteMapping[] = [
|
||||
// Dashboard
|
||||
{ route: '/dashboard', navigationPath: ['dashboard'] },
|
||||
|
||||
// Media Management routes
|
||||
{ route: '/sonarr', navigationPath: ['media-apps', 'sonarr'] },
|
||||
{ route: '/radarr', navigationPath: ['media-apps', 'radarr'] },
|
||||
{ route: '/lidarr', navigationPath: ['media-apps', 'lidarr'] },
|
||||
{ route: '/readarr', navigationPath: ['media-apps', 'readarr'] },
|
||||
{ route: '/whisparr', navigationPath: ['media-apps', 'whisparr'] },
|
||||
{ route: '/download-clients', navigationPath: ['media-apps', 'download-clients'] },
|
||||
|
||||
// Settings routes
|
||||
{ route: '/general-settings', navigationPath: ['settings', 'general'] },
|
||||
{ route: '/queue-cleaner', navigationPath: ['settings', 'queue-cleaner'] },
|
||||
{ route: '/malware-blocker', navigationPath: ['settings', 'malware-blocker'] },
|
||||
{ route: '/download-cleaner', navigationPath: ['settings', 'download-cleaner'] },
|
||||
{ route: '/notifications', navigationPath: ['settings', 'notifications'] },
|
||||
|
||||
// Other routes will be handled dynamically
|
||||
];
|
||||
|
||||
ngOnInit(): void {
|
||||
// Start with loading state
|
||||
this.isNavigationReady = false;
|
||||
|
||||
// Initialize navigation after showing skeleton
|
||||
setTimeout(() => {
|
||||
this.initializeNavigation();
|
||||
}, 100);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['menuItems']) {
|
||||
this.updateActivityItems();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.routerSubscription?.unsubscribe();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize navigation and determine correct level based on route
|
||||
*/
|
||||
private initializeNavigation(): void {
|
||||
if (this.hasInitialized) return;
|
||||
|
||||
// 1. Initialize navigation data
|
||||
this.setupNavigationData();
|
||||
|
||||
// 2. Update activity items if available
|
||||
if (this.menuItems && this.menuItems.length > 0) {
|
||||
this.updateActivityItems();
|
||||
}
|
||||
|
||||
// 3. Determine correct navigation level based on current route
|
||||
this.syncSidebarWithCurrentRoute();
|
||||
|
||||
// 4. Mark as ready and subscribe to route changes
|
||||
this.isNavigationReady = true;
|
||||
this.hasInitialized = true;
|
||||
this.subscribeToRouteChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup basic navigation data structure
|
||||
*/
|
||||
private setupNavigationData(): void {
|
||||
this.navigationData = this.getNavigationData();
|
||||
this.currentNavigation = this.buildTopLevelNavigation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build top-level navigation including expanded sections marked with topLevel: true
|
||||
*/
|
||||
private buildTopLevelNavigation(): NavigationItem[] {
|
||||
const topLevelItems: NavigationItem[] = [];
|
||||
|
||||
for (const item of this.navigationData) {
|
||||
if (item.topLevel && item.children) {
|
||||
// Add section header
|
||||
topLevelItems.push({
|
||||
id: `${item.id}-header`,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
isHeader: true
|
||||
});
|
||||
|
||||
// Add all children directly to top level
|
||||
topLevelItems.push(...item.children);
|
||||
} else {
|
||||
// Add item normally (drill-down behavior)
|
||||
topLevelItems.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
return topLevelItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the navigation data structure
|
||||
*/
|
||||
private getNavigationData(): NavigationItem[] {
|
||||
return [
|
||||
{
|
||||
id: 'dashboard',
|
||||
label: 'Dashboard',
|
||||
icon: 'pi pi-home',
|
||||
route: '/dashboard'
|
||||
},
|
||||
{
|
||||
id: 'media-apps',
|
||||
label: 'Media Apps',
|
||||
icon: 'pi pi-play-circle',
|
||||
children: [
|
||||
{ id: 'sonarr', label: 'Sonarr', icon: 'pi pi-play-circle', route: '/sonarr' },
|
||||
{ id: 'radarr', label: 'Radarr', icon: 'pi pi-play-circle', route: '/radarr' },
|
||||
{ id: 'lidarr', label: 'Lidarr', icon: 'pi pi-bolt', route: '/lidarr' },
|
||||
{ id: 'readarr', label: 'Readarr', icon: 'pi pi-book', route: '/readarr' },
|
||||
{ id: 'whisparr', label: 'Whisparr', icon: 'pi pi-lock', route: '/whisparr' },
|
||||
{ id: 'download-clients', label: 'Download Clients', icon: 'pi pi-download', route: '/download-clients' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'settings',
|
||||
label: 'Settings',
|
||||
icon: 'pi pi-cog',
|
||||
children: [
|
||||
{ id: 'general', label: 'General', icon: 'pi pi-cog', route: '/general-settings' },
|
||||
{ id: 'queue-cleaner', label: 'Queue Cleaner', icon: 'pi pi-list', route: '/queue-cleaner' },
|
||||
{ id: 'malware-blocker', label: 'Malware Blocker', icon: 'pi pi-shield', route: '/malware-blocker' },
|
||||
{ id: 'download-cleaner', label: 'Download Cleaner', icon: 'pi pi-trash', route: '/download-cleaner' },
|
||||
{ id: 'notifications', label: 'Notifications', icon: 'pi pi-bell', route: '/notifications' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'activity',
|
||||
label: 'Activity',
|
||||
icon: 'pi pi-chart-line',
|
||||
children: [] // Will be populated dynamically from menuItems
|
||||
},
|
||||
{
|
||||
id: 'help-support',
|
||||
label: 'Help & Support',
|
||||
icon: 'pi pi-question-circle',
|
||||
children: [
|
||||
{
|
||||
id: 'issues',
|
||||
label: 'Issues and Requests',
|
||||
icon: 'pi pi-github',
|
||||
isExternal: true,
|
||||
href: 'https://github.com/Cleanuparr/Cleanuparr/issues'
|
||||
},
|
||||
{
|
||||
id: 'discord',
|
||||
label: 'Discord',
|
||||
icon: 'pi pi-discord',
|
||||
isExternal: true,
|
||||
href: 'https://discord.gg/SCtMCgtsc4'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'suggested-apps',
|
||||
label: 'Suggested Apps',
|
||||
topLevel: true,
|
||||
icon: 'pi pi-star',
|
||||
children: [
|
||||
{
|
||||
id: 'huntarr',
|
||||
label: 'Huntarr',
|
||||
icon: 'pi pi-github',
|
||||
isExternal: true,
|
||||
href: 'https://github.com/plexguide/Huntarr.io'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to route mapping synchronously without delays
|
||||
*/
|
||||
private navigateToRouteMappingSync(mapping: RouteMapping): void {
|
||||
// No delays, no async operations - just set the state
|
||||
this.navigationBreadcrumb = [];
|
||||
this.currentNavigation = this.buildTopLevelNavigation();
|
||||
|
||||
for (let i = 0; i < mapping.navigationPath.length - 1; i++) {
|
||||
const itemId = mapping.navigationPath[i];
|
||||
// Find in original navigation data, not the flattened version
|
||||
const item = this.navigationData.find(nav => nav.id === itemId);
|
||||
|
||||
if (item && item.children && !item.topLevel) {
|
||||
// Only drill down if it's not a top-level section
|
||||
this.navigationBreadcrumb.push(item);
|
||||
this.currentNavigation = [...item.children];
|
||||
}
|
||||
}
|
||||
|
||||
this.updateNavigationState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skeleton items based on predicted navigation state
|
||||
*/
|
||||
getSkeletonItems(): Array<{isSponsor: boolean}> {
|
||||
const currentRoute = this.router.url;
|
||||
const mapping = this.findRouteMapping(currentRoute);
|
||||
|
||||
if (mapping && mapping.navigationPath.length > 1) {
|
||||
// We'll show sub-navigation, predict item count
|
||||
return [
|
||||
{ isSponsor: true },
|
||||
{ isSponsor: false }, // Go back
|
||||
...Array(6).fill({ isSponsor: false }) // Estimated items
|
||||
];
|
||||
}
|
||||
|
||||
// Default main navigation count
|
||||
return [
|
||||
{ isSponsor: true },
|
||||
...Array(5).fill({ isSponsor: false })
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* TrackBy function for better performance
|
||||
*/
|
||||
trackByItemId(index: number, item: NavigationItem): string {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* TrackBy function that includes navigation state for animation triggers
|
||||
*/
|
||||
trackByItemIdWithState(index: number, item: NavigationItem): string {
|
||||
return `${item.id}-${this.navigationStateKey}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* TrackBy function for breadcrumb items
|
||||
*/
|
||||
trackByBreadcrumb(index: number, item: NavigationItem): string {
|
||||
return `${item.id}-${index}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update activity items from menuItems input
|
||||
*/
|
||||
private updateActivityItems(): void {
|
||||
const activityItem = this.navigationData.find(item => item.id === 'activity');
|
||||
if (activityItem && this.menuItems) {
|
||||
activityItem.children = this.menuItems
|
||||
.filter(item => !['Dashboard', 'Settings'].includes(item.label))
|
||||
.map(item => ({
|
||||
id: item.label.toLowerCase().replace(/\s+/g, '-'),
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
route: item.route,
|
||||
badge: item.badge
|
||||
}));
|
||||
|
||||
// Update route mappings for activity items
|
||||
this.updateActivityRouteMappings();
|
||||
|
||||
// Update current navigation if we're showing the root level
|
||||
if (this.navigationBreadcrumb.length === 0) {
|
||||
this.currentNavigation = this.buildTopLevelNavigation();
|
||||
}
|
||||
|
||||
// Re-sync with current route to handle activity routes
|
||||
this.syncSidebarWithCurrentRoute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update route mappings for activity items
|
||||
*/
|
||||
private updateActivityRouteMappings(): void {
|
||||
// Remove old activity mappings
|
||||
this.routeMappings = this.routeMappings.filter(mapping =>
|
||||
!mapping.navigationPath[0] || !mapping.navigationPath[0].startsWith('activity')
|
||||
);
|
||||
|
||||
// Add new activity mappings
|
||||
const activityItem = this.navigationData.find(item => item.id === 'activity');
|
||||
if (activityItem?.children) {
|
||||
activityItem.children.forEach(child => {
|
||||
if (child.route) {
|
||||
this.routeMappings.push({
|
||||
route: child.route,
|
||||
navigationPath: ['activity', child.id]
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync sidebar state with current route
|
||||
*/
|
||||
private syncSidebarWithCurrentRoute(): void {
|
||||
const currentRoute = this.router.url;
|
||||
const mapping = this.findRouteMapping(currentRoute);
|
||||
|
||||
if (mapping) {
|
||||
this.navigateToRouteMapping(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find route mapping for current route
|
||||
*/
|
||||
private findRouteMapping(route: string): RouteMapping | null {
|
||||
// Find exact match first, or routes that start with the mapping route
|
||||
const mapping = this.routeMappings.find(m =>
|
||||
route === m.route || route.startsWith(m.route + '/')
|
||||
);
|
||||
|
||||
return mapping || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate sidebar to match route mapping (used by route sync)
|
||||
*/
|
||||
private navigateToRouteMapping(mapping: RouteMapping): void {
|
||||
// Use the synchronous version
|
||||
this.navigateToRouteMappingSync(mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to route changes for real-time synchronization
|
||||
*/
|
||||
private subscribeToRouteChanges(): void {
|
||||
this.routerSubscription = this.router.events
|
||||
.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
this.syncSidebarWithCurrentRoute();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to a sub-level with animation trigger
|
||||
*/
|
||||
navigateToLevel(item: NavigationItem): void {
|
||||
if (item.children && item.children.length > 0) {
|
||||
this.navigationBreadcrumb.push(item);
|
||||
this.currentNavigation = item.children ? [...item.children] : [];
|
||||
this.navigationStateKey++; // Force animation trigger
|
||||
this.updateNavigationState();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Go back to the previous level with animation trigger
|
||||
*/
|
||||
goBack(): void {
|
||||
if (this.navigationBreadcrumb.length > 0) {
|
||||
this.navigationBreadcrumb.pop();
|
||||
|
||||
if (this.navigationBreadcrumb.length === 0) {
|
||||
// Back to root level - use top-level navigation
|
||||
this.currentNavigation = this.buildTopLevelNavigation();
|
||||
} else {
|
||||
// Back to parent level
|
||||
const parent = this.navigationBreadcrumb[this.navigationBreadcrumb.length - 1];
|
||||
this.currentNavigation = parent.children ? [...parent.children] : [];
|
||||
}
|
||||
|
||||
this.navigationStateKey++; // Force animation trigger
|
||||
this.updateNavigationState();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update navigation state
|
||||
*/
|
||||
private updateNavigationState(): void {
|
||||
this.canGoBack = this.navigationBreadcrumb.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle navigation item click
|
||||
*/
|
||||
|
||||
@@ -11,14 +11,6 @@
|
||||
></p-tag>
|
||||
</div>
|
||||
<div class="log-controls flex align-items-center gap-2">
|
||||
<div class="auto-scroll-toggle">
|
||||
<p-inputSwitch
|
||||
[ngModel]="autoScroll()"
|
||||
(ngModelChange)="setAutoScroll($event)"
|
||||
id="autoScrollToggle"
|
||||
></p-inputSwitch>
|
||||
<label for="autoScrollToggle" class="ml-2 text-sm">Auto-scroll</label>
|
||||
</div>
|
||||
<button
|
||||
pButton
|
||||
icon="pi pi-download"
|
||||
@@ -112,7 +104,7 @@
|
||||
|
||||
<div class="card-content">
|
||||
<!-- Console-style Logs View -->
|
||||
<div class="viewer-console" #logsConsole>
|
||||
<div class="viewer-console">
|
||||
<!-- Logs List -->
|
||||
<div class="items-list" *ngIf="filteredLogs().length > 0; else emptyLogs">
|
||||
<div *ngFor="let log of filteredLogs(); let i = index" class="item-entry" [id]="'log-' + i">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, OnInit, OnDestroy, signal, computed, inject, ViewChild, ElementRef } from '@angular/core';
|
||||
import { Component, OnInit, OnDestroy, signal, computed, inject, ViewChild } from '@angular/core';
|
||||
import { DatePipe, NgFor, NgIf } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { Subject, takeUntil, debounceTime, distinctUntilChanged } from 'rxjs';
|
||||
@@ -14,7 +14,6 @@ import { CardModule } from 'primeng/card';
|
||||
import { ToolbarModule } from 'primeng/toolbar';
|
||||
import { TooltipModule } from 'primeng/tooltip';
|
||||
import { ProgressSpinnerModule } from 'primeng/progressspinner';
|
||||
import { InputSwitchModule } from 'primeng/inputswitch';
|
||||
|
||||
// Services & Models
|
||||
import { AppHubService } from '../../core/services/app-hub.service';
|
||||
@@ -39,8 +38,7 @@ import { MenuItem } from 'primeng/api';
|
||||
ToolbarModule,
|
||||
TooltipModule,
|
||||
ProgressSpinnerModule,
|
||||
MenuModule,
|
||||
InputSwitchModule
|
||||
MenuModule
|
||||
],
|
||||
providers: [AppHubService],
|
||||
templateUrl: './logs-viewer.component.html',
|
||||
@@ -52,13 +50,11 @@ export class LogsViewerComponent implements OnInit, OnDestroy {
|
||||
private clipboard = inject(Clipboard);
|
||||
private search$ = new Subject<string>();
|
||||
|
||||
@ViewChild('logsConsole') logsConsole!: ElementRef;
|
||||
@ViewChild('exportMenu') exportMenu: any;
|
||||
|
||||
// Signals for reactive state
|
||||
logs = signal<LogEntry[]>([]);
|
||||
isConnected = signal<boolean>(false);
|
||||
autoScroll = signal<boolean>(true);
|
||||
expandedLogs: { [key: number]: boolean } = {};
|
||||
|
||||
// Filter state
|
||||
@@ -92,7 +88,8 @@ export class LogsViewerComponent implements OnInit, OnDestroy {
|
||||
(log.exception && log.exception.toLowerCase().includes(search)));
|
||||
}
|
||||
|
||||
return filtered;
|
||||
// Sort by timestamp descending (newest first)
|
||||
return filtered.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
||||
});
|
||||
|
||||
levels = computed(() => {
|
||||
@@ -117,9 +114,6 @@ export class LogsViewerComponent implements OnInit, OnDestroy {
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((logs: LogEntry[]) => {
|
||||
this.logs.set(logs);
|
||||
if (this.autoScroll()) {
|
||||
this.scrollToBottom();
|
||||
}
|
||||
});
|
||||
|
||||
// Subscribe to connection status
|
||||
@@ -141,12 +135,6 @@ export class LogsViewerComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewChecked(): void {
|
||||
if (this.autoScroll() && this.logsConsole) {
|
||||
this.scrollToBottom();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
@@ -345,24 +333,4 @@ export class LogsViewerComponent implements OnInit, OnDestroy {
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scroll to the bottom of the logs container
|
||||
*/
|
||||
private scrollToBottom(): void {
|
||||
if (this.logsConsole && this.logsConsole.nativeElement) {
|
||||
const element = this.logsConsole.nativeElement;
|
||||
element.scrollTop = element.scrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the auto-scroll state
|
||||
*/
|
||||
setAutoScroll(value: boolean): void {
|
||||
this.autoScroll.set(value);
|
||||
if (value) {
|
||||
this.scrollToBottom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
/* Content Blocker Settings Styles */
|
||||
|
||||
@use '../styles/settings-shared.scss';
|
||||
@@ -1,13 +1,16 @@
|
||||
<!-- Toast notifications handled by central toast container -->
|
||||
<div class="settings-container">
|
||||
<div class="flex align-items-center justify-content-between mb-4">
|
||||
<h1>Download Cleaner</h1>
|
||||
</div>
|
||||
|
||||
<p-card styleClass="settings-card h-full">
|
||||
<ng-template pTemplate="header">
|
||||
<div class="flex align-items-center justify-content-between p-3 border-bottom-1 surface-border">
|
||||
<div class="header-title-container">
|
||||
<h2 class="card-title m-0">Download Cleaner Configuration</h2>
|
||||
<span class="card-subtitle">Configure automatic download cleanup</span>
|
||||
<p-card styleClass="settings-card h-full">
|
||||
<ng-template pTemplate="header">
|
||||
<div class="flex align-items-center justify-content-between p-3 border-bottom-1 surface-border">
|
||||
<div class="header-title-container">
|
||||
<h2 class="card-title m-0">Download Cleaner Configuration</h2>
|
||||
<span class="card-subtitle">Configure automatic download cleanup</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<div class="card-content">
|
||||
@@ -25,7 +28,7 @@
|
||||
<!-- Main Settings -->
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('enabled')"
|
||||
title="Click for documentation"></i>
|
||||
Enable Download Cleaner
|
||||
@@ -39,7 +42,7 @@
|
||||
<!-- Scheduling Mode Toggle -->
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('useAdvancedScheduling')"
|
||||
title="Click for documentation"></i>
|
||||
Scheduling Mode
|
||||
@@ -92,7 +95,7 @@
|
||||
<!-- Advanced Schedule Controls - shown when useAdvancedScheduling is true -->
|
||||
<div class="field-row" *ngIf="downloadCleanerForm.get('useAdvancedScheduling')?.value">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('cronExpression')"
|
||||
title="Click for documentation"></i>
|
||||
Cron Expression
|
||||
@@ -124,7 +127,7 @@
|
||||
<!-- Delete Private Option -->
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('deletePrivate')"
|
||||
title="Click for documentation"></i>
|
||||
Delete Private Torrents
|
||||
@@ -155,7 +158,7 @@
|
||||
<div class="category-title">
|
||||
<i class="pi pi-tag category-icon"></i>
|
||||
<input type="text" pInputText formControlName="name" placeholder="Category name" class="category-name-input" />
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('name')"
|
||||
title="Click for documentation"></i>
|
||||
</div>
|
||||
@@ -167,7 +170,7 @@
|
||||
<div class="category-content">
|
||||
<div class="category-field">
|
||||
<label>
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('maxRatio')"
|
||||
title="Click for documentation"></i>
|
||||
Max Ratio
|
||||
@@ -185,7 +188,7 @@
|
||||
|
||||
<div class="category-field">
|
||||
<label>
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('minSeedTime')"
|
||||
title="Click for documentation"></i>
|
||||
Min Seed Time (hours)
|
||||
@@ -202,7 +205,7 @@
|
||||
|
||||
<div class="category-field">
|
||||
<label>
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('maxSeedTime')"
|
||||
title="Click for documentation"></i>
|
||||
Max Seed Time (hours)
|
||||
@@ -249,7 +252,7 @@
|
||||
<p-accordion-content>
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('unlinkedEnabled')"
|
||||
title="Click for documentation"></i>
|
||||
Enable Unlinked Download Handling
|
||||
@@ -263,7 +266,7 @@
|
||||
<!-- Unlinked Target Category -->
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('unlinkedTargetCategory')"
|
||||
title="Click for documentation"></i>
|
||||
Target Category
|
||||
@@ -274,13 +277,14 @@
|
||||
</div>
|
||||
<small *ngIf="hasError('unlinkedTargetCategory', 'required')" class="p-error">Target category is required</small>
|
||||
<small class="form-helper-text">Category to move unlinked downloads to</small>
|
||||
<small class="form-helper-text">You have to create a seeding rule for this category if you want to remove the downloads</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Use Tag Option -->
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('unlinkedUseTag')"
|
||||
title="Click for documentation"></i>
|
||||
Use Tag
|
||||
@@ -294,7 +298,7 @@
|
||||
<!-- Ignored Root Directory -->
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('unlinkedIgnoredRootDir')"
|
||||
title="Click for documentation"></i>
|
||||
Ignored Root Directory
|
||||
@@ -310,7 +314,7 @@
|
||||
<!-- Unlinked Categories -->
|
||||
<div class="field-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('unlinkedCategories')"
|
||||
title="Click for documentation"></i>
|
||||
Unlinked Categories
|
||||
@@ -370,8 +374,9 @@
|
||||
</p-card>
|
||||
|
||||
<!-- Confirmation Dialog -->
|
||||
<p-confirmDialog
|
||||
[style]="{ width: '450px' }"
|
||||
[baseZIndex]="10000"
|
||||
rejectButtonStyleClass="p-button-text">
|
||||
</p-confirmDialog>
|
||||
<p-confirmDialog
|
||||
[style]="{ width: '450px' }"
|
||||
[baseZIndex]="10000"
|
||||
rejectButtonStyleClass="p-button-text">
|
||||
</p-confirmDialog>
|
||||
</div>
|
||||
@@ -1,6 +1,8 @@
|
||||
/* Download Cleaner Settings Styles */
|
||||
|
||||
@use '../styles/settings-shared.scss';
|
||||
@use '../styles/arr-shared.scss';
|
||||
@use '../settings-page/settings-page.component.scss';
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 1rem;
|
||||
|
||||
@@ -793,7 +793,7 @@ export class DownloadCleanerSettingsComponent implements OnDestroy, CanComponent
|
||||
private showEnableConfirmationDialog(): void {
|
||||
this.confirmationService.confirm({
|
||||
header: 'Enable Download Cleaner',
|
||||
message: 'To avoid affecting items that are awaiting to be imported, please ensure that your Sonarr, Radarr, and Lidarr instances have been properly configured prior to enabling the Download Cleaner.<br/><br/>Are you sure you want to proceed?',
|
||||
message: 'To avoid affecting items that are awaiting to be imported, please ensure that your Sonarr, Radarr, and Lidarr instances have been configured prior to enabling the Download Cleaner.<br/><br/>Are you sure you want to proceed?',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-check',
|
||||
rejectIcon: 'pi pi-times',
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
<form [formGroup]="clientForm" class="p-fluid instance-form">
|
||||
<div class="field flex flex-row">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('enabled')"
|
||||
pTooltip="Click for documentation"></i>
|
||||
Enabled
|
||||
@@ -128,7 +128,7 @@
|
||||
|
||||
<div class="field">
|
||||
<label for="client-name">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('name')"
|
||||
pTooltip="Click for documentation"></i>
|
||||
Name *
|
||||
@@ -146,28 +146,28 @@
|
||||
|
||||
<div class="field">
|
||||
<label for="client-type">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
(click)="openFieldDocs('type')"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('typeName')"
|
||||
pTooltip="Click for documentation"></i>
|
||||
Client Type *
|
||||
</label>
|
||||
<p-select
|
||||
id="client-type"
|
||||
formControlName="type"
|
||||
[options]="clientTypeOptions"
|
||||
formControlName="typeName"
|
||||
[options]="typeNameOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select client type"
|
||||
appendTo="body"
|
||||
class="w-full"
|
||||
></p-select>
|
||||
<small *ngIf="hasError(clientForm, 'type', 'required')" class="p-error">Client type is required</small>
|
||||
<small *ngIf="hasError(clientForm, 'typeName', 'required')" class="p-error">Client type is required</small>
|
||||
</div>
|
||||
|
||||
<ng-container>
|
||||
<div class="field">
|
||||
<label for="client-host">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('host')"
|
||||
pTooltip="Click for documentation"></i>
|
||||
Host *
|
||||
@@ -187,7 +187,7 @@
|
||||
|
||||
<div class="field">
|
||||
<label for="client-urlbase">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('urlBase')"
|
||||
pTooltip="Click for documentation"></i>
|
||||
URL Base
|
||||
@@ -204,7 +204,7 @@
|
||||
|
||||
<div class="field" *ngIf="shouldShowUsernameField()">
|
||||
<label for="client-username">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('username')"
|
||||
pTooltip="Click for documentation"></i>
|
||||
Username
|
||||
@@ -221,7 +221,7 @@
|
||||
|
||||
<div class="field">
|
||||
<label for="client-password">
|
||||
<i class="pi pi-info-circle field-info-icon"
|
||||
<i class="pi pi-question-circle field-info-icon"
|
||||
(click)="openFieldDocs('password')"
|
||||
pTooltip="Click for documentation"></i>
|
||||
Password
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Subject, takeUntil } from "rxjs";
|
||||
import { DownloadClientConfigStore } from "./download-client-config.store";
|
||||
import { CanComponentDeactivate } from "../../core/guards";
|
||||
import { ClientConfig, DownloadClientConfig, CreateDownloadClientDto } from "../../shared/models/download-client-config.model";
|
||||
import { DownloadClientType } from "../../shared/models/enums";
|
||||
import { DownloadClientType, DownloadClientTypeName } from "../../shared/models/enums";
|
||||
import { DocumentationService } from "../../core/services/documentation.service";
|
||||
|
||||
// PrimeNG Components
|
||||
@@ -56,11 +56,7 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
editingClient: ClientConfig | null = null;
|
||||
|
||||
// Download client type options
|
||||
clientTypeOptions = [
|
||||
{ label: "qBittorrent", value: DownloadClientType.QBittorrent },
|
||||
{ label: "Deluge", value: DownloadClientType.Deluge },
|
||||
{ label: "Transmission", value: DownloadClientType.Transmission },
|
||||
];
|
||||
typeNameOptions: { label: string, value: DownloadClientTypeName }[] = [];
|
||||
|
||||
// Clean up subscriptions
|
||||
private destroy$ = new Subject<void>();
|
||||
@@ -89,7 +85,7 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
// Initialize client form for modal
|
||||
this.clientForm = this.formBuilder.group({
|
||||
name: ['', Validators.required],
|
||||
type: [null, Validators.required],
|
||||
typeName: [null, Validators.required],
|
||||
host: ['', [Validators.required, this.uriValidator.bind(this)]],
|
||||
username: [''],
|
||||
password: [''],
|
||||
@@ -97,11 +93,19 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
enabled: [true]
|
||||
});
|
||||
|
||||
// Initialize type name options
|
||||
for (const key of Object.keys(DownloadClientTypeName)) {
|
||||
this.typeNameOptions.push({
|
||||
label: key,
|
||||
value: DownloadClientTypeName[key as keyof typeof DownloadClientTypeName]
|
||||
});
|
||||
}
|
||||
|
||||
// Load Download Client config data
|
||||
this.downloadClientStore.loadConfig();
|
||||
|
||||
// Setup client type change handler
|
||||
this.clientForm.get('type')?.valueChanges
|
||||
this.clientForm.get('typeName')?.valueChanges
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(() => {
|
||||
this.onClientTypeChange();
|
||||
@@ -184,14 +188,9 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
this.modalMode = 'edit';
|
||||
this.editingClient = client;
|
||||
|
||||
// Map backend type to frontend type
|
||||
const frontendType = client.typeName
|
||||
? this.mapClientTypeFromBackend(client.typeName)
|
||||
: client.type;
|
||||
|
||||
this.clientForm.patchValue({
|
||||
name: client.name,
|
||||
type: frontendType,
|
||||
typeName: client.typeName,
|
||||
host: client.host,
|
||||
username: client.username,
|
||||
password: client.password,
|
||||
@@ -222,28 +221,27 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
}
|
||||
|
||||
const formValue = this.clientForm.value;
|
||||
const mappedType = this.mapClientTypeForBackend(formValue.type);
|
||||
|
||||
const clientData: CreateDownloadClientDto = {
|
||||
name: formValue.name,
|
||||
typeName: mappedType.typeName,
|
||||
type: mappedType.type,
|
||||
host: formValue.host,
|
||||
username: formValue.username,
|
||||
password: formValue.password,
|
||||
urlBase: formValue.urlBase,
|
||||
enabled: formValue.enabled
|
||||
};
|
||||
|
||||
if (this.modalMode === 'add') {
|
||||
const clientData: CreateDownloadClientDto = {
|
||||
name: formValue.name,
|
||||
type: this.mapTypeNameToType(formValue.typeName),
|
||||
typeName: formValue.typeName,
|
||||
host: formValue.host,
|
||||
username: formValue.username,
|
||||
password: formValue.password,
|
||||
urlBase: formValue.urlBase,
|
||||
enabled: formValue.enabled
|
||||
};
|
||||
|
||||
this.downloadClientStore.createClient(clientData);
|
||||
} else if (this.editingClient) {
|
||||
// For updates, create a proper ClientConfig object
|
||||
const clientConfig: ClientConfig = {
|
||||
id: this.editingClient.id!,
|
||||
id: this.editingClient.id,
|
||||
name: formValue.name,
|
||||
type: formValue.type, // Keep the frontend enum type
|
||||
typeName: mappedType.typeName,
|
||||
type: this.mapTypeNameToType(formValue.typeName),
|
||||
typeName: formValue.typeName,
|
||||
host: formValue.host,
|
||||
username: formValue.username,
|
||||
password: formValue.password,
|
||||
@@ -325,42 +323,25 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
}
|
||||
|
||||
/**
|
||||
* Map frontend client type to backend TypeName and Type
|
||||
* Map typeName to type category
|
||||
*/
|
||||
private mapClientTypeForBackend(frontendType: DownloadClientType): { typeName: string, type: string } {
|
||||
switch (frontendType) {
|
||||
case DownloadClientType.QBittorrent:
|
||||
return { typeName: 'qBittorrent', type: 'Torrent' };
|
||||
case DownloadClientType.Deluge:
|
||||
return { typeName: 'Deluge', type: 'Torrent' };
|
||||
case DownloadClientType.Transmission:
|
||||
return { typeName: 'Transmission', type: 'Torrent' };
|
||||
private mapTypeNameToType(typeName: DownloadClientTypeName): DownloadClientType {
|
||||
switch (typeName) {
|
||||
case DownloadClientTypeName.qBittorrent:
|
||||
case DownloadClientTypeName.Deluge:
|
||||
case DownloadClientTypeName.Transmission:
|
||||
case DownloadClientTypeName.uTorrent:
|
||||
return DownloadClientType.Torrent;
|
||||
default:
|
||||
return { typeName: 'QBittorrent', type: 'Torrent' };
|
||||
throw new Error(`Unknown client type name: ${typeName}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map backend TypeName to frontend client type
|
||||
*/
|
||||
private mapClientTypeFromBackend(backendTypeName: string): DownloadClientType {
|
||||
switch (backendTypeName) {
|
||||
case 'QBittorrent':
|
||||
return DownloadClientType.QBittorrent;
|
||||
case 'Deluge':
|
||||
return DownloadClientType.Deluge;
|
||||
case 'Transmission':
|
||||
return DownloadClientType.Transmission;
|
||||
default:
|
||||
return DownloadClientType.QBittorrent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle client type changes to update validation
|
||||
*/
|
||||
onClientTypeChange(): void {
|
||||
const clientType = this.clientForm.get('type')?.value;
|
||||
const clientTypeName = this.clientForm.get('typeName')?.value;
|
||||
const hostControl = this.clientForm.get('host');
|
||||
const usernameControl = this.clientForm.get('username');
|
||||
const urlBaseControl = this.clientForm.get('urlBase');
|
||||
@@ -373,13 +354,13 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
]);
|
||||
|
||||
// Clear username value and remove validation for Deluge
|
||||
if (clientType === DownloadClientType.Deluge) {
|
||||
if (clientTypeName === DownloadClientTypeName.Deluge) {
|
||||
usernameControl.setValue('');
|
||||
usernameControl.clearValidators();
|
||||
}
|
||||
|
||||
// Set default URL base for Transmission
|
||||
if (clientType === DownloadClientType.Transmission) {
|
||||
if (clientTypeName === DownloadClientTypeName.Transmission) {
|
||||
urlBaseControl.setValue('transmission');
|
||||
}
|
||||
|
||||
@@ -392,19 +373,15 @@ export class DownloadClientSettingsComponent implements OnDestroy, CanComponentD
|
||||
* Check if username field should be shown (hidden for Deluge)
|
||||
*/
|
||||
shouldShowUsernameField(): boolean {
|
||||
const clientType = this.clientForm.get('type')?.value;
|
||||
return clientType !== DownloadClientType.Deluge;
|
||||
const clientTypeName = this.clientForm.get('typeName')?.value;
|
||||
return clientTypeName !== DownloadClientTypeName.Deluge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client type label for display
|
||||
*/
|
||||
getClientTypeLabel(client: ClientConfig): string {
|
||||
const frontendType = client.typeName
|
||||
? this.mapClientTypeFromBackend(client.typeName)
|
||||
: client.type;
|
||||
|
||||
const option = this.clientTypeOptions.find(opt => opt.value === frontendType);
|
||||
const option = this.typeNameOptions.find(opt => opt.value === client.typeName);
|
||||
return option?.label || 'Unknown';
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user