aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Controllers/ApplicationController.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-31 11:15:35 -0600
committerGitHub <noreply@github.com>2021-01-31 11:15:35 -0600
commit36ecf12404338bacf1fdd90334c252f89c897b3e (patch)
tree59772d1c8276bf363c33cd2875f395c9dba1ac5c /src/slskd/Controllers/ApplicationController.cs
parentcec869b9456cf6fe5597847948b2d75b9846755a (diff)
parentc9cd2a67ea65570cbd8bd72f09ff5383b1a5c2fe (diff)
downloadslskd-36ecf12404338bacf1fdd90334c252f89c897b3e.tar.gz
Merge pull request #24 from slskd/config
Add app configuration
Diffstat (limited to 'src/slskd/Controllers/ApplicationController.cs')
-rw-r--r--src/slskd/Controllers/ApplicationController.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/slskd/Controllers/ApplicationController.cs b/src/slskd/Controllers/ApplicationController.cs
new file mode 100644
index 00000000..cc9d56a1
--- /dev/null
+++ b/src/slskd/Controllers/ApplicationController.cs
@@ -0,0 +1,59 @@
+namespace slskd.Controllers
+{
+ using Microsoft.AspNetCore.Authorization;
+ using Microsoft.AspNetCore.Mvc;
+ using System.Diagnostics;
+ using System;
+ using Microsoft.Extensions.Hosting;
+ using Soulseek;
+
+ /// <summary>
+ /// Application
+ /// </summary>
+ [Route("api/v{version:apiVersion}/[controller]")]
+ [ApiVersion("0")]
+ [ApiController]
+ [Produces("application/json")]
+ [Consumes("application/json")]
+ public class ApplicationController : ControllerBase
+ {
+ private ISoulseekClient Client { get; }
+ private IHostApplicationLifetime Lifetime { get; }
+
+ public ApplicationController(ISoulseekClient client, IHostApplicationLifetime lifetime)
+ {
+ Client = client;
+ Lifetime = lifetime;
+ }
+
+ /// <summary>
+ /// Stops the application.
+ /// </summary>
+ /// <returns></returns>
+ [HttpDelete]
+ [Authorize]
+ public IActionResult Shutdown()
+ {
+ Client.Disconnect("Shut down via API");
+
+ Lifetime.StopApplication();
+ return NoContent();
+ }
+
+ /// <summary>
+ /// Restarts the application.
+ /// </summary>
+ /// <returns></returns>
+ [HttpPut]
+ [Authorize]
+ public IActionResult Restart()
+ {
+ Client.Disconnect("Restarted via API");
+
+ Process.Start(Process.GetCurrentProcess().MainModule.FileName, Environment.CommandLine);
+ Lifetime.StopApplication();
+
+ return NoContent();
+ }
+ }
+}