Started with adding modules for archiving for the file manager
This commit is contained in:
parent
0234a8e179
commit
b4251a0f1f
6 changed files with 52 additions and 16 deletions
|
@ -0,0 +1,38 @@
|
|||
using MoonCore.Exceptions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCoreUI.Services;
|
||||
using Moonlight.Features.FileManager.Interfaces;
|
||||
using Moonlight.Features.FileManager.Models.Abstractions.FileAccess;
|
||||
|
||||
namespace Moonlight.Features.FileManager.Implementations;
|
||||
|
||||
public class ArchiveSelectionAction : IFileManagerSelectionAction
|
||||
{
|
||||
public string Name => "Archive";
|
||||
public string Color => "primary";
|
||||
|
||||
public async Task Execute(BaseFileAccess access, UI.Components.FileManager fileManager, FileEntry[] entries,
|
||||
IServiceProvider provider)
|
||||
{
|
||||
if (!access.Actions.GetType().IsAssignableFrom(typeof(IArchiveFileActions)))
|
||||
throw new DisplayException("This file access does not support archiving");
|
||||
|
||||
var archiveAccess = access as IArchiveFileActions;
|
||||
|
||||
if (archiveAccess == null)
|
||||
throw new DisplayException("This file access does not support archiving");
|
||||
|
||||
var alertService = provider.GetRequiredService<AlertService>();
|
||||
|
||||
var fileName = await alertService.Text("Enter the archive file name", "",
|
||||
Formatter.FormatDate(DateTime.UtcNow) + ".tar.gz");
|
||||
|
||||
if (string.IsNullOrEmpty(fileName) || fileName.Contains("..")) // => canceled
|
||||
return;
|
||||
|
||||
await archiveAccess.Archive(
|
||||
access.CurrentDirectory + fileName,
|
||||
entries.Select(x => access.CurrentDirectory + x.Name).ToArray()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@ namespace Moonlight.Features.FileManager.Models.Abstractions.FileAccess;
|
|||
|
||||
public class BaseFileAccess : IDisposable
|
||||
{
|
||||
private readonly IFileActions Actions;
|
||||
public readonly IFileActions Actions;
|
||||
|
||||
private string CurrentDirectory = "/";
|
||||
public string CurrentDirectory { get; private set; } = "/";
|
||||
|
||||
public BaseFileAccess(IFileActions actions)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
namespace Moonlight.Features.FileManager.Models.Abstractions.FileAccess;
|
||||
|
||||
public interface IArchiveFileActions
|
||||
{
|
||||
public Task Archive(string path, string[] files);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
namespace Moonlight.Features.FileManager.Models.Abstractions.FileAccess;
|
||||
|
||||
public interface IFileCompressAccess
|
||||
{
|
||||
public Task Compress(string[] names);
|
||||
public Task Decompress(string name);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
namespace Moonlight.Features.FileManager.Models.Abstractions.FileAccess;
|
||||
|
||||
public interface IFileLaunchAccess
|
||||
{
|
||||
public Task<string> GetLaunchUrl();
|
||||
}
|
|
@ -4,7 +4,7 @@ using Moonlight.Features.Servers.Exceptions;
|
|||
|
||||
namespace Moonlight.Features.Servers.Helpers;
|
||||
|
||||
public class ServerApiFileActions : IFileActions
|
||||
public class ServerApiFileActions : IFileActions, IArchiveFileActions
|
||||
{
|
||||
private readonly string Endpoint;
|
||||
private readonly string Token;
|
||||
|
@ -43,6 +43,11 @@ public class ServerApiFileActions : IFileActions
|
|||
public async Task WriteFileStream(string path, Stream dataStream) =>
|
||||
await ApiClient.PostFile($"writeFileStream?path={path}", dataStream, "upload");
|
||||
|
||||
public async Task Archive(string path, string[] files)
|
||||
{
|
||||
await ApiClient.Post($"archive?path={path}&provider=tar.gz", files);
|
||||
}
|
||||
|
||||
public IFileActions Clone() => new ServerApiFileActions(Endpoint, Token, ServerId);
|
||||
|
||||
public void Dispose() => ApiClient.Dispose();
|
||||
|
|
Loading…
Reference in a new issue