[FEATURE] Adjust server control

This commit is contained in:
Dunemask 2023-12-17 12:25:14 -07:00
parent 7348b07352
commit 62c966a6bd
8 changed files with 109 additions and 57 deletions

View file

@ -4,6 +4,22 @@ import { getServerAssets } from "./k8s-server-control.js";
const namespace = process.env.MCL_SERVER_NAMESPACE;
export async function useFtp(serverService) {
const { name } = serverService.metadata;
const client = new ftp.Client();
await client.access({
host: `${name}.${namespace}.svc.cluster.local`,
user: "minecluster",
password: "minecluster",
});
return client;
}
const handleError = (res) => (e) => {
ERR("SERVER FILES", "Error occurred while preforming FTP operation!", e);
res.status(500).send("Error occurred while performing FTP operation!");
};
export async function listFiles(req, res) {
const serverSpec = req.body;
if (!serverSpec) return res.sendStatus(400);
@ -16,20 +32,12 @@ export async function listFiles(req, res) {
return res
.status(409)
.send("Service doesn't exist, please contact your hosting provider!");
const client = new ftp.Client(0);
client.ftp.verbose = true;
try {
await client.access({
host: `${server.service.metadata.name}.${namespace}.svc.cluster.local`,
user: "minecluster",
password: "minecluster",
});
const files = await client.list();
res.json(files);
} catch (err) {
console.log(err);
ERR("SERVER FILES", "Error loading client files:");
res.status(500).send(err);
}
// client.ftp.verbose = true;
const client = await useFtp(server.service).catch(handleError(res));
if (!client) return;
await client
.list()
.then((f) => res.json(f))
.catch(handleError(res));
client.close();
}