Implemented server console streaming in the frontend with xterm. Added logs endpoint for servers

This commit is contained in:
2024-12-31 17:57:39 +01:00
parent 6d674e153a
commit f652945a3f
19 changed files with 419 additions and 163 deletions

View File

@@ -32,6 +32,20 @@ public class ServersController : Controller
};
}
[HttpGet("{serverId:int}/logs")]
public async Task<ServerLogsResponse> GetLogs([FromRoute] int serverId)
{
var server = ServerService.GetServer(serverId);
if (server == null)
throw new HttpApiException("No server with this id found", 404);
return new ServerLogsResponse()
{
Messages = server.Console.Messages
};
}
[HttpPost("{serverId:int}/start")]
public async Task Start(int serverId)
{

View File

@@ -17,12 +17,24 @@ public class ServerConsoleHub : Hub
ConsoleService = consoleService;
}
#region Connection Handlers
public override async Task OnConnectedAsync()
=> await ConsoleService.InitializeClient(Context);
public override async Task OnDisconnectedAsync(Exception? exception)
=> await ConsoleService.DestroyClient(Context);
#endregion
#region Methods
[HubMethodName("Authenticate")]
public async Task Authenticate(string accessToken)
{
try
{
await ConsoleService.Authenticate(Context, accessToken);
await ConsoleService.AuthenticateClient(Context, accessToken);
}
catch (Exception e)
{
@@ -30,6 +42,5 @@ public class ServerConsoleHub : Hub
}
}
public override async Task OnDisconnectedAsync(Exception? exception)
=> await ConsoleService.OnClientDisconnected(Context);
#endregion
}