Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Oct 4, 2024
1 parent 5279efa commit a0fba63
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>1.4.3</Version>
<Version>1.4.4</Version>
<Company>Berry</Company>
<Copyright>Copyright (C) Jerry Berry</Copyright>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion Juro.Core/Juro.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Juro.Extractors/Juro.Extractors.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Juro.Providers.Adult/Juro.Providers.Adult.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net6.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Juro.Providers/Juro.Providers.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net8.0</TargetFrameworks>
<EnableDynamicLoading>true</EnableDynamicLoading>
<IsPackable>true</IsPackable>
</PropertyGroup>
Expand Down
10 changes: 10 additions & 0 deletions Juro.WebApi/Controllers/Anime/AnimeController.cs
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)
{
}
10 changes: 10 additions & 0 deletions Juro.WebApi/Controllers/Manga/MangaController.cs
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)
{
}
17 changes: 2 additions & 15 deletions Juro/Clients/AnimeApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AnimeApiClient(string baseUrl, IHttpClientFactory httpClientFactory

public string BaseUrl { get; set; } = baseUrl;

public string ProviderKey { get; set; } = "Gogoanime";
public string ProviderKey { get; set; } = "Anime";

/// <summary>
/// Initializes an instance of <see cref="AnimeApiClient"/>.
Expand All @@ -36,30 +36,17 @@ public AnimeApiClient(string baseUrl)
: this(baseUrl, Http.ClientProvider) { }

public async ValueTask<List<Provider>> GetProvidersAsync(
ProviderType type,
CancellationToken cancellationToken = default
)
{
var response = await _http.ExecuteAsync(
$"{BaseUrl}/Providers?type={type}",
$"{BaseUrl}/Providers?type={(int)ProviderType.Anime}",
cancellationToken: cancellationToken
);

return JsonSerializer.Deserialize<List<Provider>>(response, _options)!;
}

public async ValueTask<Provider> GetDefaultProviderAsync(
CancellationToken cancellationToken = default
)
{
var response = await _http.ExecuteAsync(
$"{BaseUrl}/Providers",
cancellationToken: cancellationToken
);

return JsonSerializer.Deserialize<Provider>(response, _options)!;
}

public async ValueTask<IAnimeInfo> GetAsync(
string id,
CancellationToken cancellationToken = default
Expand Down
108 changes: 108 additions & 0 deletions Juro/Clients/MangaApiClient.cs
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) ?? [];
}
}
2 changes: 1 addition & 1 deletion Juro/Juro.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down

0 comments on commit a0fba63

Please sign in to comment.