diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-08-23 19:10:36 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-08-23 19:10:36 -0500 |
| commit | 3b2d0c62f410a4db800055b831bf37c1e512c1b7 (patch) | |
| tree | 444497e0a124bd8a2bef78adb7bed5477d848721 /src/slskd/Core/API/Controllers/LogsController.cs | |
| parent | bb25e7accb1e47bfea4ddbb998106ad7365a88a6 (diff) | |
| download | slskd-3b2d0c62f410a4db800055b831bf37c1e512c1b7.tar.gz | |
wip of log zip
Diffstat (limited to 'src/slskd/Core/API/Controllers/LogsController.cs')
| -rw-r--r-- | src/slskd/Core/API/Controllers/LogsController.cs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/slskd/Core/API/Controllers/LogsController.cs b/src/slskd/Core/API/Controllers/LogsController.cs index 43300e63..569848b2 100644 --- a/src/slskd/Core/API/Controllers/LogsController.cs +++ b/src/slskd/Core/API/Controllers/LogsController.cs @@ -33,7 +33,10 @@ namespace slskd.Core.API { using System; + using System.Collections.Generic; using System.IO; + using System.IO.Compression; + using System.Threading; using System.Threading.Tasks; using Asp.Versioning; using Microsoft.AspNetCore.Authorization; @@ -77,7 +80,7 @@ namespace slskd.Core.API /// <returns></returns> [HttpGet("files")] [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] - public async Task<IActionResult> List() + public async Task<IActionResult> List(CancellationToken cancellationToken, [FromQuery] bool download = false) { var directory = await Files.ListDirectoryContentsAsync(System.IO.Path.GetFullPath(Program.LogDirectory), enumerationOptions: new EnumerationOptions { @@ -85,6 +88,16 @@ namespace slskd.Core.API RecurseSubdirectories = false, }); + if (download) + { + var stream = new MemoryStream(); + await ZipFile.CreateFromDirectoryAsync(Program.LogDirectory, stream, cancellationToken: cancellationToken); + + var now = DateTime.UtcNow; + + return File(stream, "application/zip", $"logs-{now:yyyyMMdd}-{new DateTimeOffset(now).ToUnixTimeMilliseconds}.zip"); + } + return Ok(directory.Files); } |
