Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Upload drag drop files MT fix (#10881)
Browse files Browse the repository at this point in the history
* Upload drag drop files MT fix

* Array length check
  • Loading branch information
MichaelEstes authored Aug 6, 2024
1 parent 981d0e3 commit 1b3f726
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/editor/src/functions/assetFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 16 additions & 32 deletions packages/ui/src/components/editor/panels/Files/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ 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,
StaticResourceType,
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 {
Expand All @@ -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'
Expand Down Expand Up @@ -346,10 +347,8 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (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) => {
Expand All @@ -358,38 +357,23 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (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)
}
})
)

if (toUpload.length) {
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)
Expand Down

0 comments on commit 1b3f726

Please sign in to comment.