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