Refactored frontend to work with the latest mooncore changes

This commit is contained in:
2025-07-16 20:46:45 +02:00
parent 383d4bb24b
commit 61253919cf
93 changed files with 3347 additions and 1661 deletions

View File

@@ -13,7 +13,7 @@ using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations;
namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes;
[ApiController]
[Route("api/admin/servers/nodes")]
[Route("api/admin/servers/nodes/{nodeId:int}/allocations")]
public class NodeAllocationsController : Controller
{
private readonly DatabaseRepository<Node> NodeRepository;
@@ -28,7 +28,7 @@ public class NodeAllocationsController : Controller
AllocationRepository = allocationRepository;
}
[HttpGet("{nodeId:int}/allocations")]
[HttpGet("")]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<IPagedData<NodeAllocationResponse>> Get(
[FromRoute] int nodeId,
@@ -59,7 +59,7 @@ public class NodeAllocationsController : Controller
};
}
[HttpGet("{nodeId:int}/allocations/{id:int}")]
[HttpGet("{id:int}")]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<NodeAllocationResponse> GetSingle([FromRoute] int nodeId, [FromRoute] int id)
{
@@ -74,7 +74,7 @@ public class NodeAllocationsController : Controller
return AllocationMapper.ToNodeAllocation(allocation);
}
[HttpPost("{nodeId:int}/allocations")]
[HttpPost("")]
[Authorize(Policy = "permissions:admin.servers.nodes.create")]
public async Task<NodeAllocationResponse> Create(
[FromRoute] int nodeId,
@@ -95,7 +95,7 @@ public class NodeAllocationsController : Controller
return AllocationMapper.ToNodeAllocation(finalAllocation);
}
[HttpPatch("{nodeId:int}/allocations/{id:int}")]
[HttpPatch("{id:int}")]
public async Task<NodeAllocationResponse> Update(
[FromRoute] int nodeId,
[FromRoute] int id,
@@ -116,7 +116,7 @@ public class NodeAllocationsController : Controller
return AllocationMapper.ToNodeAllocation(allocation);
}
[HttpDelete("{nodeId:int}/allocations/{id:int}")]
[HttpDelete("{id:int}")]
public async Task Delete([FromRoute] int nodeId, [FromRoute] int id)
{
var allocation = await AllocationRepository
@@ -130,7 +130,7 @@ public class NodeAllocationsController : Controller
await AllocationRepository.Remove(allocation);
}
[HttpPost("{nodeId:int}/allocations/range")]
[HttpPost("range")]
public async Task CreateRange([FromRoute] int nodeId, [FromBody] CreateNodeAllocationRangeRequest rangeRequest)
{
var node = await NodeRepository
@@ -168,7 +168,7 @@ public class NodeAllocationsController : Controller
await AllocationRepository.RunTransaction(async set => { await set.AddRangeAsync(allocations); });
}
[HttpDelete("{nodeId:int}/allocations/all")]
[HttpDelete("all")]
public async Task DeleteAll([FromRoute] int nodeId)
{
var allocations = AllocationRepository
@@ -179,7 +179,7 @@ public class NodeAllocationsController : Controller
await AllocationRepository.RunTransaction(set => { set.RemoveRange(allocations); });
}
[HttpGet("{nodeId:int}/allocations/free")]
[HttpGet("free")]
[Authorize(Policy = "permissions:admin.servers.nodes.get")]
public async Task<IPagedData<NodeAllocationResponse>> GetFree(
[FromRoute] int nodeId,

View File

@@ -96,7 +96,7 @@ public class NodesController : Controller
if (node == null)
throw new HttpApiException("No node with this id found", 404);
node = NodeMapper.Merge(request, node);
NodeMapper.Merge(request, node);
await NodeRepository.Update(node);
return NodeMapper.ToAdminNodeResponse(node);

View File

@@ -229,7 +229,7 @@ public class ServersController : Controller
if (server == null)
throw new HttpApiException("No server with that id found", 404);
server = ServerMapper.Merge(request, server);
ServerMapper.Merge(request, server);
var allocations = new List<Allocation>();

View File

@@ -135,7 +135,7 @@ public class StarDockerImagesController : Controller
if (dockerImage == null)
throw new HttpApiException("No star docker image with this id found", 404);
dockerImage = DockerImageMapper.Merge(request, dockerImage);
DockerImageMapper.Merge(request, dockerImage);
await DockerImageRepository.Update(dockerImage);
return DockerImageMapper.ToAdminResponse(dockerImage);

View File

@@ -133,7 +133,7 @@ public class StarVariablesController : Controller
if (starVariable == null)
throw new HttpApiException("No variable with this id found", 404);
starVariable = StarVariableMapper.Merge(request, starVariable);
StarVariableMapper.Merge(request, starVariable);
await VariableRepository.Update(starVariable);
return StarVariableMapper.ToAdminResponse(starVariable);

View File

@@ -106,7 +106,7 @@ public class StarsController : Controller
if (star == null)
throw new HttpApiException("No star with that id found", 404);
star = StarMapper.Merge(request, star);
StarMapper.Merge(request, star);
await StarRepository.Update(star);
return StarMapper.ToAdminResponse(star);

View File

@@ -15,7 +15,7 @@ namespace MoonlightServers.ApiServer.Http.Controllers.Client;
[Authorize]
[ApiController]
[Route("api/client/servers")]
[Route("api/client/servers/{serverId:int}/files")]
public class FilesController : Controller
{
private readonly DatabaseRepository<Server> ServerRepository;
@@ -36,7 +36,7 @@ public class FilesController : Controller
AuthorizeService = authorizeService;
}
[HttpGet("{serverId:int}/files/list")]
[HttpGet("list")]
public async Task<ServerFilesEntryResponse[]> List([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionType.Read);
@@ -47,13 +47,13 @@ public class FilesController : Controller
{
Name = x.Name,
Size = x.Size,
IsFile = x.IsFile,
IsFolder = x.IsFolder,
CreatedAt = x.CreatedAt,
UpdatedAt = x.UpdatedAt
}).ToArray();
}
[HttpPost("{serverId:int}/files/move")]
[HttpPost("move")]
public async Task Move([FromRoute] int serverId, [FromQuery] string oldPath, [FromQuery] string newPath)
{
var server = await GetServerById(serverId, ServerPermissionType.ReadWrite);
@@ -61,7 +61,7 @@ public class FilesController : Controller
await ServerFileSystemService.Move(server, oldPath, newPath);
}
[HttpDelete("{serverId:int}/files/delete")]
[HttpDelete("delete")]
public async Task Delete([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionType.ReadWrite);
@@ -69,15 +69,23 @@ public class FilesController : Controller
await ServerFileSystemService.Delete(server, path);
}
[HttpPost("{serverId:int}/files/mkdir")]
[HttpPost("mkdir")]
public async Task Mkdir([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionType.ReadWrite);
await ServerFileSystemService.Mkdir(server, path);
}
[HttpPost("touch")]
public async Task Touch([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionType.ReadWrite);
[HttpGet("{serverId:int}/files/upload")]
await ServerFileSystemService.Mkdir(server, path);
}
[HttpGet("upload")]
public async Task<ServerFilesUploadResponse> Upload([FromRoute] int serverId)
{
var server = await GetServerById(serverId, ServerPermissionType.ReadWrite);
@@ -104,7 +112,7 @@ public class FilesController : Controller
};
}
[HttpGet("{serverId:int}/files/download")]
[HttpGet("download")]
public async Task<ServerFilesDownloadResponse> Download([FromRoute] int serverId, [FromQuery] string path)
{
var server = await GetServerById(serverId, ServerPermissionType.Read);
@@ -132,7 +140,7 @@ public class FilesController : Controller
};
}
[HttpPost("{serverId:int}/files/compress")]
[HttpPost("compress")]
public async Task Compress([FromRoute] int serverId, [FromBody] ServerFilesCompressRequest request)
{
var server = await GetServerById(serverId, ServerPermissionType.ReadWrite);
@@ -143,7 +151,7 @@ public class FilesController : Controller
await ServerFileSystemService.Compress(server, type, request.Items, request.Destination);
}
[HttpPost("{serverId:int}/files/decompress")]
[HttpPost("decompress")]
public async Task Decompress([FromRoute] int serverId, [FromBody] ServerFilesDecompressRequest request)
{
var server = await GetServerById(serverId, ServerPermissionType.ReadWrite);

View File

@@ -10,5 +10,5 @@ public static partial class AllocationMapper
{
public static partial NodeAllocationResponse ToNodeAllocation(Allocation allocation);
public static partial Allocation ToAllocation(CreateNodeAllocationRequest request);
public static partial Allocation Merge(UpdateNodeAllocationRequest request, Allocation allocation);
public static partial void Merge(UpdateNodeAllocationRequest request, Allocation allocation);
}

View File

@@ -10,5 +10,5 @@ public static partial class DockerImageMapper
{
public static partial StarDockerImageDetailResponse ToAdminResponse(StarDockerImage dockerImage);
public static partial StarDockerImage ToDockerImage(CreateStarDockerImageRequest request);
public static partial StarDockerImage Merge(UpdateStarDockerImageRequest request, StarDockerImage variable);
public static partial void Merge(UpdateStarDockerImageRequest request, StarDockerImage variable);
}

View File

@@ -10,5 +10,5 @@ public static partial class NodeMapper
{
public static partial NodeResponse ToAdminNodeResponse(Node node);
public static partial Node ToNode(CreateNodeRequest request);
public static partial Node Merge(UpdateNodeRequest request, Node node);
public static partial void Merge(UpdateNodeRequest request, Node node);
}

View File

@@ -21,5 +21,5 @@ public static partial class ServerMapper
private static partial ServerResponse ToAdminServerResponse_Internal(Server server);
public static partial Server ToServer(CreateServerRequest request);
public static partial Server Merge(UpdateServerRequest request, Server server);
public static partial void Merge(UpdateServerRequest request, Server server);
}

