mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Fix Moddb streamer
This commit is contained in:
parent
440de5e277
commit
2d8670cf98
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user