Implemented basic server file system endpoints and services. Implemented server files tab

This commit is contained in:
2025-03-03 18:07:49 +01:00
parent 30390dab71
commit 43b04ff630
21 changed files with 735 additions and 86 deletions

View File

@@ -0,0 +1,60 @@
using MoonCore.Blazor.Tailwind.Fm;
using MoonlightServers.Frontend.Services;
namespace MoonlightServers.Frontend.Helpers;
public class ServerFileSystemProvider : IFileSystemProvider
{
private readonly int ServerId;
private readonly ServerFileSystemService FileSystemService;
public ServerFileSystemProvider(
int serverId,
ServerFileSystemService fileSystemService
)
{
ServerId = serverId;
FileSystemService = fileSystemService;
}
public async Task<FileSystemEntry[]> List(string path)
{
var result = await FileSystemService.List(ServerId, path);
return result
.Select(x => new FileSystemEntry()
{
Name = x.Name,
Size = x.Size,
IsFile = x.IsFile,
CreatedAt = x.CreatedAt,
UpdatedAt = x.UpdatedAt
})
.ToArray();
}
public async Task Create(string path, Stream stream)
{
await FileSystemService.Upload(ServerId, path, stream);
}
public async Task Move(string oldPath, string newPath)
{
await FileSystemService.Move(ServerId, oldPath, newPath);
}
public async Task Delete(string path)
{
await FileSystemService.Delete(ServerId, path);
}
public async Task CreateDirectory(string path)
{
await FileSystemService.Mkdir(ServerId, path);
}
public Task<Stream> Read(string path)
{
throw new NotImplementedException();
}
}

View File

@@ -19,10 +19,6 @@
<_ContentIncludedByDefault Remove="Pages\Home.razor"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Helpers\"/>
</ItemGroup>
<ItemGroup>
<None Remove="Properties\launchSettings.json"/>
</ItemGroup>

View File

@@ -0,0 +1,58 @@
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Files;
namespace MoonlightServers.Frontend.Services;
[Scoped]
public class ServerFileSystemService
{
private readonly HttpApiClient ApiClient;
public ServerFileSystemService(HttpApiClient apiClient)
{
ApiClient = apiClient;
}
public async Task<ServerFilesEntryResponse[]> List(int serverId, string path)
{
return await ApiClient.GetJson<ServerFilesEntryResponse[]>(
$"api/client/servers/{serverId}/files/list?path={path}"
);
}
public async Task Move(int serverId, string oldPath, string newPath)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/move?oldPath={oldPath}&newPath={newPath}"
);
}
public async Task Delete(int serverId, string path)
{
await ApiClient.Delete(
$"api/client/servers/{serverId}/files/delete?path={path}"
);
}
public async Task Mkdir(int serverId, string path)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/mkdir?path={path}"
);
}
public async Task Upload(int serverId, string path, Stream dataStream)
{
var uploadSession = await ApiClient.GetJson<ServerFilesUploadResponse>(
$"api/client/servers/{serverId}/files/upload?path={path}"
);
using var httpClient = new HttpClient();
var content = new MultipartFormDataContent();
content.Add(new StreamContent(dataStream), "file", path);
await httpClient.PostAsync(uploadSession.UploadUrl, content);
}
}

View File

@@ -1,6 +1,19 @@
@using MoonlightServers.Frontend.Services
@using MoonCore.Blazor.Tailwind.Fm
@using MoonlightServers.Frontend.Helpers
@inherits BaseServerTab
@inject ServerFileSystemService FileSystemService
<FileManager FileSystemProvider="Provider" />
@code
{
private IFileSystemProvider Provider;
protected override void OnInitialized()
{
Provider = new ServerFileSystemProvider(Server.Id, FileSystemService);
}
}