From 5efa00e0598646e3ee60e25666107af2f49eaf4d Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 25 May 2023 13:50:48 +0200 Subject: [PATCH] Added field posterBase64 to Publication #22 --- Tranga/Connectors/MangaDex.cs | 12 +++++++++++- Tranga/Publication.cs | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index 62426b0..d6bc7d8 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -98,6 +98,15 @@ public class MangaDex : Connector authorId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue() == "author")!["id"]!.GetValue(); } string? coverUrl = GetCoverUrl(publicationId, posterId); + string? coverBase64 = null; + if (coverUrl is not null) + { + DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(coverUrl, (byte)RequestType.AtHomeServer); + using MemoryStream ms = new(); + coverResult.result.CopyTo(ms); + byte[] imageBytes = ms.ToArray(); + coverBase64 = Convert.ToBase64String(imageBytes); + } string? author = GetAuthor(authorId); Dictionary linksDict = new(); @@ -127,6 +136,7 @@ public class MangaDex : Connector altTitlesDict, tags.ToArray(), coverUrl, + coverBase64, linksDict, year, originalLanguage, @@ -232,7 +242,7 @@ public class MangaDex : Connector //Request information where to download Cover DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.Cover); + downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.CoverUrl); if (requestResult.statusCode != HttpStatusCode.OK) return null; JsonObject? result = JsonSerializer.Deserialize(requestResult.result); diff --git a/Tranga/Publication.cs b/Tranga/Publication.cs index 793f616..3003800 100644 --- a/Tranga/Publication.cs +++ b/Tranga/Publication.cs @@ -15,6 +15,7 @@ public readonly struct Publication public string? description { get; } public string[] tags { get; } public string? posterUrl { get; } + public string? posterBase64 { get; } public Dictionary links { get; } public int? year { get; } public string? originalLanguage { get; } @@ -23,13 +24,14 @@ public readonly struct Publication public string publicationId { get; } public string internalId { get; } - public Publication(string sortName, string? author, string? description, Dictionary altTitles, string[] tags, string? posterUrl, Dictionary? links, int? year, string? originalLanguage, string status, string publicationId) + public Publication(string sortName, string? author, string? description, Dictionary altTitles, string[] tags, string? posterUrl, string? posterBase64, Dictionary? links, int? year, string? originalLanguage, string status, string publicationId) { this.sortName = sortName; this.author = author; this.description = description; this.altTitles = altTitles; this.tags = tags; + this.posterBase64 = posterBase64; this.posterUrl = posterUrl; this.links = links ?? new Dictionary(); this.year = year;