From 1066e1ca2ec710ce1c6eda7ceed7e7dee869b323 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 13 Sep 2023 14:09:47 +0200 Subject: [PATCH] #50 translated-language support (if connector supports it) API GET Manga/Chapters new parameter "translatedLanguage" --- Tranga/Jobs/DownloadNewChapters.cs | 12 +++++++----- Tranga/Server.cs | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Tranga/Jobs/DownloadNewChapters.cs b/Tranga/Jobs/DownloadNewChapters.cs index b00e53d..c3490b1 100644 --- a/Tranga/Jobs/DownloadNewChapters.cs +++ b/Tranga/Jobs/DownloadNewChapters.cs @@ -1,22 +1,24 @@ -using System.Text; -using Tranga.MangaConnectors; +using Tranga.MangaConnectors; namespace Tranga.Jobs; public class DownloadNewChapters : Job { public Manga manga { get; init; } + public string translatedLanguage { get; init; } public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, DateTime lastExecution, - bool recurring = false, TimeSpan? recurrence = null, string? parentJobId = null) : base(clone, connector, lastExecution, recurring, + bool recurring = false, TimeSpan? recurrence = null, string? parentJobId = null, string translatedLanguage = "en") : base(clone, connector, lastExecution, recurring, recurrence, parentJobId) { this.manga = manga; + this.translatedLanguage = translatedLanguage; } - public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, bool recurring = false, TimeSpan? recurrence = null, string? parentJobId = null) : base (clone, connector, recurring, recurrence, parentJobId) + public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, bool recurring = false, TimeSpan? recurrence = null, string? parentJobId = null, string translatedLanguage = "en") : base (clone, connector, recurring, recurrence, parentJobId) { this.manga = manga; + this.translatedLanguage = translatedLanguage; } protected override string GetId() @@ -31,7 +33,7 @@ public class DownloadNewChapters : Job protected override IEnumerable ExecuteReturnSubTasksInternal() { - Chapter[] chapters = mangaConnector.GetNewChapters(manga); + Chapter[] chapters = mangaConnector.GetNewChapters(manga, this.translatedLanguage); this.progressToken.increments = chapters.Length; List jobs = new(); foreach (Chapter chapter in chapters) diff --git a/Tranga/Server.cs b/Tranga/Server.cs index 3841a17..93ee3a9 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -163,7 +163,8 @@ public class Server : GlobalBase SendResponse(HttpStatusCode.BadRequest, response); break; } - SendResponse(HttpStatusCode.OK, response, connector!.GetChapters((Manga)manga!)); + requestVariables.TryGetValue("translatedLanguage", out string? translatedLanguage); + SendResponse(HttpStatusCode.OK, response, connector!.GetChapters((Manga)manga!, translatedLanguage??"en")); break; case "Jobs": if (!requestVariables.TryGetValue("jobId", out jobId))