From d908f152c40062356f77cc179d4efeb0283d58b5 Mon Sep 17 00:00:00 2001 From: Michael Estes Date: Mon, 5 Aug 2024 16:27:29 -0700 Subject: [PATCH 1/2] Upload drag drop files MT fix --- .../editor/src/functions/assetFunctions.ts | 2 +- .../editor/panels/Files/container/index.tsx | 46 ++++++------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/packages/editor/src/functions/assetFunctions.ts b/packages/editor/src/functions/assetFunctions.ts index fb0c7f040d..4f979bbe9f 100644 --- a/packages/editor/src/functions/assetFunctions.ts +++ b/packages/editor/src/functions/assetFunctions.ts @@ -35,7 +35,7 @@ import { modelResourcesPath } from '@etherealengine/engine/src/assets/functions/ import { pathJoin } from '@etherealengine/common/src/utils/miscUtils' -const handleUploadFiles = (projectName: string, directoryPath: string, files: FileList) => { +export const handleUploadFiles = (projectName: string, directoryPath: string, files: FileList | File[]) => { return Promise.all( Array.from(files).map((file) => { const fileDirectory = file.webkitRelativePath || file.name diff --git a/packages/ui/src/components/editor/panels/Files/container/index.tsx b/packages/ui/src/components/editor/panels/Files/container/index.tsx index 2f1078afb6..df23fad999 100644 --- a/packages/ui/src/components/editor/panels/Files/container/index.tsx +++ b/packages/ui/src/components/editor/panels/Files/container/index.tsx @@ -25,7 +25,6 @@ Ethereal Engine. All Rights Reserved. import { FileThumbnailJobState } from '@etherealengine/client-core/src/common/services/FileThumbnailJobState' import { NotificationService } from '@etherealengine/client-core/src/common/services/NotificationService' import { PopoverState } from '@etherealengine/client-core/src/common/services/PopoverState' -import { uploadToFeathersService } from '@etherealengine/client-core/src/util/upload' import config from '@etherealengine/common/src/config' import { FileBrowserContentType, @@ -33,12 +32,10 @@ import { UserID, archiverPath, fileBrowserPath, - fileBrowserUploadPath, projectPath, staticResourcePath } from '@etherealengine/common/src/schema.type.module' import { CommonKnownContentTypes } from '@etherealengine/common/src/utils/CommonKnownContentTypes' -import { processFileName } from '@etherealengine/common/src/utils/processFileName' import { Engine } from '@etherealengine/ecs' import { AssetSelectionChangePropsType } from '@etherealengine/editor/src/components/assets/AssetsPreviewPanel' import { @@ -51,7 +48,11 @@ import ImageCompressionPanel from '@etherealengine/editor/src/components/assets/ import ModelCompressionPanel from '@etherealengine/editor/src/components/assets/ModelCompressionPanel' import { DndWrapper } from '@etherealengine/editor/src/components/dnd/DndWrapper' import { SupportedFileTypes } from '@etherealengine/editor/src/constants/AssetTypes' -import { downloadBlobAsZip, inputFileWithAddToScene } from '@etherealengine/editor/src/functions/assetFunctions' +import { + downloadBlobAsZip, + handleUploadFiles, + inputFileWithAddToScene +} from '@etherealengine/editor/src/functions/assetFunctions' import { bytesToSize, unique } from '@etherealengine/editor/src/functions/utils' import { EditorState } from '@etherealengine/editor/src/services/EditorServices' import { ClickPlacementState } from '@etherealengine/editor/src/systems/ClickPlacementSystem' @@ -346,10 +347,8 @@ const FileBrowserContentPanel: React.FC = (props) await moveContent(data.fullName, newName, data.path, destinationPath, false) } } else { - const destinationPathCleaned = removeLeadingTrailingSlash(destinationPath) - const folder = destinationPathCleaned //destinationPathCleaned.substring(0, destinationPathCleaned.lastIndexOf('/') + 1) - const projectName = folder.split('/')[1] - const relativePath = folder.replace('projects/' + projectName + '/', '') + const path = selectedDirectory.get(NO_PROXY).slice(1) + const toUpload = [] as File[] await Promise.all( data.files.map(async (file) => { @@ -358,38 +357,21 @@ const FileBrowserContentPanel: React.FC = (props) // creating directory await fileService.create(`${destinationPath}${file.name}`) } else { - try { - const name = processFileName(file.name) - await uploadToFeathersService(fileBrowserUploadPath, [file], { - args: [ - { - project: projectName, - path: relativePath + '/' + name, - contentType: file.type - } - ] - }).promise - } catch (err) { - NotificationService.dispatchNotify(err.message, { variant: 'error' }) - } + toUpload.push(file) } }) ) + + try { + await handleUploadFiles(projectName, path, toUpload) + } catch (err) { + NotificationService.dispatchNotify(err.message, { variant: 'error' }) + } } await refreshDirectory() } - function removeLeadingTrailingSlash(str) { - if (str.startsWith('/')) { - str = str.substring(1) - } - if (str.endsWith('/')) { - str = str.substring(0, str.length - 1) - } - return str - } - const onBackDirectory = () => { const pattern = /([^/]+)/g const result = selectedDirectory.value.match(pattern) From b70c7c30c7e8ccb88226522c1dfe059a4efcaa89 Mon Sep 17 00:00:00 2001 From: Michael Estes Date: Mon, 5 Aug 2024 16:41:15 -0700 Subject: [PATCH 2/2] Array length check --- .../components/editor/panels/Files/container/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/components/editor/panels/Files/container/index.tsx b/packages/ui/src/components/editor/panels/Files/container/index.tsx index df23fad999..441eab9ae0 100644 --- a/packages/ui/src/components/editor/panels/Files/container/index.tsx +++ b/packages/ui/src/components/editor/panels/Files/container/index.tsx @@ -362,10 +362,12 @@ const FileBrowserContentPanel: React.FC = (props) }) ) - try { - await handleUploadFiles(projectName, path, toUpload) - } catch (err) { - NotificationService.dispatchNotify(err.message, { variant: 'error' }) + if (toUpload.length) { + try { + await handleUploadFiles(projectName, path, toUpload) + } catch (err) { + NotificationService.dispatchNotify(err.message, { variant: 'error' }) + } } }