Refactored frontend to work with the latest mooncore changes
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user