[FEATURE] Basic System with file manager (#4)
Co-authored-by: dunemask <dunemask@gmail.com> Co-authored-by: Dunemask <dunemask@gmail.com> Reviewed-on: https://gitea.dunemask.dev/elysium/minecluster/pulls/4
This commit is contained in:
parent
8fb5b34c77
commit
4f19cf19d9
62 changed files with 5910 additions and 1190 deletions
70
lib/controllers/file-controller.js
Normal file
70
lib/controllers/file-controller.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
import {
|
||||
createServerFolder,
|
||||
getServerItem,
|
||||
listServerFiles,
|
||||
removeServerItem,
|
||||
uploadServerItem,
|
||||
} from "../k8s/server-files.js";
|
||||
import { sendError } from "../util/ExpressClientError.js";
|
||||
|
||||
export async function listFiles(req, res) {
|
||||
const serverSpec = req.body;
|
||||
if (!serverSpec) return res.sendStatus(400);
|
||||
if (!serverSpec.name) return res.status(400).send("Server name required!");
|
||||
listServerFiles(serverSpec)
|
||||
.then((f) => {
|
||||
const fileData = f.map((fi, i) => ({
|
||||
name: fi.name,
|
||||
isDir: fi.type === 2,
|
||||
id: `${fi.name}-${i}`,
|
||||
isHidden: fi.name.startsWith("."),
|
||||
isSymLink: !!fi.link,
|
||||
size: fi.size,
|
||||
}));
|
||||
res.json(fileData);
|
||||
})
|
||||
.catch(sendError(res));
|
||||
}
|
||||
|
||||
export async function createFolder(req, res) {
|
||||
const serverSpec = req.body;
|
||||
if (!serverSpec) return res.sendStatus(400);
|
||||
if (!serverSpec.name) return res.status(400).send("Server name required!");
|
||||
if (!serverSpec.path) return res.status(400).send("Path required!");
|
||||
createServerFolder(serverSpec)
|
||||
.then(() => res.sendStatus(200))
|
||||
.catch(sendError(res));
|
||||
}
|
||||
|
||||
export async function deleteItem(req, res) {
|
||||
const serverSpec = req.body;
|
||||
if (!serverSpec) return res.sendStatus(400);
|
||||
if (!serverSpec.name) return res.status(400).send("Server name required!");
|
||||
if (!serverSpec.path) return res.status(400).send("Path required!");
|
||||
if (serverSpec.isDir === undefined || serverSpec.isDir === null)
|
||||
return res.status(400).send("IsDIr required!");
|
||||
removeServerItem(serverSpec)
|
||||
.then(() => res.sendStatus(200))
|
||||
.catch(sendError(res));
|
||||
}
|
||||
|
||||
export async function uploadItem(req, res) {
|
||||
const serverSpec = req.body;
|
||||
if (!serverSpec.name) return res.status(400).send("Server name required!");
|
||||
if (!serverSpec.path) return res.status(400).send("Path required!");
|
||||
uploadServerItem(serverSpec, req.file)
|
||||
.then(() => res.sendStatus(200))
|
||||
.catch(sendError(res));
|
||||
}
|
||||
|
||||
export async function getItem(req, res) {
|
||||
const serverSpec = req.body;
|
||||
if (!serverSpec.name) return res.status(400).send("Server name required!");
|
||||
if (!serverSpec.path) return res.status(400).send("Path required!");
|
||||
getServerItem(serverSpec, res)
|
||||
.then(({ ds, ftpTransfer }) => {
|
||||
ds.pipe(res).on("error", sendError(res));
|
||||
return ftpTransfer;
|
||||
})
|
||||
.catch(sendError(res));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue