Refactored frontend to work with the latest mooncore changes
This commit is contained in:
@@ -30,12 +30,12 @@ public class ServerFileSystem
|
||||
// to hide the folder shown by virtual disk volumes
|
||||
if (string.IsNullOrEmpty(inputPath) || inputPath == "/")
|
||||
entryQuery = entryQuery.Where(x => x.Name != "lost+found");
|
||||
|
||||
|
||||
var result = entryQuery
|
||||
.Select(x => new ServerFileSystemResponse()
|
||||
{
|
||||
Name = x.Name,
|
||||
IsFile = x.IsFile,
|
||||
IsFolder = x.IsDirectory,
|
||||
Size = x.Size,
|
||||
UpdatedAt = x.LastChanged,
|
||||
CreatedAt = x.CreatedAt
|
||||
@@ -73,6 +73,24 @@ public class ServerFileSystem
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Touch(string inputPath)
|
||||
{
|
||||
var path = Normalize(inputPath);
|
||||
|
||||
var parentDirectory = Path.GetDirectoryName(path);
|
||||
|
||||
if (!string.IsNullOrEmpty(parentDirectory) && parentDirectory != "/")
|
||||
FileSystem.MkdirAll(parentDirectory, FilePermissions.ACCESSPERMS);
|
||||
|
||||
FileSystem.OpenFileWrite(
|
||||
path,
|
||||
_ => { },
|
||||
OpenFlags.O_CREAT
|
||||
); // We use these custom flags to ensure we aren't overwriting the file
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task CreateChunk(string inputPath, long totalSize, long positionToSkip, Stream chunkStream)
|
||||
{
|
||||
var path = Normalize(inputPath);
|
||||
@@ -81,14 +99,14 @@ public class ServerFileSystem
|
||||
|
||||
if (!string.IsNullOrEmpty(parentDirectory) && parentDirectory != "/")
|
||||
FileSystem.MkdirAll(parentDirectory, FilePermissions.ACCESSPERMS);
|
||||
|
||||
|
||||
FileSystem.OpenFileWrite(path, fileStream =>
|
||||
{
|
||||
if (fileStream.Length != totalSize)
|
||||
fileStream.SetLength(totalSize);
|
||||
|
||||
fileStream.Position = positionToSkip;
|
||||
|
||||
|
||||
chunkStream.CopyTo(fileStream);
|
||||
fileStream.Flush();
|
||||
}, OpenFlags.O_CREAT | OpenFlags.O_RDWR); // We use these custom flags to ensure we aren't overwriting the file
|
||||
@@ -183,7 +201,7 @@ public class ServerFileSystem
|
||||
FileSystem.OpenFileRead(path, fileStream =>
|
||||
{
|
||||
var zipInputStream = new ZipInputStream(fileStream);
|
||||
|
||||
|
||||
ExtractZip(zipInputStream, destination);
|
||||
});
|
||||
}
|
||||
@@ -193,11 +211,11 @@ public class ServerFileSystem
|
||||
{
|
||||
var gzInputStream = new GZipInputStream(fileStream);
|
||||
var zipInputStream = new TarInputStream(gzInputStream, Encoding.UTF8);
|
||||
|
||||
|
||||
ExtractTar(zipInputStream, destination);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -259,10 +277,7 @@ public class ServerFileSystem
|
||||
|
||||
outputStream.PutNextEntry(entry);
|
||||
|
||||
FileSystem.OpenFileRead(path, stream =>
|
||||
{
|
||||
stream.CopyTo(outputStream);
|
||||
});
|
||||
FileSystem.OpenFileRead(path, stream => { stream.CopyTo(outputStream); });
|
||||
|
||||
outputStream.CloseEntry();
|
||||
}
|
||||
@@ -273,54 +288,54 @@ public class ServerFileSystem
|
||||
while (true)
|
||||
{
|
||||
var entry = inputStream.GetNextEntry();
|
||||
|
||||
if(entry == null)
|
||||
|
||||
if (entry == null)
|
||||
break;
|
||||
|
||||
if(entry.IsDirectory)
|
||||
|
||||
if (entry.IsDirectory)
|
||||
continue;
|
||||
|
||||
var fileDestination = Path.Combine(destination, entry.Name);
|
||||
|
||||
|
||||
var parentDirectory = Path.GetDirectoryName(fileDestination);
|
||||
|
||||
if (!string.IsNullOrEmpty(parentDirectory) && parentDirectory != "/")
|
||||
FileSystem.MkdirAll(parentDirectory, FilePermissions.ACCESSPERMS);
|
||||
|
||||
|
||||
FileSystem.OpenFileWrite(fileDestination, stream =>
|
||||
{
|
||||
stream.Position = 0;
|
||||
|
||||
|
||||
inputStream.CopyTo(stream);
|
||||
|
||||
stream.Flush();
|
||||
}); // This will override the file if it exists
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ExtractTar(TarInputStream inputStream, string destination)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var entry = inputStream.GetNextEntry();
|
||||
|
||||
if(entry == null)
|
||||
|
||||
if (entry == null)
|
||||
break;
|
||||
|
||||
if(entry.IsDirectory)
|
||||
|
||||
if (entry.IsDirectory)
|
||||
continue;
|
||||
|
||||
var fileDestination = Path.Combine(destination, entry.Name);
|
||||
|
||||
|
||||
var parentDirectory = Path.GetDirectoryName(fileDestination);
|
||||
|
||||
if (!string.IsNullOrEmpty(parentDirectory) && parentDirectory != "/")
|
||||
FileSystem.MkdirAll(parentDirectory, FilePermissions.ACCESSPERMS);
|
||||
|
||||
|
||||
FileSystem.OpenFileWrite(fileDestination, stream =>
|
||||
{
|
||||
stream.Position = 0;
|
||||
|
||||
|
||||
inputStream.CopyTo(stream);
|
||||
|
||||
stream.Flush();
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace MoonlightServers.Daemon.Http.Controllers.Servers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/servers")]
|
||||
[Route("api/servers/{id:int}/files")]
|
||||
public class ServerFileSystemController : Controller
|
||||
{
|
||||
private readonly ServerService ServerService;
|
||||
@@ -21,7 +21,7 @@ public class ServerFileSystemController : Controller
|
||||
ServerService = serverService;
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}/files/list")]
|
||||
[HttpGet("list")]
|
||||
public async Task<ServerFileSystemResponse[]> List([FromRoute] int id, [FromQuery] string path = "")
|
||||
{
|
||||
var fileSystem = await GetFileSystemById(id);
|
||||
@@ -29,7 +29,7 @@ public class ServerFileSystemController : Controller
|
||||
return await fileSystem.List(path);
|
||||
}
|
||||
|
||||
[HttpPost("{id:int}/files/move")]
|
||||
[HttpPost("move")]
|
||||
public async Task Move([FromRoute] int id, [FromQuery] string oldPath, [FromQuery] string newPath)
|
||||
{
|
||||
var fileSystem = await GetFileSystemById(id);
|
||||
@@ -37,7 +37,7 @@ public class ServerFileSystemController : Controller
|
||||
await fileSystem.Move(oldPath, newPath);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:int}/files/delete")]
|
||||
[HttpDelete("delete")]
|
||||
public async Task Delete([FromRoute] int id, [FromQuery] string path)
|
||||
{
|
||||
var fileSystem = await GetFileSystemById(id);
|
||||
@@ -45,15 +45,23 @@ public class ServerFileSystemController : Controller
|
||||
await fileSystem.Delete(path);
|
||||
}
|
||||
|
||||
[HttpPost("{id:int}/files/mkdir")]
|
||||
[HttpPost("mkdir")]
|
||||
public async Task Mkdir([FromRoute] int id, [FromQuery] string path)
|
||||
{
|
||||
var fileSystem = await GetFileSystemById(id);
|
||||
|
||||
await fileSystem.Mkdir(path);
|
||||
}
|
||||
|
||||
[HttpPost("touch")]
|
||||
public async Task Touch([FromRoute] int id, [FromQuery] string path)
|
||||
{
|
||||
var fileSystem = await GetFileSystemById(id);
|
||||
|
||||
[HttpPost("{id:int}/files/compress")]
|
||||
await fileSystem.Touch(path);
|
||||
}
|
||||
|
||||
[HttpPost("compress")]
|
||||
public async Task Compress([FromRoute] int id, [FromBody] ServerFilesCompressRequest request)
|
||||
{
|
||||
var fileSystem = await GetFileSystemById(id);
|
||||
@@ -65,7 +73,7 @@ public class ServerFileSystemController : Controller
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPost("{id:int}/files/decompress")]
|
||||
[HttpPost("decompress")]
|
||||
public async Task Decompress([FromRoute] int id, [FromBody] ServerFilesDecompressRequest request)
|
||||
{
|
||||
var fileSystem = await GetFileSystemById(id);
|
||||
|
||||
Reference in New Issue
Block a user