Refactored ui. Improved console experience. Added command endpoint

This commit is contained in:
2025-07-18 21:16:52 +02:00
parent f8c11b2dd8
commit 265a4b280b
43 changed files with 479 additions and 149 deletions

View File

@@ -68,6 +68,7 @@ public class ServersController : Controller
.Include(x => x.Star)
.Skip(page * pageSize)
.Take(pageSize)
.OrderBy(x => x.Id)
.ToArrayAsync();
var mappedItems = items
@@ -213,7 +214,7 @@ public class ServersController : Controller
}
[HttpPatch("{id:int}")]
[Authorize(Policy = "permissions.admin.servers.write")]
[Authorize(Policy = "permissions:admin.servers.write")]
public async Task<ServerResponse> Update([FromRoute] int id, [FromBody] UpdateServerRequest request)
{
//TODO: Handle shrinking virtual disk
@@ -294,11 +295,16 @@ public class ServersController : Controller
.Include(x => x.Star)
.Include(x => x.Variables)
.Include(x => x.Backups)
.Include(x => x.Allocations)
.FirstOrDefaultAsync(x => x.Id == id);
if (server == null)
throw new HttpApiException("No server with that id found", 404);
server.Variables.Clear();
server.Backups.Clear();
server.Allocations.Clear();
try
{
// If the sync fails on the node and we aren't forcing the deletion,

View File

@@ -11,6 +11,7 @@ using MoonlightServers.ApiServer.Extensions;
using MoonlightServers.ApiServer.Models;
using MoonlightServers.ApiServer.Services;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Http.Requests.Client.Servers;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Allocations;
using MoonlightServers.Shared.Models;
@@ -293,6 +294,17 @@ public class ServersController : Controller
};
}
[HttpPost("{serverId:int}/command")]
public async Task RunCommand([FromRoute] int serverId, [FromBody] ServerCommandRequest request)
{
var server = await GetServerById(
serverId,
permission => permission is { Name: "console", Type: >= ServerPermissionType.ReadWrite }
);
await ServerService.RunCommand(server, request.Command);
}
private async Task<Server> GetServerById(int serverId, Func<ServerSharePermission, bool>? filter = null)
{
var server = await ServerRepository