feat: log download button (#6330)

* feat: add download button to logs view

* fix: add using block for `fileStream` if it isnt downloaded
This commit is contained in:
jackstar12
2024-10-27 13:43:47 +01:00
committed by GitHub
parent 9bb1a5b80a
commit 41a2241ae1
2 changed files with 20 additions and 4 deletions

View File

@@ -1275,7 +1275,7 @@ namespace BTCPayServer.Controllers
}
[Route("server/logs/{file?}")]
public async Task<IActionResult> LogsView(string? file = null, int offset = 0)
public async Task<IActionResult> LogsView(string? file = null, int offset = 0, bool download = false)
{
if (offset < 0)
{
@@ -1317,13 +1317,23 @@ namespace BTCPayServer.Controllers
return NotFound();
try
{
using var fileStream = new FileStream(
var fileStream = new FileStream(
fi.FullName,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite);
using var reader = new StreamReader(fileStream);
vm.Log = await reader.ReadToEndAsync();
if (download)
{
return new FileStreamResult(fileStream, "text/plain")
{
FileDownloadName = file
};
}
await using (fileStream)
{
using var reader = new StreamReader(fileStream);
vm.Log = await reader.ReadToEndAsync();
}
}
catch
{