|
@@ -4,11 +4,14 @@ using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
using VeloeAvaloniaKemonoPartyApp.Models;
|
|
using VeloeAvaloniaKemonoPartyApp.Models;
|
|
|
|
+using VeloeAvaloniaKemonoPartyApp.Services;
|
|
|
|
|
|
namespace VeloeKemonoPartyApp.Services
|
|
namespace VeloeKemonoPartyApp.Services
|
|
{
|
|
{
|
|
public class KemonoHttpClient : IDisposable
|
|
public class KemonoHttpClient : IDisposable
|
|
{
|
|
{
|
|
|
|
+ private StorageService _storageService = new();
|
|
|
|
+
|
|
public HttpClient httpClient;
|
|
public HttpClient httpClient;
|
|
|
|
|
|
public List<Post> posts;
|
|
public List<Post> posts;
|
|
@@ -22,11 +25,31 @@ namespace VeloeKemonoPartyApp.Services
|
|
posts = new List<Post>();
|
|
posts = new List<Post>();
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<List<Creator>> GetCreatorsList()
|
|
|
|
|
|
+ public async Task<List<Creator>> GetCreatorsList(bool reloadSource)
|
|
{
|
|
{
|
|
|
|
+ if (System.IO.File.Exists(await _storageService.GetDocumentsFolderAsync() + "/creators.json") && new System.IO.FileInfo(await _storageService.GetDocumentsFolderAsync() + "/creators.json").CreationTime > DateTime.Now.AddDays(-7) && !reloadSource)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ using (var stream = System.IO.File.OpenRead(await _storageService.GetDocumentsFolderAsync() + "/creators.json"))
|
|
|
|
+ {
|
|
|
|
+ return await JsonSerializer.DeserializeAsync<List<Creator>>(stream);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch
|
|
|
|
+ {
|
|
|
|
+ System.IO.File.Delete(await _storageService.GetDocumentsFolderAsync() + "/creators.json");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
using (HttpResponseMessage response = await httpClient.GetAsync("https://kemono.su/api/v1/creators.txt"))
|
|
using (HttpResponseMessage response = await httpClient.GetAsync("https://kemono.su/api/v1/creators.txt"))
|
|
using (HttpContent content = response.Content)
|
|
using (HttpContent content = response.Content)
|
|
{
|
|
{
|
|
|
|
+ using (var stream = System.IO.File.OpenWrite(await _storageService.GetDocumentsFolderAsync() + "/creators.json"))
|
|
|
|
+ {
|
|
|
|
+ stream.Write(await response.Content.ReadAsByteArrayAsync());
|
|
|
|
+ }
|
|
|
|
+
|
|
return await JsonSerializer.DeserializeAsync<List<Creator>>(await response.Content.ReadAsStreamAsync());
|
|
return await JsonSerializer.DeserializeAsync<List<Creator>>(await response.Content.ReadAsStreamAsync());
|
|
}
|
|
}
|
|
}
|
|
}
|