-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
136 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Juro.Providers.Anime; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Juro.WebApi.Controllers.Anime; | ||
|
||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class AnimeController(Gogoanime provider) : GogoanimeController(provider) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Juro.Providers.Manga; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Juro.WebApi.Controllers.Manga; | ||
|
||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class MangaController(Mangadex provider) : MangadexController(provider) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization.Metadata; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Juro.Core; | ||
using Juro.Core.Models; | ||
using Juro.Core.Models.Manga; | ||
using Juro.Core.Utils; | ||
using Juro.Core.Utils.Extensions; | ||
|
||
namespace Juro.Clients; | ||
|
||
public class MangaApiClient(string baseUrl, IHttpClientFactory httpClientFactory) | ||
{ | ||
private readonly HttpClient _http = httpClientFactory.CreateClient(); | ||
private readonly JsonSerializerOptions _options = | ||
new() | ||
{ | ||
PropertyNameCaseInsensitive = true, | ||
TypeInfoResolver = new DefaultJsonTypeInfoResolver | ||
{ | ||
Modifiers = | ||
{ | ||
static typeInfo => | ||
{ | ||
if (typeInfo.Type == typeof(IMangaInfo)) | ||
typeInfo.CreateObject = () => new MangaInfo(); | ||
else if (typeInfo.Type == typeof(IMangaResult)) | ||
typeInfo.CreateObject = () => new MangaResult(); | ||
else if (typeInfo.Type == typeof(IMangaChapter)) | ||
typeInfo.CreateObject = () => new MangaChapter(); | ||
else if (typeInfo.Type == typeof(IMangaChapterPage)) | ||
typeInfo.CreateObject = () => new MangaChapterPage(); | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
public string BaseUrl { get; set; } = baseUrl; | ||
|
||
public string ProviderKey { get; set; } = "MangaPill"; | ||
|
||
/// <summary> | ||
/// Initializes an instance of <see cref="MangaApiClient"/>. | ||
/// </summary> | ||
public MangaApiClient(string baseUrl, Func<HttpClient> httpClientProvider) | ||
: this(baseUrl, new HttpClientFactory(httpClientProvider)) { } | ||
|
||
/// <summary> | ||
/// Initializes an instance of <see cref="MangaApiClient"/>. | ||
/// </summary> | ||
public MangaApiClient(string baseUrl) | ||
: this(baseUrl, Http.ClientProvider) { } | ||
|
||
public async ValueTask<List<Provider>> GetProvidersAsync( | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
var response = await _http.ExecuteAsync( | ||
$"{BaseUrl}/Providers?type={(int)ProviderType.Manga}", | ||
cancellationToken: cancellationToken | ||
); | ||
|
||
return JsonSerializer.Deserialize<List<Provider>>(response, _options)!; | ||
} | ||
|
||
public async ValueTask<IMangaInfo> GetAsync( | ||
string id, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
var response = await _http.ExecuteAsync( | ||
$"{BaseUrl}/{ProviderKey}/{Uri.EscapeDataString(id)}", | ||
cancellationToken: cancellationToken | ||
); | ||
|
||
return JsonSerializer.Deserialize<IMangaInfo>(response, _options)!; | ||
} | ||
|
||
public async ValueTask<List<IMangaResult>> SearchAsync( | ||
string query, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
var response = await _http.ExecuteAsync( | ||
$"{BaseUrl}/{ProviderKey}/Search?q={Uri.EscapeDataString(query)}", | ||
cancellationToken: cancellationToken | ||
); | ||
|
||
return JsonSerializer.Deserialize<List<IMangaResult>>(response, _options) ?? []; | ||
} | ||
|
||
public async ValueTask<List<IMangaChapterPage>> GetChapterPagesAsync( | ||
string id, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
var response = await _http.ExecuteAsync( | ||
$"{BaseUrl}/{ProviderKey}/ChapterPages/{Uri.EscapeDataString(id)}", | ||
cancellationToken: cancellationToken | ||
); | ||
|
||
return JsonSerializer.Deserialize<List<IMangaChapterPage>>(response, _options) ?? []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters