Fix Moddb streamer

This commit is contained in:
Timothy Baldridge 2022-06-09 15:05:26 -06:00
parent 440de5e277
commit 2d8670cf98

View File

@ -75,24 +75,30 @@ public class ModDBDownloader : ADownloader<DTOs.DownloadStates.ModDB>, IUrlDownl
public async Task<T> DownloadStream<T>(Archive archive, Func<Stream, Task<T>> fn, CancellationToken token) public async Task<T> DownloadStream<T>(Archive archive, Func<Stream, Task<T>> fn, CancellationToken token)
{ {
var state = archive.State as DTOs.DownloadStates.ModDB; var state = archive.State as DTOs.DownloadStates.ModDB;
var url = (await GetDownloadUrls(state!)).First(); foreach (var url in await GetDownloadUrls(state!))
try
{ {
var msg = new HttpRequestMessage try
{ {
Method = HttpMethod.Get, var msg = new HttpRequestMessage
RequestUri = new Uri(url) {
}; Method = HttpMethod.Get,
using var response = await _httpClient.SendAsync(msg, token); RequestUri = new Uri(url)
HttpException.ThrowOnFailure(response); };
await using var stream = await response.Content.ReadAsStreamAsync(token); using var response = await _httpClient.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead, token);
return await fn(stream); if (!response.IsSuccessStatusCode)
} continue;
catch (Exception ex) HttpException.ThrowOnFailure(response);
{ await using var stream = await response.Content.ReadAsStreamAsync(token);
_logger.LogError(ex, "While downloading from ModDB"); return await fn(stream);
throw; }
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, public override async Task<Hash> Download(Archive archive, DTOs.DownloadStates.ModDB state,