From 69296bd413e2fc2a1c3183519fb4b6de40401171 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 28 Nov 2024 22:09:52 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9C=AA=E6=B5=8B=E8=AF=95]=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0Tag=E5=B8=AE=E5=8A=A9=E7=B1=BB=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Db.cs | 49 ++++++++++++++++++++++++++++++++++--- src/Services/TaskManager.cs | 2 +- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/Models/Db.cs b/src/Models/Db.cs index fde96d1..9be3a12 100644 --- a/src/Models/Db.cs +++ b/src/Models/Db.cs @@ -48,7 +48,7 @@ namespace iFileProxy.Models [JsonProperty("tag")] [JsonPropertyName("tag")] - public string Tag { get; set; } + public string Tag { get; set; } = string.Empty; [JsonProperty("queue_position")] [JsonPropertyName("queue_position")] @@ -57,10 +57,53 @@ namespace iFileProxy.Models [System.Text.Json.Serialization.JsonIgnore] [Newtonsoft.Json.JsonIgnore] public Process Process { get; set; } + + // Helper to get the tags as a list + private List GetTagList() + { + return string.IsNullOrWhiteSpace(Tag) ? [] : [.. Tag.Split(';')]; + } + + // Add a new tag + public void AddTag(string tag) + { + var tags = GetTagList(); + if (!tags.Contains(tag)) + { + tags.Add(tag); + Tag = string.Join(";", tags); + } + } + + // Remove a tag + public bool RemoveTag(string tag) + { + var tags = GetTagList(); + if (tags.Remove(tag)) + { + Tag = string.Join(";", tags); + return true; + } + return false; + } + + // Find a tag + public bool FindTag(string tag) + { + return GetTagList().Contains(tag); + } + + // Get all tags as a list + public List GetTags() + { + return GetTagList(); + } } - public class DbConfigName { + + public class DbConfigName + { public static string iFileProxy = "iFileProxy_Db"; - + } } diff --git a/src/Services/TaskManager.cs b/src/Services/TaskManager.cs index 205dbad..9a7ddc3 100644 --- a/src/Services/TaskManager.cs +++ b/src/Services/TaskManager.cs @@ -146,7 +146,7 @@ namespace iFileProxy.Services taskInfo.Status = TaskState.Cached; taskInfo.Hash = r.Hash; taskInfo.Size = r.Size; - taskInfo.Tag = $"REDIRECT:{r.TaskId}"; + taskInfo.AddTag($"REDIRECT:{r.TaskId}"); } }