From b515215f4b67d6a391f1106c322b0147b901e823 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 22 Jun 2023 23:09:59 +0200 Subject: [PATCH] Fix taskIds being changed during requests --- Tranga/TaskManager.cs | 15 ++++++--------- Tranga/TrangaSettings.cs | 4 +++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index 347511e..6ad439a 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -128,18 +128,15 @@ public class TaskManager _allTasks.Add(newTask); break; case TrangaTask.Task.MonitorPublication: - if (!_allTasks.Any(mTask => mTask is MonitorPublicationTask mpt && newTask is MonitorPublicationTask nMpt && - mpt.publication.internalId == nMpt.publication.internalId && - mpt.connectorName == nMpt.connectorName)) + MonitorPublicationTask mpt = (MonitorPublicationTask)newTask; + if(!GetTasksMatching(mpt.task, mpt.connectorName, internalId:mpt.publication.internalId).Any()) _allTasks.Add(newTask); else logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}"); break; case TrangaTask.Task.DownloadChapter: - if (!_allTasks.Any(mTask => mTask is DownloadChapterTask dct && newTask is DownloadChapterTask nDct && - dct.publication.internalId == nDct.publication.internalId && - dct.connectorName == nDct.connectorName && - dct.chapter.sortNumber == nDct.chapter.sortNumber)) + DownloadChapterTask dct = (DownloadChapterTask)newTask; + if(!GetTasksMatching(dct.task, dct.connectorName, internalId:dct.publication.internalId, chapterSortNumber:dct.chapter.sortNumber).Any()) _allTasks.Add(newTask); else logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}"); @@ -182,7 +179,7 @@ public class TaskManager { return _allTasks.Where(mTask => mTask is MonitorPublicationTask mpt && mpt.connectorName == connectorName && - mpt.publication.internalId == internalId); + string.Concat(settings.CleanIdRex.Matches(mpt.publication.internalId)) == string.Concat(settings.CleanIdRex.Matches(internalId))); } else return _allTasks.Where(tTask => @@ -202,7 +199,7 @@ public class TaskManager { return _allTasks.Where(mTask => mTask is DownloadChapterTask dct && dct.connectorName == connectorName && - dct.publication.publicationId == internalId && + string.Concat(settings.CleanIdRex.Matches(dct.publication.internalId)) == string.Concat(settings.CleanIdRex.Matches(internalId)) && dct.chapter.sortNumber == chapterSortNumber); } else diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index 19a1c3e..2ffe654 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -1,4 +1,5 @@ -using Logging; +using System.Text.RegularExpressions; +using Logging; using Newtonsoft.Json; using Tranga.LibraryManagers; using Tranga.NotificationManagers; @@ -15,6 +16,7 @@ public class TrangaSettings [JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache"); public HashSet libraryManagers { get; } public HashSet notificationManagers { get; } + [JsonIgnore]internal Regex CleanIdRex = new (@"[a-zA-Z0-9]*-*_*"); public TrangaSettings(string downloadLocation, string workingDirectory, HashSet? libraryManagers, HashSet? notificationManagers)