mirror of
https://github.com/C9Glax/tranga.git
synced 2025-10-11 05:09:49 +02:00
Fix #468 failed downloads (Task cancelled) results in empty chapter archive
Some checks are pending
Docker Image CI / build (push) Waiting to run
Some checks are pending
Docker Image CI / build (push) Waiting to run
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
|
||||
public interface IDownloadClient
|
||||
{
|
||||
internal Task<HttpResponseMessage> MakeRequest(string url, RequestType requestType, string? referrer = null);
|
||||
internal Task<HttpResponseMessage> MakeRequest(string url, RequestType requestType, string? referrer = null,
|
||||
CancellationToken? cancellationToken = null);
|
||||
}
|
@@ -12,7 +12,7 @@ public class FlareSolverrDownloadClient(HttpClient client) : IDownloadClient
|
||||
{
|
||||
private ILog Log { get; } = LogManager.GetLogger(typeof(FlareSolverrDownloadClient));
|
||||
|
||||
public async Task<HttpResponseMessage> MakeRequest(string url, RequestType requestType, string? referrer = null)
|
||||
public async Task<HttpResponseMessage> MakeRequest(string url, RequestType requestType, string? referrer = null, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
Log.Debug($"Using {typeof(FlareSolverrDownloadClient).FullName} for {url}");
|
||||
if(referrer is not null)
|
||||
@@ -46,7 +46,7 @@ public class FlareSolverrDownloadClient(HttpClient client) : IDownloadClient
|
||||
HttpResponseMessage? response;
|
||||
try
|
||||
{
|
||||
response = await client.SendAsync(requestMessage);
|
||||
response = await client.SendAsync(requestMessage, cancellationToken ?? CancellationToken.None);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ public class FlareSolverrDownloadClient(HttpClient client) : IDownloadClient
|
||||
return response;
|
||||
}
|
||||
|
||||
string responseString = response.Content.ReadAsStringAsync().Result;
|
||||
string responseString = await response.Content.ReadAsStringAsync(cancellationToken ?? CancellationToken.None);
|
||||
JObject responseObj = JObject.Parse(responseString);
|
||||
if (!IsInCorrectFormat(responseObj, out string? reason))
|
||||
{
|
||||
|
@@ -14,7 +14,7 @@ internal class HttpDownloadClient : IDownloadClient
|
||||
private static readonly FlareSolverrDownloadClient FlareSolverrDownloadClient = new(Client);
|
||||
private ILog Log { get; } = LogManager.GetLogger(typeof(HttpDownloadClient));
|
||||
|
||||
public async Task<HttpResponseMessage> MakeRequest(string url, RequestType requestType, string? referrer = null)
|
||||
public async Task<HttpResponseMessage> MakeRequest(string url, RequestType requestType, string? referrer = null, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
Log.Debug($"Using {typeof(HttpDownloadClient).FullName} for {url}");
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
||||
@@ -24,7 +24,7 @@ internal class HttpDownloadClient : IDownloadClient
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await Client.SendAsync(requestMessage);
|
||||
HttpResponseMessage response = await Client.SendAsync(requestMessage, cancellationToken ?? CancellationToken.None);
|
||||
Log.Debug($"Request {url} returned {(int)response.StatusCode} {response.StatusCode}");
|
||||
if(response.IsSuccessStatusCode)
|
||||
return response;
|
||||
|
Reference in New Issue
Block a user