From ec84365603aa7eb3bb2ad7e14f437d2d72051846 Mon Sep 17 00:00:00 2001 From: Jared Date: Thu, 24 Sep 2020 07:36:05 -0700 Subject: [PATCH] Return FileStream for Windows installer. --- Server/API/ClientDownloadsController.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Server/API/ClientDownloadsController.cs b/Server/API/ClientDownloadsController.cs index 277542f4..a0473903 100644 --- a/Server/API/ClientDownloadsController.cs +++ b/Server/API/ClientDownloadsController.cs @@ -48,21 +48,20 @@ namespace Remotely.Server.API if (await FileLock.WaitAsync(TimeSpan.FromSeconds(15))) { var scheme = AppConfig.RedirectToHttps ? "https" : Request.Scheme; - var fileContents = new List(); - string fileName; - byte[] fileBytes; + switch (platformID) { case "Windows": { var filePath = Path.Combine(HostEnv.WebRootPath, "Downloads", $"Remotely_Installer.exe"); - fileBytes = await System.IO.File.ReadAllBytesAsync(filePath); - fileName = $"Remotely_Installer-{organizationID}.exe"; - break; + var fileName = $"Remotely_Installer-{organizationID}.exe"; + var fileStream = System.IO.File.OpenRead(filePath); + return File(fileStream, "application/octet-stream", $"{fileName}"); } case "Linux-x64": { - fileName = "Install-Linux-x64.sh"; + var fileContents = new List(); + var fileName = "Install-Linux-x64.sh"; fileContents.AddRange(await System.IO.File.ReadAllLinesAsync(Path.Combine(HostEnv.WebRootPath, "Downloads", $"{fileName}"))); @@ -71,15 +70,13 @@ namespace Remotely.Server.API fileContents[hostIndex] = $"HostName=\"{scheme}://{Request.Host}\""; fileContents[orgIndex] = $"Organization=\"{organizationID}\""; - fileBytes = Encoding.UTF8.GetBytes(string.Join("\n", fileContents)); - break; + var fileBytes = Encoding.UTF8.GetBytes(string.Join("\n", fileContents)); + return File(fileBytes, "application/octet-stream", $"{fileName}"); } default: return BadRequest(); } - - return File(fileBytes, "application/octet-stream", $"{fileName}"); } else {