Skip to content

Commit

Permalink
Fix Moddb streamer
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Jun 9, 2022
1 parent 440de5e commit 2d8670c
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Wabbajack.Downloaders.ModDB/ModDBDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,30 @@ public Uri UnParse(IDownloadState state)
public async Task<T> DownloadStream<T>(Archive archive, Func<Stream, Task<T>> fn, CancellationToken token)
{
var state = archive.State as DTOs.DownloadStates.ModDB;
var url = (await GetDownloadUrls(state!)).First();
try
foreach (var url in await GetDownloadUrls(state!))
{
var msg = new HttpRequestMessage
try
{
Method = HttpMethod.Get,
RequestUri = new Uri(url)
};
using var response = await _httpClient.SendAsync(msg, token);
HttpException.ThrowOnFailure(response);
await using var stream = await response.Content.ReadAsStreamAsync(token);
return await fn(stream);
}
catch (Exception ex)
{
_logger.LogError(ex, "While downloading from ModDB");
throw;
var msg = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(url)
};
using var response = await _httpClient.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead, token);
if (!response.IsSuccessStatusCode)
continue;
HttpException.ThrowOnFailure(response);
await using var stream = await response.Content.ReadAsStreamAsync(token);
return await fn(stream);
}
catch (Exception ex)
{
_logger.LogError(ex, "While downloading from ModDB");
throw;
}
}
_logger.LogError("All servers were invalid downloading from ModDB {Uri}", state.Url);
return default;
}

public override async Task<Hash> Download(Archive archive, DTOs.DownloadStates.ModDB state,
Expand Down

0 comments on commit 2d8670c

Please sign in to comment.