mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
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:
@@ -1275,7 +1275,7 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Route("server/logs/{file?}")]
|
[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)
|
if (offset < 0)
|
||||||
{
|
{
|
||||||
@@ -1317,13 +1317,23 @@ namespace BTCPayServer.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var fileStream = new FileStream(
|
var fileStream = new FileStream(
|
||||||
fi.FullName,
|
fi.FullName,
|
||||||
FileMode.Open,
|
FileMode.Open,
|
||||||
FileAccess.Read,
|
FileAccess.Read,
|
||||||
FileShare.ReadWrite);
|
FileShare.ReadWrite);
|
||||||
using var reader = new StreamReader(fileStream);
|
if (download)
|
||||||
vm.Log = await reader.ReadToEndAsync();
|
{
|
||||||
|
return new FileStreamResult(fileStream, "text/plain")
|
||||||
|
{
|
||||||
|
FileDownloadName = file
|
||||||
|
};
|
||||||
|
}
|
||||||
|
await using (fileStream)
|
||||||
|
{
|
||||||
|
using var reader = new StreamReader(fileStream);
|
||||||
|
vm.Log = await reader.ReadToEndAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,12 @@
|
|||||||
{
|
{
|
||||||
<li>
|
<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">@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>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user