fix: object reference not set by adding retry for GetDecryptionKeyOFDL
This commit is contained in:
parent
c147a19a0a
commit
2bddedb644
@ -31,6 +31,8 @@ public class APIHelper : IAPIHelper
|
||||
private readonly Auth auth;
|
||||
private static DateTime? cachedDynamicRulesExpiration;
|
||||
private static DynamicRules? cachedDynamicRules;
|
||||
private const int MaxAttempts = 30;
|
||||
private const int DelayBetweenAttempts = 3000;
|
||||
|
||||
static APIHelper()
|
||||
{
|
||||
@ -2674,13 +2676,10 @@ public class APIHelper : IAPIHelper
|
||||
return DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> GetDecryptionKeyCDRMProject(Dictionary<string, string> drmHeaders, string licenceURL, string pssh)
|
||||
{
|
||||
Log.Debug("Calling GetDecryptionKey");
|
||||
|
||||
const int maxAttempts = 30;
|
||||
const int delayBetweenAttempts = 3000;
|
||||
int attempt = 0;
|
||||
|
||||
try
|
||||
@ -2701,7 +2700,7 @@ public class APIHelper : IAPIHelper
|
||||
|
||||
Log.Debug($"Posting to CDRM Project: {json}");
|
||||
|
||||
while (attempt < maxAttempts)
|
||||
while (attempt < MaxAttempts)
|
||||
{
|
||||
attempt++;
|
||||
|
||||
@ -2727,19 +2726,19 @@ public class APIHelper : IAPIHelper
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"CDRM response status not successful. Retrying... Attempt {attempt} of {maxAttempts}");
|
||||
if (attempt < maxAttempts)
|
||||
Log.Debug($"CDRM response status not successful. Retrying... Attempt {attempt} of {MaxAttempts}");
|
||||
if (attempt < MaxAttempts)
|
||||
{
|
||||
await Task.Delay(delayBetweenAttempts);
|
||||
await Task.Delay(DelayBetweenAttempts);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"Status not in CDRM response. Retrying... Attempt {attempt} of {maxAttempts}");
|
||||
if (attempt < maxAttempts)
|
||||
Log.Debug($"Status not in CDRM response. Retrying... Attempt {attempt} of {MaxAttempts}");
|
||||
if (attempt < MaxAttempts)
|
||||
{
|
||||
await Task.Delay(delayBetweenAttempts);
|
||||
await Task.Delay(DelayBetweenAttempts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2764,11 +2763,10 @@ public class APIHelper : IAPIHelper
|
||||
{
|
||||
Log.Debug("Calling GetDecryptionOFDL");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
string dcValue = string.Empty;
|
||||
HttpClient client = new();
|
||||
int attempt = 0;
|
||||
|
||||
OFDLRequest ofdlRequest = new OFDLRequest
|
||||
{
|
||||
@ -2781,6 +2779,10 @@ public class APIHelper : IAPIHelper
|
||||
|
||||
Log.Debug($"Posting to ofdl.tools: {json}");
|
||||
|
||||
while (attempt < MaxAttempts)
|
||||
{
|
||||
attempt++;
|
||||
|
||||
HttpRequestMessage request = new(HttpMethod.Post, "https://ofdl.tools/WV")
|
||||
{
|
||||
Content = new StringContent(json, Encoding.UTF8, "application/json")
|
||||
@ -2788,10 +2790,16 @@ public class APIHelper : IAPIHelper
|
||||
|
||||
using var response = await client.SendAsync(request);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
continue;
|
||||
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!body.TrimStart().StartsWith('{'))
|
||||
return body;
|
||||
|
||||
Log.Debug($"Received JSON object instead of string. Retrying... Attempt {attempt} of {MaxAttempts}");
|
||||
await Task.Delay(DelayBetweenAttempts);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -2805,6 +2813,7 @@ public class APIHelper : IAPIHelper
|
||||
Log.Error("Inner Exception: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user