Added MangaDex Api. Updated project structure.

This commit is contained in:
2025-05-26 17:16:25 -04:00
parent 648aa95f32
commit ea8b4a36ff
61 changed files with 4937 additions and 197 deletions

View File

@@ -0,0 +1,33 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MangaReader.Core.Sources.MangaDex.Api;
public class MangaDexEntityConverter : JsonConverter<MangaDexEntity>
{
public override MangaDexEntity? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using var doc = JsonDocument.ParseValue(ref reader);
var root = doc.RootElement;
var type = root.GetProperty("type").GetString();
return type switch
{
"manga" => JsonSerializer.Deserialize<MangaEntity>(root.GetRawText(), options),
"author" => JsonSerializer.Deserialize<AuthorEntity>(root.GetRawText(), options),
"artist" => JsonSerializer.Deserialize<ArtistEntity>(root.GetRawText(), options),
"creator" => JsonSerializer.Deserialize<CreatorEntity>(root.GetRawText(), options),
"tag" => JsonSerializer.Deserialize<TagEntity>(root.GetRawText(), options),
"chapter" => JsonSerializer.Deserialize<ChapterEntity>(root.GetRawText(), options),
"scanlation_group" => JsonSerializer.Deserialize<ScanlationGroupEntity>(root.GetRawText(), options),
"cover_art" => JsonSerializer.Deserialize<CoverArtEntity>(root.GetRawText(), options),
_ => throw new NotSupportedException($"Unknown type '{type}'")
};
}
public override void Write(Utf8JsonWriter writer, MangaDexEntity value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, (object)value, options);
}
}