[FEATURE] Allow folder uploads

This commit is contained in:
Dunemask 2024-03-11 13:21:56 -06:00
parent b15f616adb
commit 17c1d68a63
2 changed files with 7 additions and 3 deletions

View file

@ -2,7 +2,8 @@ import ftp from "basic-ftp";
import { ERR } from "../util/logging.js"; import { ERR } from "../util/logging.js";
import { getServerAssets } from "./k8s-server-control.js"; import { getServerAssets } from "./k8s-server-control.js";
import ExpressClientError from "../util/ExpressClientError.js"; import ExpressClientError from "../util/ExpressClientError.js";
import { Readable, Writable, Transform } from "node:stream"; import { Readable, Transform } from "node:stream";
import { dirname, basename } from "node:path";
const namespace = process.env.MCL_SERVER_NAMESPACE; const namespace = process.env.MCL_SERVER_NAMESPACE;
@ -82,7 +83,8 @@ export async function uploadServerItem(serverSpec, file) {
const { path } = serverSpec; const { path } = serverSpec;
pathSecurityCheck(path); pathSecurityCheck(path);
await useServerFtp(serverSpec, async (c) => { await useServerFtp(serverSpec, async (c) => {
await c.uploadFrom(fileStream, path); await c.ensureDir(dirname(path));
await c.uploadFrom(fileStream, basename(path));
}).catch(handleError); }).catch(handleError);
} }

View file

@ -111,10 +111,12 @@ export default function MineclusterFiles(props) {
} }
async function uploadFile(file) { async function uploadFile(file) {
const filePath = file.path.startsWith("/") ? file.path : `/${file.path}`;
const formData = new FormData(); const formData = new FormData();
formData.append("file", file); formData.append("file", file);
formData.append("id", serverId); formData.append("id", serverId);
formData.append("path", [...dirStack, file.name].join("/")); const path = `${[...dirStack].join("/")}${filePath}`;
formData.append("path", path);
await fetch("/api/files/upload", { await fetch("/api/files/upload", {
method: "POST", method: "POST",
body: formData, body: formData,