mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-30 19:54:14 -04:00
* Lots of cleanup on the warnings in the solution. Deprecated IsLastWriteLessThan and made a new method HasFileBeenModifiedSince. * Added some tests for the new extension method. * Changed filter import to use correct import * Scan Series now uses Refresh Metadata for Series, rather than library one. * Fixed an issue where cover generation wasn't properly taking forced update into consideration. Removed a case of cover generation for no reason. * Fixed series downloads not triggering backend call
55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Threading.Tasks;
|
|
using API.DTOs.Stats;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Services.Clients
|
|
{
|
|
public class StatsApiClient
|
|
{
|
|
private readonly HttpClient _client;
|
|
private readonly ILogger<StatsApiClient> _logger;
|
|
#pragma warning disable S1075
|
|
private const string ApiUrl = "http://stats.kavitareader.com";
|
|
#pragma warning restore S1075
|
|
|
|
public StatsApiClient(HttpClient client, ILogger<StatsApiClient> logger)
|
|
{
|
|
_client = client;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task SendDataToStatsServer(UsageStatisticsDto data)
|
|
{
|
|
var responseContent = string.Empty;
|
|
|
|
try
|
|
{
|
|
using var response = await _client.PostAsJsonAsync(ApiUrl + "/api/InstallationStats", data);
|
|
|
|
responseContent = await response.Content.ReadAsStringAsync();
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
}
|
|
catch (HttpRequestException e)
|
|
{
|
|
var info = new
|
|
{
|
|
dataSent = data,
|
|
response = responseContent
|
|
};
|
|
|
|
_logger.LogError(e, "KavitaStats did not respond successfully. {Content}", info);
|
|
throw;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, "An error happened during the request to KavitaStats");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|