[FEATURE] Allow folder uploads (#21)
Co-authored-by: Dunemask <dunemask@gmail.com> Reviewed-on: https://gitea.dunemask.dev/elysium/minecluster/pulls/21
This commit is contained in:
parent
b15f616adb
commit
332f84972c
2 changed files with 7 additions and 3 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue