From 143c0b1e81efe4ee221cfb9771b666a6db66d112 Mon Sep 17 00:00:00 2001 From: thattuys <110502928+thattuys@users.noreply.github.com> Date: Tue, 2 Aug 2022 19:12:41 -0400 Subject: [PATCH 1/3] Support downloading from http Add http support to downloads(ws:// connections and uploads already work, this is just fixing the downloads) --- MareSynchronos/WebAPI/ApIController.Functions.Files.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs index 6cd527e..8757795 100644 --- a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs +++ b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs @@ -55,7 +55,12 @@ namespace MareSynchronos.WebAPI wc.DownloadProgressChanged += progChanged; string fileName = Path.GetTempFileName(); - var baseUri = new Uri(ApiUri.Replace("wss", "https"), UriKind.Absolute); + Uri baseUri; + if (ApiUri.StartsWith("ws://")) { // Bad bad bad but yeah + baseUri = new Uri(ApiUri.Replace("ws", "http"), UriKind.Absolute); + } else { + baseUri = new Uri(ApiUri.Replace("wss", "https"), UriKind.Absolute); + } var relativeUri = new Uri("cache/" + hash, UriKind.Relative); var fileUri = new Uri(baseUri, relativeUri); From 04afc4db026e86872bb7c502e453bda47faf9379 Mon Sep 17 00:00:00 2001 From: thattuys <110502928+thattuys@users.noreply.github.com> Date: Tue, 2 Aug 2022 19:22:22 -0400 Subject: [PATCH 2/3] Update ApIController.Functions.Files.cs --- MareSynchronos/WebAPI/ApIController.Functions.Files.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs index 8757795..d253476 100644 --- a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs +++ b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs @@ -55,12 +55,7 @@ namespace MareSynchronos.WebAPI wc.DownloadProgressChanged += progChanged; string fileName = Path.GetTempFileName(); - Uri baseUri; - if (ApiUri.StartsWith("ws://")) { // Bad bad bad but yeah - baseUri = new Uri(ApiUri.Replace("ws", "http"), UriKind.Absolute); - } else { - baseUri = new Uri(ApiUri.Replace("wss", "https"), UriKind.Absolute); - } + var baseUri = new Uri(ApiUri.Replace("ws", "http"), UriKind.Absolute); var relativeUri = new Uri("cache/" + hash, UriKind.Relative); var fileUri = new Uri(baseUri, relativeUri); From f718ebef9bcd306b7f2276f810d9dc83c87e2436 Mon Sep 17 00:00:00 2001 From: thattuys <110502928+thattuys@users.noreply.github.com> Date: Tue, 2 Aug 2022 19:36:28 -0400 Subject: [PATCH 3/3] Update ApIController.Functions.Files.cs Only replace the first occurrence of "ws" in the Uri string --- MareSynchronos/WebAPI/ApIController.Functions.Files.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs index d253476..514bcab 100644 --- a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs +++ b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using LZ4; @@ -55,7 +56,7 @@ namespace MareSynchronos.WebAPI wc.DownloadProgressChanged += progChanged; string fileName = Path.GetTempFileName(); - var baseUri = new Uri(ApiUri.Replace("ws", "http"), UriKind.Absolute); + var baseUri = new Uri(Regex.Replace(ApiUri, "^ws", "http"), UriKind.Absolute); var relativeUri = new Uri("cache/" + hash, UriKind.Relative); var fileUri = new Uri(baseUri, relativeUri);