Implemented system files tab

This commit is contained in:
2025-02-06 10:56:49 +01:00
parent 2e5d0dcd73
commit 480d118014
8 changed files with 552 additions and 2 deletions

View File

@@ -0,0 +1,83 @@
using MoonCore.Blazor.Tailwind.Fm;
using MoonCore.Blazor.Tailwind.Fm.Models;
using MoonCore.Helpers;
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
using Moonlight.Shared.Http.Responses.Admin.Sys.Files;
namespace Moonlight.Client.Implementations;
public class SysFileSystemProvider : IFileSystemProvider, ICompressFileSystemProvider
{
private readonly HttpApiClient HttpApiClient;
private readonly string BaseApiUrl = "api/admin/system/files";
public CompressType[] CompressTypes { get; } =
[
new()
{
Extension = "zip",
DisplayName = "ZIP Archive"
},
new()
{
Extension = "tar.gz",
DisplayName = "GZ Compressed Tar Archive"
}
];
public SysFileSystemProvider(HttpApiClient httpApiClient)
{
HttpApiClient = httpApiClient;
}
public async Task<FileSystemEntry[]> List(string path)
{
var entries = await HttpApiClient.GetJson<FileSystemEntryResponse[]>(
$"{BaseApiUrl}/list?path={path}"
);
return entries.Select(x => new FileSystemEntry()
{
Name = x.Name,
Size = x.Size,
CreatedAt = x.CreatedAt,
IsFile = x.IsFile,
UpdatedAt = x.UpdatedAt
}).ToArray();
}
public async Task Create(string path, Stream stream)
=> await HttpApiClient.PostStream($"{BaseApiUrl}/create?path={path}", stream);
public async Task Move(string oldPath, string newPath)
=> await HttpApiClient.Post($"{BaseApiUrl}/move?oldPath={oldPath}&newPath={newPath}");
public async Task Delete(string path)
=> await HttpApiClient.Delete($"{BaseApiUrl}/delete?path={path}");
public async Task CreateDirectory(string path)
=> await HttpApiClient.Post($"{BaseApiUrl}/mkdir?path={path}");
public async Task<Stream> Read(string path)
=> await HttpApiClient.GetStream($"{BaseApiUrl}/read?path={path}");
public async Task Compress(CompressType type, string path, string[] itemsToCompress)
{
await HttpApiClient.Post($"{BaseApiUrl}/compress", new CompressRequest()
{
Type = type.Extension,
Path = path,
ItemsToCompress = itemsToCompress
});
}
public async Task Decompress(CompressType type, string path, string destination)
{
await HttpApiClient.Post($"{BaseApiUrl}/decompress", new DecompressRequest()
{
Type = type.Extension,
Path = path,
Destination = destination
});
}
}

View File

@@ -0,0 +1,26 @@
@page "/admin/system/files"
@using MoonCore.Attributes
@using MoonCore.Helpers
@using MoonCore.Blazor.Tailwind.Fm
@using Moonlight.Client.Implementations
@attribute [RequirePermission("admin.system.overview")]
@inject HttpApiClient ApiClient
<div class="mb-3">
<NavTabs Index="2" Names="UiConstants.AdminNavNames" Links="UiConstants.AdminNavLinks" />
</div>
<FileManager FileSystemProvider="FileSystemProvider" />
@code
{
private IFileSystemProvider FileSystemProvider;
protected override void OnInitialized()
{
FileSystemProvider = new SysFileSystemProvider(ApiClient);
}
}

View File

@@ -2,6 +2,6 @@ namespace Moonlight.Client;
public static class UiConstants
{
public static readonly string[] AdminNavNames = ["Overview", "Theme"];
public static readonly string[] AdminNavLinks = ["/admin/system", "/admin/system/theme"];
public static readonly string[] AdminNavNames = ["Overview", "Theme", "Files"];
public static readonly string[] AdminNavLinks = ["/admin/system", "/admin/system/theme", "/admin/system/files"];
}