Project restructuring.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using MangaReader.Core.HttpService;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MangaReader.Core.Sources.MangaDex.Api
|
||||
@@ -18,22 +19,55 @@ namespace MangaReader.Core.Sources.MangaDex.Api
|
||||
_jsonSerializerOptions.Converters.Add(new MangaDexEntityConverter());
|
||||
}
|
||||
|
||||
private async Task<MangaDexResponse> GetAsync(string url, CancellationToken cancellationToken)
|
||||
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" };
|
||||
return JsonSerializer.Deserialize<MangaDexResponse>(response, _jsonSerializerOptions);
|
||||
}
|
||||
|
||||
public async Task<MangaDexResponse> GetMangaAsync(Guid mangaGuid, CancellationToken cancellationToken)
|
||||
public async Task<MangaDexResponse?> SearchMangaByTitleAsync(string title, CancellationToken cancellationToken)
|
||||
{
|
||||
string normalizedKeyword = GetNormalizedKeyword(title);
|
||||
|
||||
return await GetAsync($"https://api.mangadex.org/manga?title={normalizedKeyword}&limit=5", cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<MangaDexResponse?> SearchMangaByAuthorAsync(string author, CancellationToken cancellationToken)
|
||||
{
|
||||
string normalizedKeyword = GetNormalizedKeyword(author);
|
||||
|
||||
return await GetAsync($"https://api.mangadex.org/manga?author={normalizedKeyword}&limit=5", cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<MangaDexResponse?> SearchMangaByGroupAsync(string group, CancellationToken cancellationToken)
|
||||
{
|
||||
string normalizedKeyword = GetNormalizedKeyword(group);
|
||||
|
||||
return await GetAsync($"https://api.mangadex.org/manga?group={normalizedKeyword}&limit=5", cancellationToken);
|
||||
}
|
||||
|
||||
protected static string GetNormalizedKeyword(string keyword)
|
||||
{
|
||||
return keyword.ToLowerInvariant().Normalize(NormalizationForm.FormD);
|
||||
}
|
||||
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
public async Task<MangaDexChapterResponse?> GetChapterAsync(Guid chapterGuid, CancellationToken cancellationToken)
|
||||
{
|
||||
string url = $"https://api.mangadex.org/at-home/server/{chapterGuid}?forcePort443=false";
|
||||
string response = await httpService.GetStringAsync(url, cancellationToken);
|
||||
|
||||
return JsonSerializer.Deserialize<MangaDexChapterResponse>(response, _jsonSerializerOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user