Add more Logging

This commit is contained in:
2025-05-08 03:03:44 +02:00
parent a490e233d7
commit ec5d048df5
4 changed files with 110 additions and 23 deletions

View File

@ -16,6 +16,7 @@ internal abstract class DownloadClient
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
{
Log.Debug($"Requesting {url}");
if (!TrangaSettings.requestLimits.ContainsKey(requestType))
{
return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null);
@ -24,14 +25,17 @@ internal abstract class DownloadClient
int rateLimit = TrangaSettings.userAgent == TrangaSettings.DefaultUserAgent
? TrangaSettings.DefaultRequestLimits[requestType]
: TrangaSettings.requestLimits[requestType];
Log.Debug($"Request limit {rateLimit}");
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
_lastExecutedRateLimit.TryAdd(requestType, DateTime.UtcNow.Subtract(timeBetweenRequests));
TimeSpan rateLimitTimeout = timeBetweenRequests.Subtract(DateTime.UtcNow.Subtract(_lastExecutedRateLimit[requestType]));
if (rateLimitTimeout > TimeSpan.Zero)
{
Log.Debug($"Timeout: {rateLimitTimeout}");
Thread.Sleep(rateLimitTimeout);
}