diff --git a/Moonlight/App/Helpers/Files/HostFileAccess.cs b/Moonlight/App/Helpers/Files/HostFileAccess.cs new file mode 100644 index 00000000..0c425a8b --- /dev/null +++ b/Moonlight/App/Helpers/Files/HostFileAccess.cs @@ -0,0 +1,143 @@ +using System.IO.Compression; + +namespace Moonlight.App.Helpers.Files; + +public class HostFileAccess : FileAccess +{ + private string BasePath; + + public HostFileAccess(string basePath) + { + BasePath = basePath; + } + private string currhp => BasePath.TrimEnd('/') + "/" + CurrentPath.TrimStart('/').TrimEnd('/') + "/"; + public override async Task Ls() + { + var x = new List(); + + foreach (var dir in Directory.GetDirectories(currhp)) + { + x.Add(new() + { + Name = dir.Remove(0, currhp.Length), + Size = 0, + IsFile = false, + }); + } + + foreach (var fn in Directory.GetFiles(currhp)) + { + x.Add(new() + { + Name = fn.Remove(0, currhp.Length), + Size = new FileInfo(fn).Length, + IsFile = true, + }); + } + + return x.ToArray(); + } + + public override Task Cd(string dir) + { + var x = Path.Combine(CurrentPath, dir).Replace("\\", "/") + "/"; + x = x.Replace("//", "/"); + CurrentPath = x; + + return Task.CompletedTask; + } + + public override Task Up() + { + CurrentPath = Path.GetFullPath(Path.Combine(CurrentPath, "..")).Replace("\\", "/").Replace("C:", ""); + return Task.CompletedTask; + } + + public override Task SetDir(string dir) + { + CurrentPath = dir; + return Task.CompletedTask; + } + + public override async Task Read(FileData fileData) + { + return await File.ReadAllTextAsync(currhp + fileData.Name); + } + + public override async Task Write(FileData fileData, string content) + { + await File.WriteAllTextAsync(currhp + fileData.Name, content); + } + + public override async Task Upload(string name, Stream dataStream, Action? progressUpdated = null) + { + var ms = new MemoryStream(); + await dataStream.CopyToAsync(ms); + var data = ms.ToArray(); + ms.Dispose(); + dataStream.Dispose(); + + await File.WriteAllBytesAsync(currhp + name, data); + } + + public override async Task MkDir(string name) + { + Directory.CreateDirectory(currhp + name + "/"); + } + + public override Task Pwd() + { + return Task.FromResult(CurrentPath); + } + + public override Task DownloadUrl(FileData fileData) + { + throw new NotImplementedException(); + } + + public override async Task DownloadStream(FileData fileData) + { + var s = new MemoryStream(8 * 1024 * 1204); //TODO: Add config option + + s.Write(File.ReadAllBytes(currhp + fileData.Name)); + s.Position = 0; + + return s; + } + + public override async Task Delete(FileData fileData) + { + if (fileData.IsFile) + File.Delete(currhp + fileData.Name); + else + Directory.Delete(currhp + fileData.Name); + } + + public override async Task Move(FileData fileData, string newPath) + { + if (fileData.IsFile) + File.Move(currhp + fileData.Name, newPath); + else + Directory.Move(currhp + fileData.Name, newPath); + } + + public override Task Compress(params FileData[] files) + { + throw new NotImplementedException(); + } + + public override Task Decompress(FileData fileData) + { + throw new NotImplementedException(); + } + + public override Task GetLaunchUrl() + { + throw new NotImplementedException(); + } + + public override object Clone() + { + return new HostFileAccess(BasePath); + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Sys/Resources.razor b/Moonlight/Shared/Views/Admin/Sys/Resources.razor index cbb4fd54..28a53119 100644 --- a/Moonlight/Shared/Views/Admin/Sys/Resources.razor +++ b/Moonlight/Shared/Views/Admin/Sys/Resources.razor @@ -1,14 +1,14 @@ @page "/admin/system/resources" -@using Moonlight.Shared.Components.Navigations @using Moonlight.Shared.Components.FileManagerPartials -@using Moonlight.App.Models.Files.Accesses +@using Moonlight.App.Helpers.Files +@using Moonlight.Shared.Components.Navigations
- +
\ No newline at end of file diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index c0ba8c4f..8b2d39c4 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -513,3 +513,8 @@ Error from plesk;Error from plesk Host;Host Username;Username SRV records cannot be updated thanks to the cloudflare api client. Please delete the record and create a new one;SRV records cannot be updated thanks to the cloudflare api client. Please delete the record and create a new one +Hour;Hour +Day;Day +Month;Month +Year;Year +All time;All time