[FEATURE] Initial FS traversal
This commit is contained in:
parent
af44ff710f
commit
e66e685903
11 changed files with 1260 additions and 108 deletions
|
@ -6,6 +6,19 @@ export async function listFiles(req, res) {
|
||||||
if (!serverSpec) return res.sendStatus(400);
|
if (!serverSpec) return res.sendStatus(400);
|
||||||
if (!serverSpec.name) return res.status(400).send("Server name required!");
|
if (!serverSpec.name) return res.status(400).send("Server name required!");
|
||||||
listServerFiles(serverSpec)
|
listServerFiles(serverSpec)
|
||||||
.then(() => res.sendStatus(200))
|
.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,
|
||||||
|
}));
|
||||||
|
console.log(fileData);
|
||||||
|
res.json(fileData);
|
||||||
|
})
|
||||||
.catch(sendError(res));
|
.catch(sendError(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function uploadFile(req, res) {}
|
||||||
|
|
|
@ -25,7 +25,7 @@ const handleError = (e) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function listServerFiles(serverSpec) {
|
export async function listServerFiles(serverSpec) {
|
||||||
const { name } = serverSpec;
|
const { name, dir } = serverSpec;
|
||||||
const server = await getServerAssets(name);
|
const server = await getServerAssets(name);
|
||||||
if (!server)
|
if (!server)
|
||||||
throw new ExpressClientError({
|
throw new ExpressClientError({
|
||||||
|
@ -40,9 +40,12 @@ export async function listServerFiles(serverSpec) {
|
||||||
|
|
||||||
// FTP Operations;
|
// FTP Operations;
|
||||||
const client = await useFtp(server.service).catch(handleError);
|
const client = await useFtp(server.service).catch(handleError);
|
||||||
await client
|
const files = client
|
||||||
.list()
|
.list(dir)
|
||||||
.then((f) => res.json(f))
|
.then((f) => {
|
||||||
.catch(handleError);
|
|
||||||
client.close();
|
client.close();
|
||||||
|
return f;
|
||||||
|
})
|
||||||
|
.catch(handleError);
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
|
|
1223
package-lock.json
generated
1223
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -43,6 +43,8 @@
|
||||||
"basic-ftp": "^5.0.4",
|
"basic-ftp": "^5.0.4",
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"chalk": "^5.3.0",
|
"chalk": "^5.3.0",
|
||||||
|
"chonky": "^2.3.2",
|
||||||
|
"chonky-icon-fontawesome": "^2.3.2",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"figlet": "^1.7.0",
|
"figlet": "^1.7.0",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
|
|
55
src/components/edit/MineclusterFiles.jsx
Normal file
55
src/components/edit/MineclusterFiles.jsx
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import {
|
||||||
|
FileBrowser,
|
||||||
|
FileContextMenu,
|
||||||
|
FileList,
|
||||||
|
FileNavbar,
|
||||||
|
FileToolbar,
|
||||||
|
setChonkyDefaults,
|
||||||
|
} from "chonky";
|
||||||
|
import { ChonkyIconFA } from "chonky-icon-fontawesome";
|
||||||
|
|
||||||
|
import { getServerFiles } from "@mcl/queries";
|
||||||
|
|
||||||
|
export default function MineclusterFiles(props) {
|
||||||
|
setChonkyDefaults({ iconComponent: ChonkyIconFA });
|
||||||
|
const { server: serverName } = props;
|
||||||
|
const [dirStack, setDirStack] = useState(["."]);
|
||||||
|
const [files, setFiles] = useState([]);
|
||||||
|
useEffect(() => {
|
||||||
|
getServerFiles(serverName, dirStack.join("/")).then((f) =>
|
||||||
|
setFiles(f ?? []),
|
||||||
|
);
|
||||||
|
}, [dirStack]);
|
||||||
|
|
||||||
|
const getFolderChain = () => {
|
||||||
|
if (dirStack.length === 1) return [{ id: "home", name: "/", isDir: true }];
|
||||||
|
return dirStack.map((d, i) => ({ id: `${d}-${i}`, name: d, isDir: true }));
|
||||||
|
};
|
||||||
|
|
||||||
|
function fileClick(chonkyEvent) {
|
||||||
|
const { id: clickEvent, payload } = chonkyEvent;
|
||||||
|
console.log(chonkyEvent);
|
||||||
|
if (clickEvent === `open_parent_folder`)
|
||||||
|
return setDirStack(dirStack.slice(0, -1));
|
||||||
|
if (clickEvent !== `open_files`) return console.log(clickEvent);
|
||||||
|
const { targetFile: file } = payload;
|
||||||
|
if (!file || !file.isDir) return;
|
||||||
|
setDirStack([...dirStack, file.name]);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box className="minecluster-files" sx={{ height: "calc(100vh - 6rem)" }}>
|
||||||
|
<FileBrowser
|
||||||
|
files={files}
|
||||||
|
folderChain={getFolderChain()}
|
||||||
|
onFileAction={fileClick}
|
||||||
|
>
|
||||||
|
<FileNavbar />
|
||||||
|
<FileToolbar />
|
||||||
|
<FileList />
|
||||||
|
<FileContextMenu />
|
||||||
|
</FileBrowser>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
|
@ -14,6 +14,8 @@ import PlayArrowIcon from "@mui/icons-material/PlayArrow";
|
||||||
import PendingIcon from "@mui/icons-material/Pending";
|
import PendingIcon from "@mui/icons-material/Pending";
|
||||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||||
import EditIcon from "@mui/icons-material/Edit";
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
|
import FolderIcon from "@mui/icons-material/Folder";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
export default function ServerCard(props) {
|
export default function ServerCard(props) {
|
||||||
const { server, openRcon } = props;
|
const { server, openRcon } = props;
|
||||||
|
@ -94,9 +96,24 @@ export default function ServerCard(props) {
|
||||||
>
|
>
|
||||||
<TerminalIcon />
|
<TerminalIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton color="primary" aria-label="Edit" size="large">
|
<IconButton
|
||||||
|
color="primary"
|
||||||
|
aria-label="Edit"
|
||||||
|
size="large"
|
||||||
|
component={Link}
|
||||||
|
to={`/mcl/edit?server=${name}`}
|
||||||
|
>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
color="primary"
|
||||||
|
aria-label="Files"
|
||||||
|
size="large"
|
||||||
|
component={Link}
|
||||||
|
to={`/mcl/files?server=${name}`}
|
||||||
|
>
|
||||||
|
<FolderIcon />
|
||||||
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="error"
|
color="error"
|
||||||
aria-label="Delete Server"
|
aria-label="Delete Server"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Home from "@mcl/pages/Home.jsx";
|
import Home from "@mcl/pages/Home.jsx";
|
||||||
import Create from "@mcl/pages/Create.jsx";
|
import Create from "@mcl/pages/Create.jsx";
|
||||||
|
import Files from "@mcl/pages/Files.jsx";
|
||||||
// Go To https://mui.com/material-ui/material-icons/ for more!
|
// Go To https://mui.com/material-ui/material-icons/ for more!
|
||||||
import HomeIcon from "@mui/icons-material/Home";
|
import HomeIcon from "@mui/icons-material/Home";
|
||||||
import AddIcon from "@mui/icons-material/Add";
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
|
@ -17,4 +18,10 @@ export default [
|
||||||
icon: <AddIcon />,
|
icon: <AddIcon />,
|
||||||
component: <Create />,
|
component: <Create />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Edit",
|
||||||
|
path: "/mcl/files",
|
||||||
|
icon: <AddIcon />,
|
||||||
|
component: <Files />,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
20
src/pages/Files.jsx
Normal file
20
src/pages/Files.jsx
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useSearchParams, useNavigate } from "react-router-dom";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Toolbar from "@mui/material/Toolbar";
|
||||||
|
import MineclusterFiles from "@mcl/components/edit/MineclusterFiles.jsx";
|
||||||
|
|
||||||
|
export default function Files() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const currentServer = searchParams.get("server");
|
||||||
|
const nav = useNavigate();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!currentServer) nav("/");
|
||||||
|
}, [currentServer]);
|
||||||
|
return (
|
||||||
|
<Box className="edit" sx={{ height: "100%" }}>
|
||||||
|
<MineclusterFiles server={currentServer} />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
|
@ -30,6 +30,15 @@ export const useDeleteServer = (server) =>
|
||||||
postJsonApi("/server/delete", { name: server }, "server-instances", "DELETE");
|
postJsonApi("/server/delete", { name: server }, "server-instances", "DELETE");
|
||||||
export const useCreateServer = (spec) =>
|
export const useCreateServer = (spec) =>
|
||||||
postJsonApi("/server/create", spec, "server-list");
|
postJsonApi("/server/create", spec, "server-list");
|
||||||
|
|
||||||
|
export const getServerFiles = async (server, dir) =>
|
||||||
|
fetchApiPost("/files/list", { name: server, dir })();
|
||||||
|
|
||||||
|
export const useInvalidator = () => {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
return (q) => qc.invalidateQueries([q]);
|
||||||
|
};
|
||||||
|
|
||||||
export const useServerList = () =>
|
export const useServerList = () =>
|
||||||
useQuery({ queryKey: ["server-list"], queryFn: fetchApi("/server/list") });
|
useQuery({ queryKey: ["server-list"], queryFn: fetchApi("/server/list") });
|
||||||
export const useServerInstances = () =>
|
export const useServerInstances = () =>
|
||||||
|
@ -63,5 +72,6 @@ const postJsonApi = (subPath, body, invalidate, method = "POST") => {
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
qc.invalidateQueries([invalidate]);
|
qc.invalidateQueries([invalidate]);
|
||||||
|
return res.json();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue