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}"); } }