From 9edcb9c82d98fac534a12d9bdf1dda8dfc1ca4bf Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 30 Apr 2025 21:03:16 +0200 Subject: [PATCH] Support folder upload --- page/src/filesystem-explorer.tsx | 37 ++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/page/src/filesystem-explorer.tsx b/page/src/filesystem-explorer.tsx index 33757271..ef8b63ab 100644 --- a/page/src/filesystem-explorer.tsx +++ b/page/src/filesystem-explorer.tsx @@ -188,6 +188,36 @@ interface BreadcrumbElement { targetPath: string[]; } +function isGoodPath(path: any) { + return typeof path === "string" && path.length > 0; +} + +function trimLeadingSlash(path: string) { + if (path.startsWith("/")) { + return path.substring(1); + } + + return path; +} + +function getFileName(file: File) { + const fileObj = file as any; + const properties = ["relativePath", "webkitRelativePath", "name"]; + + for (let i = 0; i < properties.length; ++i) { + const prop = properties[i]; + + if (prop in fileObj) { + const relativePath = fileObj[prop]; + if (isGoodPath(relativePath)) { + return trimLeadingSlash(relativePath); + } + } + } + + return file.name; +} + function generateBreadcrumbElements(path: string[]): BreadcrumbElement[] { const elements = path.map((p, index) => { const e: BreadcrumbElement = { @@ -309,8 +339,9 @@ export class FilesystemExplorer extends React.Component< } const fileData = (await readFiles(files)).map((f) => { + const name = getFileName(f.file); return { - name: makeFullPathWithState(this.state, f.file.name.toLowerCase()), + name: makeFullPathWithState(this.state, name.toLowerCase()), data: f.data, }; }); @@ -439,9 +470,7 @@ export class FilesystemExplorer extends React.Component<
Are you sure you want to delete{" "} - - {makeWindowsPathWithState(this.state, this.state.removeFile)} - + {makeWindowsPathWithState(this.state, this.state.removeFile)}