From c97ff691485439f587edc141e9f0aa52f2585e8a Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 2 Jul 2023 22:46:01 +0200 Subject: [PATCH] Fix for new publications: Add to collection --- API/RequestHandler.cs | 4 ++-- Tranga-CLI/Tranga_Cli.cs | 2 +- Tranga/Connector.cs | 10 +++++++++- Tranga/Connectors/MangaDex.cs | 2 +- Tranga/Connectors/MangaKatana.cs | 2 +- Tranga/Connectors/Manganato.cs | 2 +- Tranga/Connectors/Mangasee.cs | 2 +- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/API/RequestHandler.cs b/API/RequestHandler.cs index 8986b54..ba9b401 100644 --- a/API/RequestHandler.cs +++ b/API/RequestHandler.cs @@ -158,7 +158,7 @@ public class RequestHandler if (connector1 is null) return; Publication? publication1 = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId1); - if (publication1 is null) + if (!publication1.HasValue) return; _taskManager.AddTask(new MonitorPublicationTask(connectorName1, (Publication)publication1, TimeSpan.Parse(reoccurrenceTime1), language1 ?? "en")); break; @@ -277,7 +277,7 @@ public class RequestHandler return null; if(title.Length < 4) return null; - return connector1.GetPublications(title); + return connector1.GetPublications(ref _taskManager.collection, title); case "/Publications/Chapters": string[] yes = { "true", "yes", "1", "y" }; variables.TryGetValue("connectorName", out string? connectorName2); diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index 083f36d..01e2835 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -565,7 +565,7 @@ public static class Tranga_Cli Console.WriteLine("Publication search query (leave empty for all):"); string? query = Console.ReadLine(); - Publication[] publications = connector.GetPublications(query ?? ""); + Publication[] publications = connector.GetPublications(ref taskManager.collection, query ?? ""); if (publications.Length < 1) { diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index f5bb4cd..d2e32ad 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -29,6 +29,14 @@ public abstract class Connector } public abstract string name { get; } //Name of the Connector (e.g. Website) + + public Publication[] GetPublications(ref HashSet publicationCollection, string publicationTitle = "") + { + Publication[] ret = GetPublicationsInternal(publicationTitle); + foreach (Publication p in ret) + publicationCollection.Add(p); + return ret; + } /// /// Returns all Publications with the given string. @@ -36,7 +44,7 @@ public abstract class Connector /// /// Search-Query /// Publications matching the query - public abstract Publication[] GetPublications(string publicationTitle = ""); + protected abstract Publication[] GetPublicationsInternal(string publicationTitle = ""); /// /// Returns all Chapters of the publication in the provided language. diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index f354cc8..58c4abf 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -32,7 +32,7 @@ public class MangaDex : Connector }, logger); } - public override Publication[] GetPublications(string publicationTitle = "") + protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); const int limit = 100; //How many values we want returned at once diff --git a/Tranga/Connectors/MangaKatana.cs b/Tranga/Connectors/MangaKatana.cs index 4b1300b..6f05b33 100644 --- a/Tranga/Connectors/MangaKatana.cs +++ b/Tranga/Connectors/MangaKatana.cs @@ -20,7 +20,7 @@ public class MangaKatana : Connector }, logger); } - public override Publication[] GetPublications(string publicationTitle = "") + protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_'); diff --git a/Tranga/Connectors/Manganato.cs b/Tranga/Connectors/Manganato.cs index e4356f0..f01db65 100644 --- a/Tranga/Connectors/Manganato.cs +++ b/Tranga/Connectors/Manganato.cs @@ -20,7 +20,7 @@ public class Manganato : Connector }, logger); } - public override Publication[] GetPublications(string publicationTitle = "") + protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*")).ToLower(); diff --git a/Tranga/Connectors/Mangasee.cs b/Tranga/Connectors/Mangasee.cs index 6540d05..432f419 100644 --- a/Tranga/Connectors/Mangasee.cs +++ b/Tranga/Connectors/Mangasee.cs @@ -72,7 +72,7 @@ public class Mangasee : Connector }); } - public override Publication[] GetPublications(string publicationTitle = "") + protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); string requestUrl = $"https://mangasee123.com/_search.php";