mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-14 18:33:02 +02:00
More logging
This commit is contained in:
parent
1b49b171f4
commit
397d3c93df
@ -31,7 +31,7 @@ internal abstract class DownloadClient
|
||||
_lastExecutedRateLimit.TryAdd(requestType, now.Subtract(timeBetweenRequests));
|
||||
|
||||
TimeSpan rateLimitTimeout = timeBetweenRequests.Subtract(now.Subtract(_lastExecutedRateLimit[requestType]));
|
||||
Log.Debug($"Request limit {rateLimit}/Minute timeBetweenRequests: {timeBetweenRequests} Timeout: {rateLimitTimeout}");
|
||||
Log.Debug($"Request limit {rateLimit}/Minute timeBetweenRequests: {timeBetweenRequests:ss.fff} Timeout: {rateLimitTimeout:ss.fff}");
|
||||
|
||||
if (rateLimitTimeout > TimeSpan.Zero)
|
||||
{
|
||||
|
@ -73,12 +73,14 @@ public class Kavita : LibraryConnector
|
||||
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/Library/libraries", "Bearer", Auth);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
return Array.Empty<KavitaLibrary>();
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
{
|
||||
return Array.Empty<KavitaLibrary>();
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
|
||||
List<KavitaLibrary> ret = new();
|
||||
|
@ -38,12 +38,14 @@ public class Komga : LibraryConnector
|
||||
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/v1/libraries", "Basic", Auth);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
return Array.Empty<KomgaLibrary>();
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
{
|
||||
return Array.Empty<KomgaLibrary>();
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
|
||||
HashSet<KomgaLibrary> ret = new();
|
||||
|
@ -1,5 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.LibraryConnectors;
|
||||
|
||||
@ -20,6 +23,10 @@ public abstract class LibraryConnector(string libraryConnectorId, LibraryType li
|
||||
[Required]
|
||||
public string Auth { get; init; } = auth;
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
protected ILog Log { get; init; } = LogManager.GetLogger($"{libraryType.ToString()} {baseUrl}");
|
||||
|
||||
protected abstract void UpdateLibraryInternal();
|
||||
internal abstract bool Test();
|
||||
}
|
@ -1,48 +1,52 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using log4net;
|
||||
|
||||
namespace API.Schema.LibraryConnectors;
|
||||
|
||||
public class NetClient
|
||||
{
|
||||
private static ILog Log = LogManager.GetLogger(typeof(NetClient));
|
||||
|
||||
public static Stream MakeRequest(string url, string authScheme, string auth)
|
||||
{
|
||||
Log.Debug($"Requesting {url}");
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||
|
||||
HttpRequestMessage requestMessage = new()
|
||||
{
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
try
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
|
||||
if (response.StatusCode is HttpStatusCode.Unauthorized &&
|
||||
response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return response.Content.ReadAsStream();
|
||||
else
|
||||
return Stream.Null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case HttpRequestException:
|
||||
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
if (response.StatusCode is HttpStatusCode.Unauthorized &&
|
||||
response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return response.Content.ReadAsStream();
|
||||
else
|
||||
return Stream.Null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case HttpRequestException:
|
||||
Log.Debug(e);
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
Log.Info("Failed to make request");
|
||||
return Stream.Null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool MakePost(string url, string authScheme, string auth)
|
||||
public static bool MakePost(string url, string authScheme, string auth)
|
||||
{
|
||||
HttpClient client = new()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user