From 2be29e4019fe4af729c915dc3d8390a06b11bb13 Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 7 Sep 2024 20:16:05 +0200 Subject: [PATCH 1/4] MangaDex only download single release for chapter. Fix #219 --- Tranga/MangaConnectors/MangaDex.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index 005da07..cbb8ffb 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -243,7 +243,7 @@ public class MangaDex : MangaConnector continue; } - if(chapterNum is not "null") + if(chapterNum is not "null" && !chapters.Any(chp => chp.volumeNumber.Equals(volume) && chp.chapterNumber.Equals(chapterNum))) chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId)); } } From 15f3e2b8ec3267af20d43ff31f00e810deda684d Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 7 Sep 2024 20:33:03 +0200 Subject: [PATCH 2/4] Use current time as internalId for Manga instead of BASE64 string of title #232 Fix #237 --- Tranga/Manga.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 5ebad19..6b48c5d 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -67,7 +67,7 @@ public struct Manga while (this.folderName.EndsWith('.')) this.folderName = this.folderName.Substring(0, this.folderName.Length - 1); string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter)); - this.internalId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{onlyLowerLetters}{this.year}")); + this.internalId = DateTime.Now.Ticks.ToString(); this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f; this.latestChapterDownloaded = 0; this.latestChapterAvailable = 0; From 9b8b80cd2462ff0979c9405f1811c461a57f899f Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 7 Sep 2024 20:36:00 +0200 Subject: [PATCH 3/4] Fix response closed on OPTIONS request --- Tranga/Server.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Tranga/Server.cs b/Tranga/Server.cs index 4e387f1..dbf80a5 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -63,10 +63,11 @@ public class Server : GlobalBase { HttpListenerRequest request = context.Request; HttpListenerResponse response = context.Response; - if(request.HttpMethod == "OPTIONS") - SendResponse(HttpStatusCode.OK, context.Response); - if(request.Url!.LocalPath.Contains("favicon")) + if (request.Url!.LocalPath.Contains("favicon")) + { SendResponse(HttpStatusCode.NoContent, response); + return; + } switch (request.HttpMethod) { @@ -79,7 +80,10 @@ public class Server : GlobalBase case "DELETE": HandleDelete(request, response); break; - default: + case "OPTIONS": + SendResponse(HttpStatusCode.OK, context.Response); + break; + default: SendResponse(HttpStatusCode.BadRequest, response); break; } @@ -707,14 +711,15 @@ public class Server : GlobalBase private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null) { //Log($"Response: {statusCode} {content}"); + response.StatusCode = (int)statusCode; response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With"); response.AddHeader("Access-Control-Allow-Methods", "GET, POST, DELETE"); response.AddHeader("Access-Control-Max-Age", "1728000"); response.AppendHeader("Access-Control-Allow-Origin", "*"); - try { + if (content is not Stream) { response.ContentType = "application/json"; @@ -750,7 +755,7 @@ public class Server : GlobalBase stream.Close(); } } - catch (HttpListenerException e) + catch (Exception e) { Log(e.ToString()); } From 96f3dbce6518733fe907dd6896720566f0a56cb6 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 16 Sep 2024 18:32:34 +0200 Subject: [PATCH 4/4] Throw more readable exceptions if deserialization fails for Mangaconnectors. #249 --- .../MangaConnectorJsonConverter.cs | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs b/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs index 2213a48..3b3e6da 100644 --- a/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs +++ b/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs @@ -1,4 +1,6 @@ -using Newtonsoft.Json; +using System.Data; +using System.Diagnostics; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Tranga.MangaConnectors; @@ -22,29 +24,22 @@ public class MangaConnectorJsonConverter : JsonConverter public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { JObject jo = JObject.Load(reader); - switch (jo.GetValue("name")!.Value()!) + string? connectorName = jo.Value("name"); + if (connectorName is null) + throw new ConstraintException("Name can not be null."); + return connectorName switch { - case "MangaDex": - return this._connectors.First(c => c is MangaDex); - case "Manganato": - return this._connectors.First(c => c is Manganato); - case "MangaKatana": - return this._connectors.First(c => c is MangaKatana); - case "Mangasee": - return this._connectors.First(c => c is Mangasee); - case "Mangaworld": - return this._connectors.First(c => c is Mangaworld); - case "Bato": - return this._connectors.First(c => c is Bato); - case "Manga4Life": - return this._connectors.First(c => c is MangaLife); - case "ManhuaPlus": - return this._connectors.First(c => c is ManhuaPlus); - case "MangaHere": - return this._connectors.First(c => c is MangaHere); - } - - throw new Exception(); + "MangaDex" => this._connectors.First(c => c is MangaDex), + "Manganato" => this._connectors.First(c => c is Manganato), + "MangaKatana" => this._connectors.First(c => c is MangaKatana), + "Mangasee" => this._connectors.First(c => c is Mangasee), + "Mangaworld" => this._connectors.First(c => c is Mangaworld), + "Bato" => this._connectors.First(c => c is Bato), + "Manga4Life" => this._connectors.First(c => c is MangaLife), + "ManhuaPlus" => this._connectors.First(c => c is ManhuaPlus), + "MangaHere" => this._connectors.First(c => c is MangaHere), + _ => throw new UnreachableException($"Could not find Connector with name {connectorName}") + }; } public override bool CanWrite => false;