From 5e362d4af84ff88efa435dbbccf3f657357b4f32 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Tue, 25 Mar 2025 16:11:53 +0200 Subject: [PATCH] added Deluge label creation --- .../Verticals/DownloadClient/Deluge/DelugeClient.cs | 12 +++++++++++- .../Verticals/DownloadClient/Deluge/DelugeService.cs | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeClient.cs b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeClient.cs index d5edfc5..4b34619 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeClient.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeClient.cs @@ -1,4 +1,4 @@ -using System.Net.Http.Headers; +using System.Net.Http.Headers; using System.Text.Json.Serialization; using Common.Configuration; using Common.Configuration.DownloadClient; @@ -194,6 +194,16 @@ public sealed class DelugeClient return webResponse.Result; } + public async Task> GetLabels() + { + return await SendRequest>("label.label.get_labels"); + } + + public async Task CreateLabel(string label) + { + await SendRequest>("label.add", label); + } + public async Task SetTorrentLabel(string hash, string newLabel) { // TODO diff --git a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs index 73f7b12..5bd5b76 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs @@ -298,7 +298,14 @@ public class DelugeService : DownloadService, IDelugeService public override async Task CreateCategoryAsync(string name) { - throw new NotImplementedException(); + IReadOnlyList existingLabels = await _client.GetLabels(); + + if (existingLabels.Contains(name, StringComparer.InvariantCultureIgnoreCase)) + { + return; + } + + await _client.CreateLabel(name); } public override async Task ChangeCategoryForNoHardLinksAsync(List? downloads, HashSet excludedHashes, IReadOnlyList ignoredDownloads)