Merge pull request #52 from Moonlight-Panel/ResourcesFileManager
host file access + use in admin resource manager
This commit is contained in:
143
Moonlight/App/Helpers/Files/HostFileAccess.cs
Normal file
143
Moonlight/App/Helpers/Files/HostFileAccess.cs
Normal file
@@ -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<FileData[]> Ls()
|
||||||
|
{
|
||||||
|
var x = new List<FileData>();
|
||||||
|
|
||||||
|
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<string> 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<int>? 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<string> Pwd()
|
||||||
|
{
|
||||||
|
return Task.FromResult(CurrentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<string> DownloadUrl(FileData fileData)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Stream> 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<string> GetLaunchUrl()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
return new HostFileAccess(BasePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
@page "/admin/system/resources"
|
@page "/admin/system/resources"
|
||||||
|
|
||||||
@using Moonlight.Shared.Components.Navigations
|
|
||||||
@using Moonlight.Shared.Components.FileManagerPartials
|
@using Moonlight.Shared.Components.FileManagerPartials
|
||||||
@using Moonlight.App.Models.Files.Accesses
|
@using Moonlight.App.Helpers.Files
|
||||||
|
@using Moonlight.Shared.Components.Navigations
|
||||||
|
|
||||||
<OnlyAdmin>
|
<OnlyAdmin>
|
||||||
<AdminSystemNavigation Index="5" />
|
<AdminSystemNavigation Index="5" />
|
||||||
|
|
||||||
<div class="card card-body">
|
<div class="card card-body">
|
||||||
<FileManager FileAccess="@(new HostFileAccess("resources"))">
|
<FileManager Access="@(new HostFileAccess("resources"))">
|
||||||
</FileManager>
|
</FileManager>
|
||||||
</div>
|
</div>
|
||||||
</OnlyAdmin>
|
</OnlyAdmin>
|
||||||
@@ -512,9 +512,9 @@ The name should only contain of lower case characters and numbers;The name shoul
|
|||||||
Error from plesk;Error from plesk
|
Error from plesk;Error from plesk
|
||||||
Host;Host
|
Host;Host
|
||||||
Username;Username
|
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
|
Hour;Hour
|
||||||
Day;Day
|
Day;Day
|
||||||
Month;Month
|
Month;Month
|
||||||
Year;Year
|
Year;Year
|
||||||
All time;All time
|
All time;All time
|
||||||
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
|
|
||||||
Reference in New Issue
Block a user