[FEATURE] Initial File Manager
This commit is contained in:
parent
e66e685903
commit
22bf905415
10 changed files with 356 additions and 85 deletions
|
@ -1,4 +1,10 @@
|
|||
import { listServerFiles } from "../k8s/server-files.js";
|
||||
import {
|
||||
createServerFolder,
|
||||
getServerItem,
|
||||
listServerFiles,
|
||||
removeServerItem,
|
||||
uploadServerItem,
|
||||
} from "../k8s/server-files.js";
|
||||
import { sendError } from "../util/ExpressClientError.js";
|
||||
|
||||
export async function listFiles(req, res) {
|
||||
|
@ -15,10 +21,50 @@ export async function listFiles(req, res) {
|
|||
isSymLink: !!fi.link,
|
||||
size: fi.size,
|
||||
}));
|
||||
console.log(fileData);
|
||||
res.json(fileData);
|
||||
})
|
||||
.catch(sendError(res));
|
||||
}
|
||||
|
||||
export async function uploadFile(req, 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