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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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
{

View File

@ -13,6 +13,12 @@
{
<li>
<a asp-action="LogsView" asp-route-file="@file.Name" asp-route-offset="@Model.LogFileOffset">@file.Name</a>
<a asp-action="LogsView" asp-route-file="@file.Name" asp-route-offset="@Model.LogFileOffset" asp-route-download="true" class="mx-2">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
<path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"/>
<path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z"/>
</svg>
</a>
</li>
}
</ul>