diff --git a/Forms/FormMain.cs b/Forms/FormMain.cs index ffaba41..5744688 100644 --- a/Forms/FormMain.cs +++ b/Forms/FormMain.cs @@ -8,6 +8,7 @@ using PlenBotLogUploader.GitHub; using PlenBotLogUploader.Gw2Api; using PlenBotLogUploader.Tools; +using RestSharp; using System; using System.Collections.Generic; using System.Diagnostics; @@ -73,6 +74,7 @@ internal bool UpdateFound private readonly List allSessionLogs = []; private readonly Regex songSmartCommandRegex = songRegex(); private readonly Regex buildSmartCommandRegex = buildRegex(); + private readonly RestClient logPoster; private SemaphoreSlim semaphore; private TwitchChatClient chatConnect; private readonly ArcLogsChangeObserver watcher; @@ -141,6 +143,7 @@ internal FormMain() toolTip.SetToolTip(checkBoxAutoUpdate, "Automatically downloads the newest version when it is available.\nOnly occurs during the start of the application."); toolTip.SetToolTip(twitchCommandsLink.checkBoxSongEnable, "If checked, the given command will output current song from Spotify to Twitch chat."); #endregion + logPoster = new RestClient(); try { Size = ApplicationSettings.Current.MainFormSize; @@ -740,21 +743,16 @@ internal async Task SendLogToTwitchChatAsync(DpsReportJson reportJSON, bool bypa internal async Task HttpUploadLogAsync(string file, Dictionary postData, bool bypassMessage = false) { - using var content = new MultipartFormDataContent(); - foreach (var key in postData.Keys) - { - content.Add(new StringContent(postData[key]), key); - } AddToText($">:> Uploading {Path.GetFileName(file)}"); + var request = new RestRequest(CreateDPSReportLink()); + request.AddBody(postData); var bossId = 1; try { - using var inputStream = File.OpenRead(file); - using var contentStream = new StreamContent(inputStream); - content.Add(contentStream, "file", Path.GetFileName(file)); + request.AddFile("file", file); try { - using var responseMessage = await HttpClientController.PostAsync(CreateDPSReportLink(), content); + var responseMessage = await logPoster.PostAsync(request); if (!responseMessage.IsSuccessStatusCode) { var statusCode = (int)responseMessage.StatusCode; @@ -786,10 +784,9 @@ internal async Task HttpUploadLogAsync(string file, Dictionary p AddToText($">:> Unable to upload file {Path.GetFileName(file)}, dps.report responded with an non-ok status code ({(int)responseMessage.StatusCode})."); return; } - var response = await responseMessage.Content.ReadAsStringAsync(); try { - var reportJson = JsonConvert.DeserializeObject(response); + var reportJson = JsonConvert.DeserializeObject(responseMessage.Content); if (!string.IsNullOrEmpty(reportJson.Error)) { AddToText($">:> Error processing file {Path.GetFileName(file)}, dps.report responded with following error message: {reportJson.Error}"); diff --git a/PlenBotLogUploader.csproj b/PlenBotLogUploader.csproj index 328fab7..c53c93c 100644 --- a/PlenBotLogUploader.csproj +++ b/PlenBotLogUploader.csproj @@ -59,10 +59,11 @@ + - +