Skip to content

Commit

Permalink
Merge pull request #13 from andy840119/refactor-the-project
Browse files Browse the repository at this point in the history
Refactor the project.
  • Loading branch information
andy840119 authored May 2, 2022
2 parents 7ee62b7 + e86989e commit 13c5f8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 60 deletions.
2 changes: 1 addition & 1 deletion NHentaiAPI.Tests/NHentaiAPI.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
81 changes: 23 additions & 58 deletions NHentaiAPI/NHentaiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,71 +33,47 @@ public class NHentaiClient : IDisposable

#region Data urls

protected virtual string GetHomePageUrl(int pageNum)
{
return $"{ApiRootUrl}/api/galleries/all?page={pageNum}";
}
protected virtual string GetHomePageUrl(int pageNum)
=> $"{ApiRootUrl}/api/galleries/all?page={pageNum}";

protected virtual string GetSearchUrl(string content,int pageNum)
{
return $"{ApiRootUrl}/api/galleries/search?" +
$"query={content.Replace(" ", "+")}&" +
$"page={pageNum}";
}
protected virtual string GetSearchUrl(string content,int pageNum)
=> $"{ApiRootUrl}/api/galleries/search?" +
$"query={content.Replace(" ", "+")}&" +
$"page={pageNum}";

protected virtual string GetTagUrl(Tag tag, bool isPopularList, int pageNum)
{
return $"{ApiRootUrl}/api/galleries/tagged?" +
$"tag_id={tag.Id}" +
$"&page={pageNum}" +
(isPopularList ? "&sort=popular" : "");
}
protected virtual string GetTagUrl(Tag tag, bool isPopularList, int pageNum)
=> $"{ApiRootUrl}/api/galleries/tagged?" +
$"tag_id={tag.Id}" +
$"&page={pageNum}" +
(isPopularList ? "&sort=popular" : "");

protected virtual string GetBookDetailsUrl(int bookId)
{
return $"{ApiRootUrl}/api/gallery/{bookId}";
}

protected virtual string GetBookRecommendUrl(int bookId)
{
return $"{ApiRootUrl}/api/gallery/{bookId}/related";
}

protected virtual string GetGalleryUrl(int galleryId)
{
return $"{ImageRootUrl}/galleries/{galleryId}";
}
protected virtual string GetBookDetailsUrl(int bookId)
=> $"{ApiRootUrl}/api/gallery/{bookId}";

protected virtual string GetThumbGalleryUrl(int galleryId)
{
return $"{ThumbnailRootUrl}/galleries/{galleryId}";
}
protected virtual string GetBookRecommendUrl(int bookId)
=> $"{ApiRootUrl}/api/gallery/{bookId}/related";

protected virtual string GetGalleryUrl(int galleryId)
=> $"{ImageRootUrl}/galleries/{galleryId}";

protected virtual string GetThumbGalleryUrl(int galleryId)
=> $"{ThumbnailRootUrl}/galleries/{galleryId}";

#endregion

#region Picture urls

public virtual string GetPictureUrl(Book book, int pageNum)
{
// Get image
var image = GetImage(book, pageNum);

// Get file type
var fileType = ConvertType(image.Type);

// Get url
return GetPictureUrl(book.MediaId, pageNum, fileType);
}

public virtual string GetThumbPictureUrl(Book book, int pageNum)
{
// Get image
var image = GetImage(book, pageNum);

// Get file type
var fileType = ConvertType(image.Type);

// Get url
return GetThumbPictureUrl(book.MediaId, pageNum, fileType);
}

Expand All @@ -109,10 +85,7 @@ public virtual string GetOriginPictureUrl(Book book, int pageNum)

public virtual string GetBookThumbUrl(Book book)
{
// Get file type
var fileType = ConvertType(book.Images.Cover.Type);

// Get url
return GetBookThumbUrl(book.MediaId, fileType);
}

Expand All @@ -137,15 +110,8 @@ protected virtual string GetBookThumbUrl(int galleryId ,string fileType = "jpg")

protected virtual async Task<TOutput> GetData<TOutput>(string rootUrl)
{
try
{
var json = await _client.GetStringAsync(rootUrl);
return JsonConvert.DeserializeObject<TOutput>(json);
}
catch (Exception ex)
{
throw;
}
var json = await _client.GetStringAsync(rootUrl);
return JsonConvert.DeserializeObject<TOutput>(json);
}

protected virtual async Task<byte[]> GetByteData(string rootUrl)
Expand All @@ -159,7 +125,6 @@ protected virtual Image GetImage(Book book, int pageNum)
if (book == null)
throw new ArgumentNullException(nameof(book));

// Get page
var page = book.Images.Pages[pageNum - 1];
return page;
}
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
clone_depth: 1
version: '{build}'
skip_tags: true
image: Visual Studio 2017
image: Visual Studio 2022
configuration: Debug
before_build:
- cmd: nuget restore
Expand Down

0 comments on commit 13c5f8a

Please sign in to comment.