Merge pull request #841 from wabbajack-tools/server-archive-downloader

Create a mod file archiver.
This commit is contained in:
Timothy Baldridge 2020-05-14 09:30:20 -07:00 committed by GitHub
commit 23fecce38b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -153,6 +153,14 @@ namespace Wabbajack.Lib.NexusApi
return await Get<UserStatus>(url);
}
public async Task<(int, int)> GetRemainingApiCalls()
{
var url = "https://api.nexusmods.com/v1/users/validate.json";
using var response = await HttpClient.GetAsync(url);
return (int.Parse(response.Headers.GetValues("X-RL-Daily-Remaining").First()),
int.Parse(response.Headers.GetValues("X-RL-Hourly-Remaining").First()));
}
#endregion
#region Rate Tracking

View File

@ -26,12 +26,16 @@ namespace Wabbajack.Server.Services
public override async Task<int> Execute()
{
_nexusClient ??= await NexusApiClient.Get();
await _nexusClient.GetUserStatus();
int count = 0;
while (true)
{
bool ignoreNexus = _nexusClient.HourlyRemaining < 25;
var (daily, hourly) = await _nexusClient.GetRemainingApiCalls();
bool ignoreNexus = hourly < 25;
if (ignoreNexus)
_logger.LogWarning($"Ignoring Nexus Downloads due to low hourly api limit (Daily: {_nexusClient.DailyRemaining}, Hourly:{_nexusClient.HourlyRemaining})");
else
_logger.LogInformation($"Looking for any download (Daily: {_nexusClient.DailyRemaining}, Hourly:{_nexusClient.HourlyRemaining})");
var nextDownload = await _sql.GetNextPendingDownload(ignoreNexus);