Skip to content

Commit

Permalink
Return file as a stream instead of loading all bytes into memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Aug 9, 2020
1 parent cf4623b commit 8d42f5f
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions Server/API/AgentUpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ public ActionResult ClearDownload(string downloadId)
return Ok();
}

// TODO: Remove in the next few updates.
[HttpGet("[action]")]
public string CurrentVersion()
{
var filePath = Path.Combine(HostEnv.ContentRootPath, "CurrentVersion.txt");
if (!System.IO.File.Exists(filePath))
{
return "0.0.0.0";
}
return System.IO.File.ReadAllText(filePath).Trim();
}

[HttpGet("[action]/{platform}/{downloadId}")]
public async Task<ActionResult> DownloadPackage(string platform, string downloadId)
{
Expand All @@ -70,28 +58,26 @@ public async Task<ActionResult> DownloadPackage(string platform, string download
$"Current Downloads: {downloadingAgents.Count}. Max Allowed: {AppConfig.MaxConcurrentUpdates}", EventType.Debug, null);


byte[] fileBytes;
string filePath;

switch (platform.ToLower())
{
case "win-x64":
filePath = Path.Combine(HostEnv.WebRootPath, "Downloads", "Remotely-Win10-x64.zip");
fileBytes = await System.IO.File.ReadAllBytesAsync(filePath);
break;
case "win-x86":
filePath = Path.Combine(HostEnv.WebRootPath, "Downloads", "Remotely-Win10-x86.zip");
fileBytes = await System.IO.File.ReadAllBytesAsync(filePath);
break;
case "linux":
filePath = Path.Combine(HostEnv.WebRootPath, "Downloads", "Remotely-Linux.zip");
fileBytes = await System.IO.File.ReadAllBytesAsync(filePath);
break;
default:
return BadRequest();
}

return File(fileBytes, "application/octet-stream", "RemotelyUpdate.zip");
var fileStream = System.IO.File.OpenRead(filePath);

return File(fileStream, "application/octet-stream", "RemotelyUpdate.zip");
}
catch (Exception ex)
{
Expand All @@ -100,12 +86,5 @@ public async Task<ActionResult> DownloadPackage(string platform, string download
return StatusCode((int)HttpStatusCode.InternalServerError);
}
}

// TODO: Remove in the next few updates.
[HttpGet("[action]")]
public int UpdateWindow()
{
return DataService.GetDeviceCount() * 10;
}
}
}

0 comments on commit 8d42f5f

Please sign in to comment.