[FEATURE] Several QOL Updates (#18)
Co-authored-by: Dunemask <dunemask@gmail.com> Reviewed-on: https://gitea.dunemask.dev/elysium/minecluster/pulls/18
This commit is contained in:
parent
4959d6c1fe
commit
0a0f9c8463
16 changed files with 432 additions and 828 deletions
|
@ -4,6 +4,7 @@ import {
|
|||
listServerFiles,
|
||||
removeServerItem,
|
||||
uploadServerItem,
|
||||
moveServerItems,
|
||||
} from "../k8s/server-files.js";
|
||||
import { sendError } from "../util/ExpressClientError.js";
|
||||
import { checkAuthorization } from "../database/queries/server-queries.js";
|
||||
|
@ -79,3 +80,18 @@ export async function getItem(req, res) {
|
|||
})
|
||||
.catch(sendError(res));
|
||||
}
|
||||
|
||||
export async function moveItems(req, res) {
|
||||
const serverSpec = req.body;
|
||||
if (!serverSpec.id) return res.status(400).send("Server id missing!");
|
||||
if (!serverSpec.destination)
|
||||
return res.status(400).send("Destination required!");
|
||||
if (!serverSpec.origin) return res.status(400).send("Origin required!");
|
||||
if (!serverSpec.files || !Array.isArray(serverSpec.files))
|
||||
return res.status(400).send("Files required!");
|
||||
const authorized = await checkAuthorization(serverSpec.id, req.cairoId);
|
||||
if (!authorized) return res.sendStatus(403);
|
||||
moveServerItems(serverSpec)
|
||||
.then(() => res.sendStatus(200))
|
||||
.catch(sendError(res));
|
||||
}
|
||||
|
|
|
@ -26,9 +26,13 @@ export async function webConsoleLogs(socket) {
|
|||
|
||||
const log = new k8s.Log(kc);
|
||||
const logStream = new stream.PassThrough();
|
||||
logStream.on("data", (chunk) =>
|
||||
socket.emit("push", Buffer.from(chunk).toString()),
|
||||
);
|
||||
var logstreamBuffer = "";
|
||||
logStream.on("data", (chunk) => {
|
||||
const bufferString = Buffer.from(chunk).toString();
|
||||
if (!bufferString.includes("\n")) return (logstreamBuffer += bufferString);
|
||||
const clientChunks = `${logstreamBuffer}${bufferString}`.split("\n");
|
||||
for (var c of clientChunks) socket.emit("push", c);
|
||||
});
|
||||
log
|
||||
.log(namespace, mcsPods[0], containerName, logStream, {
|
||||
follow: true,
|
||||
|
|
|
@ -67,7 +67,7 @@ function createBackupSecret(serverSpec) {
|
|||
`endpoint = ${backupHost}`,
|
||||
`acl = private`,
|
||||
`no_check_bucket = true`,
|
||||
`no_check_container = true`
|
||||
`no_check_container = true`,
|
||||
].join("\n");
|
||||
backupYaml.data["rclone.conf"] = Buffer.from(rcloneConfig).toString("base64");
|
||||
return backupYaml;
|
||||
|
|
|
@ -86,12 +86,22 @@ export async function uploadServerItem(serverSpec, file) {
|
|||
}).catch(handleError);
|
||||
}
|
||||
|
||||
export async function getServerItem(serverSpec, writableStream) {
|
||||
export async function getServerItem(serverSpec) {
|
||||
const { path } = serverSpec;
|
||||
const ds = new Transform({ transform: (c, e, cb) => cb(null, c) });
|
||||
const ds = new Transform({ transform: (c, _e, cb) => cb(null, c) });
|
||||
pathSecurityCheck(path);
|
||||
const ftpTransfer = useServerFtp(serverSpec, async (c) => {
|
||||
await c.downloadTo(ds, path);
|
||||
}).catch(handleError);
|
||||
return { ds, ftpTransfer };
|
||||
}
|
||||
|
||||
export async function moveServerItems(serverSpec) {
|
||||
const { destination, origin, files } = serverSpec;
|
||||
useServerFtp(serverSpec, async (c) =>
|
||||
Promise.all(
|
||||
files.map((f) => c.rename(`${origin}/${f}`, `${destination}/${f}`)),
|
||||
),
|
||||
).catch(handleError);
|
||||
return files;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
listFiles,
|
||||
uploadItem,
|
||||
getItem,
|
||||
moveItems,
|
||||
} from "../controllers/file-controller.js";
|
||||
|
||||
import cairoAuthMiddleware from "./middlewares/auth-middleware.js";
|
||||
|
@ -18,6 +19,7 @@ router.post("/list", listFiles);
|
|||
router.post("/folder", createFolder);
|
||||
router.delete("/item", deleteItem);
|
||||
router.post("/item", getItem);
|
||||
router.post("/move", moveItems);
|
||||
router.post("/upload", multerMiddleware.single("file"), uploadItem);
|
||||
|
||||
export default router;
|
||||
|
|
|
@ -17,7 +17,6 @@ const cairoAuthenticate = async (token) => {
|
|||
// Middleware
|
||||
const cairoAuthHandler = (req, res, next) => {
|
||||
if (!req.token) return res.status(401).send("Cairo auth required!");
|
||||
VERB("AUTH", `${MCL_CAIRO_URL}/api/user/info`);
|
||||
cairoAuthenticate(req.token)
|
||||
.then((authData) => (req.cairoId = authData.id))
|
||||
.then(() => next())
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
import multer from "multer";
|
||||
import multerS3 from "multer-s3";
|
||||
import AWS from "aws-sdk";
|
||||
|
||||
// Environment Variables
|
||||
const {
|
||||
MCL_S3_ENDPOINT: s3Endpoint,
|
||||
MCL_S3_ACCESS_KEY_ID: s3KeyId,
|
||||
MCL_S3_ACCESS_KEY: s3Key,
|
||||
} = process.env;
|
||||
|
||||
export const mcl = "mcl";
|
||||
|
||||
export const s3 = new AWS.S3({
|
||||
endpoint: s3Endpoint,
|
||||
accessKeyId: s3KeyId,
|
||||
secretAccessKey: s3Key,
|
||||
sslEnabled: true,
|
||||
s3ForcePathStyle: true,
|
||||
});
|
||||
|
||||
const storage = multerS3({
|
||||
s3,
|
||||
bucket,
|
||||
contentType: multerS3.AUTO_CONTENT_TYPE,
|
||||
metadata: (req, file, cb) => {
|
||||
cb(null, { fieldName: file.fieldname });
|
||||
},
|
||||
key: (req, file, cb) => {
|
||||
cb(null, Date.now().toString());
|
||||
},
|
||||
});
|
||||
|
||||
export const upload = multer({ storage });
|
Loading…
Add table
Add a link
Reference in a new issue