import ftp from "basic-ftp"; import { ERR } from "../util/logging.js"; import { getServerAssets } from "./k8s-server-control.js"; import ExpressClientError from "../util/ExpressClientError.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 = (e) => { ERR("SERVER FILES", "Error occurred while preforming FTP operation!", e); throw new ExpressClientError({ c: 500, m: "Error occurred while performing FTP operation!", }); }; export async function listServerFiles(serverSpec) { const { name } = serverSpec; const server = await getServerAssets(name); if (!server) throw new ExpressClientError({ c: 404, m: "No resources for that server were found!", }); if (!server.service) throw new ExpressClientError({ c: 409, m: "Service doesn't exist, please contact your hosting provider!", }); // FTP Operations; const client = await useFtp(server.service).catch(handleError); await client .list() .then((f) => res.json(f)) .catch(handleError); client.close(); }