Implemented power state and task streaming over signalr
This commit is contained in:
@@ -118,6 +118,36 @@ public class ServersController : Controller
|
||||
throw new HttpApiException("Unable to access the node the server is running on", 502);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{serverId:int}/console")]
|
||||
[RequirePermission("meta.authenticated")]
|
||||
public async Task<ServerConsoleResponse> GetConsole([FromRoute] int serverId)
|
||||
{
|
||||
var server = await GetServerWithPermCheck(serverId);
|
||||
|
||||
// TODO: Handle transparent proxy
|
||||
|
||||
var accessToken = NodeService.CreateAccessToken(server.Node, parameters =>
|
||||
{
|
||||
parameters.Add("type", "console");
|
||||
parameters.Add("serverId", server.Id);
|
||||
}, TimeSpan.FromMinutes(10));
|
||||
|
||||
var url = "";
|
||||
|
||||
if (server.Node.UseSsl)
|
||||
url += "https://";
|
||||
else
|
||||
url += "http://";
|
||||
|
||||
url += $"{server.Node.Fqdn}:{server.Node.HttpPort}/api/servers/console";
|
||||
|
||||
return new ServerConsoleResponse()
|
||||
{
|
||||
Target = url,
|
||||
AccessToken = accessToken
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<Server> GetServerWithPermCheck(int serverId,
|
||||
Func<IQueryable<Server>, IQueryable<Server>>? queryModifier = null)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.Helpers;
|
||||
using MoonCore.Helpers;
|
||||
using MoonlightServers.ApiServer.Database.Entities;
|
||||
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Statistics;
|
||||
@@ -11,7 +12,7 @@ public class NodeService
|
||||
{
|
||||
public async Task<HttpApiClient> CreateApiClient(Node node)
|
||||
{
|
||||
string url = "";
|
||||
var url = "";
|
||||
|
||||
if (node.UseSsl)
|
||||
url += "https://";
|
||||
@@ -29,6 +30,9 @@ public class NodeService
|
||||
|
||||
return new HttpApiClient(httpClient);
|
||||
}
|
||||
|
||||
public string CreateAccessToken(Node node, Action<Dictionary<string, object>> parameters, TimeSpan duration)
|
||||
=> JwtHelper.Encode(node.Token, parameters, duration);
|
||||
|
||||
public async Task<SystemStatusResponse> GetSystemStatus(Node node)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user