Fix download request failing to download if route provided starts with a /

dashboard
Pat Hartl 2023-01-14 16:11:28 -06:00
parent 98062e3f37
commit 4bcad9b76b
1 changed files with 3 additions and 4 deletions

View File

@ -46,6 +46,8 @@ namespace LANCommander.PlaynitePlugin
private string DownloadRequest(string route, Action<DownloadProgressChangedEventArgs> progressHandler, Action<AsyncCompletedEventArgs> completeHandler) private string DownloadRequest(string route, Action<DownloadProgressChangedEventArgs> progressHandler, Action<AsyncCompletedEventArgs> completeHandler)
{ {
route = route.TrimStart('/');
var client = new WebClient(); var client = new WebClient();
var tempFile = Path.GetTempFileName(); var tempFile = Path.GetTempFileName();
@ -53,9 +55,6 @@ namespace LANCommander.PlaynitePlugin
client.DownloadProgressChanged += (s, e) => progressHandler(e); client.DownloadProgressChanged += (s, e) => progressHandler(e);
client.DownloadFileCompleted += (s, e) => completeHandler(e); client.DownloadFileCompleted += (s, e) => completeHandler(e);
var request = new RestRequest(route)
.AddHeader("Authorization", $"Bearer {Token.AccessToken}");
client.DownloadFileAsync(new Uri($"{Client.BaseUrl}{route}"), tempFile); client.DownloadFileAsync(new Uri($"{Client.BaseUrl}{route}"), tempFile);
return tempFile; return tempFile;
@ -128,7 +127,7 @@ namespace LANCommander.PlaynitePlugin
public string DownloadArchive(Guid id, Action<DownloadProgressChangedEventArgs> progressHandler, Action<AsyncCompletedEventArgs> completeHandler) public string DownloadArchive(Guid id, Action<DownloadProgressChangedEventArgs> progressHandler, Action<AsyncCompletedEventArgs> completeHandler)
{ {
return DownloadRequest($"api/Archives/Download/{id}", progressHandler, completeHandler); return DownloadRequest($"/api/Archives/Download/{id}", progressHandler, completeHandler);
} }
} }
} }