[FEATURE] Adjust more server controllers
This commit is contained in:
parent
62c966a6bd
commit
37e3dc2ae9
16 changed files with 281 additions and 173 deletions
|
@ -1,6 +1,7 @@
|
|||
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;
|
||||
|
||||
|
@ -15,29 +16,33 @@ export async function useFtp(serverService) {
|
|||
return client;
|
||||
}
|
||||
|
||||
const handleError = (res) => (e) => {
|
||||
const handleError = (e) => {
|
||||
ERR("SERVER FILES", "Error occurred while preforming FTP operation!", e);
|
||||
res.status(500).send("Error occurred while performing FTP operation!");
|
||||
throw new ExpressClientError({
|
||||
c: 500,
|
||||
m: "Error occurred while performing FTP operation!",
|
||||
});
|
||||
};
|
||||
|
||||
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!");
|
||||
export async function listServerFiles(serverSpec) {
|
||||
const { name } = serverSpec;
|
||||
const server = await getServerAssets(name);
|
||||
if (!server)
|
||||
return res.status(404).send("No Resources for that server were found!");
|
||||
throw new ExpressClientError({
|
||||
c: 404,
|
||||
m: "No resources for that server were found!",
|
||||
});
|
||||
if (!server.service)
|
||||
return res
|
||||
.status(409)
|
||||
.send("Service doesn't exist, please contact your hosting provider!");
|
||||
// client.ftp.verbose = true;
|
||||
const client = await useFtp(server.service).catch(handleError(res));
|
||||
if (!client) return;
|
||||
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(res));
|
||||
.catch(handleError);
|
||||
client.close();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue