mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-23 03:24:15 +02:00
MangaDex nullvalue checks and allow null-fields in response
Some checks failed
Docker Image CI / build (push) Has been cancelled
Some checks failed
Docker Image CI / build (push) Has been cancelled
This commit is contained in:
@ -226,22 +226,25 @@ public class MangaDex : MangaConnector
|
|||||||
private Manga ParseMangaFromJToken(JToken jToken)
|
private Manga ParseMangaFromJToken(JToken jToken)
|
||||||
{
|
{
|
||||||
string? id = jToken.Value<string>("id");
|
string? id = jToken.Value<string>("id");
|
||||||
|
if(id is null)
|
||||||
|
throw new Exception("jToken was not in expected format");
|
||||||
|
|
||||||
JObject? attributes = jToken["attributes"] as JObject;
|
JObject? attributes = jToken["attributes"] as JObject;
|
||||||
string? name = attributes?["title"]?.Value<string>("en") ?? attributes?["title"]?.First?.First?.Value<string>();
|
if(attributes is null)
|
||||||
string? description = attributes?["description"]?.Value<string>("en")??attributes?["description"]?.First?.First?.Value<string>();
|
throw new Exception("jToken was not in expected format");
|
||||||
string? status = attributes?["status"]?.Value<string>();
|
string? name = attributes["title"]?.Value<string>("en") ?? attributes["title"]?.First?.First?.Value<string>();
|
||||||
uint? year = attributes?["year"]?.Value<uint?>();
|
string description = attributes["description"]?.Value<string>("en")??attributes["description"]?.First?.First?.Value<string>()??"";
|
||||||
string? originalLanguage = attributes?["originalLanguage"]?.Value<string>();
|
string? status = attributes["status"]?.Value<string>();
|
||||||
JArray? altTitlesJArray = attributes?["altTitles"] as JArray;
|
uint? year = attributes["year"]?.Value<uint?>();
|
||||||
JArray? tagsJArray = attributes?["tags"] as JArray;
|
string? originalLanguage = attributes["originalLanguage"]?.Value<string>();
|
||||||
|
JArray? altTitlesJArray = attributes.TryGetValue("altTitles", out JToken? altTitlesArray) ? altTitlesArray as JArray : null;
|
||||||
|
JArray? tagsJArray = attributes.TryGetValue("tags", out JToken? tagsArray) ? tagsArray as JArray : null;
|
||||||
JArray? relationships = jToken["relationships"] as JArray;
|
JArray? relationships = jToken["relationships"] as JArray;
|
||||||
string? coverFileName =
|
if (name is null || status is null || relationships is null)
|
||||||
relationships?.FirstOrDefault(r => r["type"]?.Value<string>() == "cover_art")?["attributes"]?.Value<string>("fileName");
|
throw new Exception("jToken was not in expected format");
|
||||||
|
|
||||||
if (id is null || attributes is null || name is null || description is null || status is null ||
|
string? coverFileName = relationships.FirstOrDefault(r => r["type"]?.Value<string>() == "cover_art")?["attributes"]?.Value<string>("fileName");
|
||||||
altTitlesJArray is null || tagsJArray is null || relationships is null || coverFileName is null)
|
if(coverFileName is null)
|
||||||
throw new Exception("jToken was not in expected format");
|
throw new Exception("jToken was not in expected format");
|
||||||
|
|
||||||
List<Link> links = attributes["links"]?
|
List<Link> links = attributes["links"]?
|
||||||
@ -276,7 +279,7 @@ public class MangaDex : MangaConnector
|
|||||||
return new Link(key, url);
|
return new Link(key, url);
|
||||||
}).ToList()!;
|
}).ToList()!;
|
||||||
|
|
||||||
List<MangaAltTitle> altTitles = altTitlesJArray
|
List<MangaAltTitle> altTitles = (altTitlesJArray??[])
|
||||||
.Select(t =>
|
.Select(t =>
|
||||||
{
|
{
|
||||||
JObject? j = t as JObject;
|
JObject? j = t as JObject;
|
||||||
@ -286,7 +289,7 @@ public class MangaDex : MangaConnector
|
|||||||
return new MangaAltTitle(p.Name, p.Value.ToString());
|
return new MangaAltTitle(p.Name, p.Value.ToString());
|
||||||
}).Where(x => x is not null).ToList()!;
|
}).Where(x => x is not null).ToList()!;
|
||||||
|
|
||||||
List<MangaTag> tags = tagsJArray
|
List<MangaTag> tags = (tagsJArray??[])
|
||||||
.Where(t => t.Value<string>("type") == "tag")
|
.Where(t => t.Value<string>("type") == "tag")
|
||||||
.Select(t => t["attributes"]?["name"]?.Value<string>("en")??t["attributes"]?["name"]?.First?.First?.Value<string>())
|
.Select(t => t["attributes"]?["name"]?.Value<string>("en")??t["attributes"]?["name"]?.First?.First?.Value<string>())
|
||||||
.Select(str => str is not null ? new MangaTag(str) : null)
|
.Select(str => str is not null ? new MangaTag(str) : null)
|
||||||
|
Reference in New Issue
Block a user