aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/API
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-08-23 02:19:36 -0500
committerJP Dillingham <jp@dillingham.me>2026-08-23 02:19:36 -0500
commit91ad4826bbd0d89f69276ea0789e1498f2a92801 (patch)
treec447684a0e340c15869798c9ed5223d74b07d5be /src/slskd/Core/API
parent1f6c6b1bf962dd03c66f55098704530bb5c4620a (diff)
downloadslskd-91ad4826bbd0d89f69276ea0789e1498f2a92801.tar.gz
stub endpoints to list and read log files
Diffstat (limited to 'src/slskd/Core/API')
-rw-r--r--src/slskd/Core/API/Controllers/LogsController.cs59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/slskd/Core/API/Controllers/LogsController.cs b/src/slskd/Core/API/Controllers/LogsController.cs
index 8055c696..a12d9187 100644
--- a/src/slskd/Core/API/Controllers/LogsController.cs
+++ b/src/slskd/Core/API/Controllers/LogsController.cs
@@ -32,9 +32,14 @@
namespace slskd.Core.API
{
+ using System;
+ using System.IO;
+ using System.Threading.Tasks;
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+ using Serilog;
+ using slskd.Files;
/// <summary>
/// Logs.
@@ -46,15 +51,67 @@ namespace slskd.Core.API
[Consumes("application/json")]
public class LogsController : ControllerBase
{
+ public LogsController(
+ FileService fileService,
+ OptionsAtStartup optionsAtStartup)
+ {
+ Files = fileService;
+ OptionsAtStartup = optionsAtStartup;
+ }
+
+ private FileService Files { get; }
+ private OptionsAtStartup OptionsAtStartup { get; }
+ private ILogger Log { get; } = Serilog.Log.ForContext<ApplicationController>();
+
/// <summary>
/// Gets the last few application logs.
/// </summary>
/// <returns></returns>
- [HttpGet]
+ [HttpGet("buffer")]
[Authorize(Policy = AuthPolicy.Any)]
public IActionResult Logs()
{
return Ok(Program.LogBuffer);
}
+
+ [HttpGet]
+ [Authorize(Policy = AuthPolicy.Any)]
+ public async Task<IActionResult> List()
+ {
+ var directory = await Files.ListDirectoryContentsAsync(System.IO.Path.GetFullPath(Program.LogDirectory), enumerationOptions: new EnumerationOptions
+ {
+ AttributesToSkip = FileAttributes.System,
+ RecurseSubdirectories = false,
+ });
+
+ return Ok(directory.Files);
+ }
+
+ [HttpGet("{filename}")]
+ [Authorize(Policy = AuthPolicy.Any)]
+ public async Task<IActionResult> Get(string filename, [FromQuery] bool download = false)
+ {
+ filename = FileSafety.GetFileNameSafely(filename);
+
+ try
+ {
+ var stream = Files.GetFileContents(FileSafety.CombineSafely(Program.LogDirectory, filename));
+
+ if (download)
+ {
+ return File(stream, "text/plain", filename);
+ }
+
+ return File(stream, "text/plain");
+ }
+ catch (UnauthorizedException)
+ {
+ return NotFound();
+ }
+ catch (NotFoundException)
+ {
+ return NotFound();
+ }
+ }
}
}