[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:
dunemask 2024-02-11 03:57:01 +00:00
parent 4959d6c1fe
commit 0a0f9c8463
16 changed files with 432 additions and 828 deletions

View file

@ -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));
}

View file

@ -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,