Add project files.

This commit is contained in:
2025-05-21 19:39:09 -04:00
parent 7d2b71fe95
commit ec1713c95f
27 changed files with 5843 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using MangaReader.Core.HttpService;
using System.Text.Json;
namespace MangaReader.Core.WebSearch;
public abstract class MangaWebSearchBase<T>(IHttpService httpService) : IMangaWebSearch<T>
{
private static JsonSerializerOptions _jsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true
};
public async Task<MangaSearchResult[]> SearchAsync(string keyword)
{
T? searchResult = await GetSearchResultAsync(keyword);
if (searchResult == null)
return [];
return GetSearchResult(searchResult);
}
private async Task<T?> GetSearchResultAsync(string keyword)
{
string url = GetSearchUrl(keyword);
string response = await httpService.GetStringAsync(url);
return JsonSerializer.Deserialize<T>(response, _jsonSerializerOptions);
}
protected abstract string GetSearchUrl(string keyword);
protected abstract MangaSearchResult[] GetSearchResult(T searchResult);
}