Added MangaDex Api. Updated project structure.
This commit is contained in:
39
MangaReader.Core/Sources/MangaDex/Api/MangaDexClient.cs
Normal file
39
MangaReader.Core/Sources/MangaDex/Api/MangaDexClient.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using MangaReader.Core.HttpService;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MangaReader.Core.Sources.MangaDex.Api
|
||||
{
|
||||
public class MangaDexClient(IHttpService httpService) : IMangaDexClient
|
||||
{
|
||||
private static readonly JsonSerializerOptions _jsonSerializerOptions;
|
||||
|
||||
static MangaDexClient()
|
||||
{
|
||||
_jsonSerializerOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
_jsonSerializerOptions.Converters.Add(new MangaDexResponseConverter());
|
||||
_jsonSerializerOptions.Converters.Add(new MangaDexEntityConverter());
|
||||
}
|
||||
|
||||
private async Task<MangaDexResponse> GetAsync(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
string response = await httpService.GetStringAsync(url, cancellationToken);
|
||||
|
||||
return JsonSerializer.Deserialize<MangaDexResponse>(response, _jsonSerializerOptions)
|
||||
?? new() { Response = "failed", Result = "unknown" };
|
||||
}
|
||||
|
||||
public async Task<MangaDexResponse> GetMangaAsync(Guid mangaGuid, CancellationToken cancellationToken)
|
||||
{
|
||||
return await GetAsync($"https://api.mangadex.org/manga/{mangaGuid}?includes[]=artist&includes[]=author&includes[]=cover_art", cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<MangaDexResponse> GetFeedAsync(Guid mangaGuid, CancellationToken cancellationToken)
|
||||
{
|
||||
return await GetAsync($"https://api.mangadex.org/manga/{mangaGuid}/feed?translatedLanguage[]=en&limit=96&includes[]=scanlation_group&includes[]=user&order[volume]=desc&order[chapter]=desc&offset=0&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic", cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user