aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/API/Controllers
diff options
context:
space:
mode:
authorLev Gorodetskiy <github@droserasprout.space>2022-09-02 17:50:01 -0300
committerLev Gorodetskiy <github@droserasprout.space>2022-09-02 17:50:01 -0300
commit200bddf616946ab625d31564fc931f48915702e3 (patch)
tree7d720573ff244352c2aee09135cc4b7751e8a495 /src/slskd/Core/API/Controllers
parent3c4ce3c0ee5a178dd14fab06575acca39a36c6b2 (diff)
parentb2611b3e94b11853f576cffce371f9ed264d4841 (diff)
downloadslskd-200bddf616946ab625d31564fc931f48915702e3.tar.gz
Merge branch 'master' into aux/docs-proofreading
Diffstat (limited to 'src/slskd/Core/API/Controllers')
-rw-r--r--src/slskd/Core/API/Controllers/ApplicationController.cs15
-rw-r--r--src/slskd/Core/API/Controllers/MetricsController.cs46
-rw-r--r--src/slskd/Core/API/Controllers/OptionsController.cs20
3 files changed, 71 insertions, 10 deletions
diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs
index cd03d96f..ac8be802 100644
--- a/src/slskd/Core/API/Controllers/ApplicationController.cs
+++ b/src/slskd/Core/API/Controllers/ApplicationController.cs
@@ -137,19 +137,14 @@ namespace slskd.Core.API
return Ok();
}
- [HttpPut]
- [Route("shares")]
+ [HttpGet("dump")]
[Authorize]
- public IActionResult RescanSharesAsync()
+ public async Task<IActionResult> DumpMemory()
{
- if (ApplicationStateMonitor.CurrentValue.SharedFileCache.Filling)
- {
- return Conflict("A share scan is already in progress.");
- }
+ using var dumper = new Dumper();
+ var file = await dumper.DumpAsync();
- _ = Application.RescanSharesAsync();
-
- return Ok();
+ return PhysicalFile(file, "application/octet-stream", "slskd.dmp");
}
}
}
diff --git a/src/slskd/Core/API/Controllers/MetricsController.cs b/src/slskd/Core/API/Controllers/MetricsController.cs
new file mode 100644
index 00000000..da2707c1
--- /dev/null
+++ b/src/slskd/Core/API/Controllers/MetricsController.cs
@@ -0,0 +1,46 @@
+// <copyright file="MetricsController.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+namespace slskd.Core.API
+{
+ using System.Threading.Tasks;
+ using Microsoft.AspNetCore.Authorization;
+ using Microsoft.AspNetCore.Mvc;
+
+ /// <summary>
+ /// Logs.
+ /// </summary>
+ [Route("api/v{version:apiVersion}/[controller]")]
+ [ApiVersion("0")]
+ [ApiController]
+ [Produces("text/plain")]
+ [Consumes("text/plain")]
+ public class MetricsController : ControllerBase
+ {
+ /// <summary>
+ /// Gets application metrics.
+ /// </summary>
+ /// <returns></returns>
+ [HttpGet]
+ [Authorize]
+ public async Task<IActionResult> Get()
+ {
+ var response = await Metrics.BuildAsync();
+ return Content(response, "text/plain");
+ }
+ }
+}
diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs
index 062de8f7..b0856ed3 100644
--- a/src/slskd/Core/API/Controllers/OptionsController.cs
+++ b/src/slskd/Core/API/Controllers/OptionsController.cs
@@ -21,8 +21,10 @@ namespace slskd.Core.API
{
using System;
using System.IO;
+ using System.Reflection;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+ using Microsoft.Extensions.Configuration;
using Serilog;
using slskd.Validation;
using IOFile = System.IO.File;
@@ -74,6 +76,24 @@ namespace slskd.Core.API
return Ok(OptionsAtStartup.Redact());
}
+ /// <summary>
+ /// Gets the debug view of the current application options.
+ /// </summary>
+ /// <returns></returns>
+ [HttpGet]
+ [Route("debug")]
+ [Authorize]
+ [ProducesResponseType(typeof(string), 200)]
+ public IActionResult Debug()
+ {
+ // retrieve the IConfigurationRoot instance with reflection to avoid
+ // exposing it as a public member of Program.
+ var property = typeof(Program).GetProperty("Configuration", BindingFlags.NonPublic | BindingFlags.Static);
+ var configurationRoot = (IConfigurationRoot)property.GetValue(null, null);
+
+ return Ok(configurationRoot.GetDebugView());
+ }
+
[HttpGet]
[Authorize]
[Route("yaml/location")]