View File

@@ -11,5 +11,5 @@ public static partial class StarMapper
{
public static partial StarDetailResponse ToAdminResponse(Star star);
public static partial Star ToStar(CreateStarRequest request);
public static partial Star Merge(UpdateStarRequest request, Star star);
public static partial void Merge(UpdateStarRequest request, Star star);
}

View File

@@ -10,5 +10,5 @@ public static partial class StarVariableMapper
{
public static partial StarVariableDetailResponse ToAdminResponse(StarVariable variable);
public static partial StarVariable ToStarVariable(CreateStarVariableRequest request);
public static partial StarVariable Merge(UpdateStarVariableRequest request, StarVariable variable);
public static partial void Merge(UpdateStarVariableRequest request, StarVariable variable);
}

View File

@@ -47,4 +47,8 @@
<None Remove="storage\**\*"/>
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Properties\launchSettings.json" />
</ItemGroup>
</Project>

View File

@@ -1,18 +0,0 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Dev Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5269",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"MOONLIGHT_PUBLICURL": "http://localhost:5269",
"HTTP_PROXY": "",
"HTTPS_PROXY": ""
}
}
}
}

View File

@@ -59,6 +59,15 @@ public class ServerFileSystemService
$"api/servers/{server.Id}/files/mkdir?path={path}"
);
}
public async Task Touch(Server server, string path)
{
using var apiClient = await GetApiClient(server);
await apiClient.Post(
$"api/servers/{server.Id}/files/touch?path={path}"
);
}
public async Task Compress(Server server, CompressType type, string[] items, string destination)
{

View File

@@ -35,11 +35,11 @@ public class PluginStartup : IPluginStartup
{
Scripts =
[
"js/XtermBlazor.min.js",
"js/addon-fit.js",
"js/moonlightServers.js"
"/_content/MoonlightServers.Frontend/js/XtermBlazor.min.js",
"/_content/MoonlightServers.Frontend/js/addon-fit.js",
"/_content/MoonlightServers.Frontend/js/moonlightServers.js"
],
Styles = ["css/XtermBlazor.min.css"]
Styles = ["/_content/MoonlightServers.Frontend/css/XtermBlazor.min.css"]
});
}