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

Commit 31162cc

Browse files
authored
Fixed issue with upload in Studio (#7609)
* Fixed issue with scene save due to thumbnail upload * Fixed issue with file browser upload in studio
1 parent a8e774f commit 31162cc

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

packages/client-core/src/common/services/FileBrowserService.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ export const FileBrowserService = {
9393
.get(directory, params)) as Paginated<FileContentType>
9494
dispatchAction(FileBrowserAction.filesFetched({ files }))
9595
},
96-
putContent: async (fileName: string, path: string, body: Buffer, contentType: string) => {
97-
return API.instance.client.service('file-browser').patch(null, { fileName, path, body, contentType })
98-
},
9996
moveContent: async (oldName: string, newName: string, oldPath: string, newPath: string, isCopy = false) => {
10097
return API.instance.client.service('file-browser').update(null, { oldName, newName, oldPath, newPath, isCopy })
10198
},

packages/editor/src/components/assets/FileBrowserContentPanel.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
FILES_PAGE_LIMIT,
1212
useFileBrowserState
1313
} from '@xrengine/client-core/src/common/services/FileBrowserService'
14+
import { uploadToFeathersService } from '@xrengine/client-core/src/util/upload'
1415
import { processFileName } from '@xrengine/common/src/utils/processFileName'
1516
import { KTX2EncodeArguments } from '@xrengine/engine/src/assets/constants/CompressionParms'
1617
import { KTX2EncodeDefaultArguments } from '@xrengine/engine/src/assets/constants/CompressionParms'
@@ -231,7 +232,11 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (props)
231232
await FileBrowserService.addNewFolder(`${path}${file.name}`)
232233
} else {
233234
const name = processFileName(file.name)
234-
await FileBrowserService.putContent(name, path, file as any, file.type)
235+
await uploadToFeathersService('file-browser/upload', [file], {
236+
fileName: name,
237+
path,
238+
contentType: file.type
239+
}).promise
235240
}
236241
})
237242
)

packages/editor/src/functions/sceneFunctions.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import i18n from 'i18next'
22

33
import { API } from '@xrengine/client-core/src/API'
4+
import { uploadToFeathersService } from '@xrengine/client-core/src/util/upload'
45
import { SceneData } from '@xrengine/common/src/interfaces/SceneInterface'
56
import multiLogger from '@xrengine/common/src/logger'
67
import { serializeWorld } from '@xrengine/engine/src/scene/functions/serializeWorld'
@@ -79,14 +80,14 @@ export const saveScene = async (
7980
) => {
8081
if (signal.aborted) throw new Error(i18n.t('editor:errors.saveProjectAborted'))
8182

82-
const thumbnailBuffer = thumbnailBlob ? await thumbnailBlob.arrayBuffer() : undefined
83-
84-
if (signal.aborted) throw new Error(i18n.t('editor:errors.saveProjectAborted'))
85-
8683
const sceneData = serializeWorld()
8784

8885
try {
89-
return await API.instance.client.service('scene').update(projectName, { sceneName, sceneData, thumbnailBuffer })
86+
return await uploadToFeathersService('scene/upload', thumbnailBlob ? [thumbnailBlob] : [], {
87+
projectName,
88+
sceneName,
89+
sceneData
90+
}).promise
9091
} catch (error) {
9192
logger.error(error, 'Error in saving project')
9293
throw error

packages/server-core/src/projects/scene/scene.hooks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { iff, isProvider } from 'feathers-hooks-common'
2+
13
import authenticate from '../../hooks/authenticate'
24
import projectPermissionAuthenticate from '../../hooks/project-permission-authenticate'
35
import setResponseStatusCode from '../../hooks/set-response-status-code'
@@ -9,7 +11,7 @@ export default {
911
find: [],
1012
get: [],
1113
create: [verifyScope('editor', 'write'), projectPermissionAuthenticate(false)],
12-
update: [verifyScope('editor', 'write'), projectPermissionAuthenticate(false)],
14+
update: [iff(isProvider('external'), verifyScope('editor', 'write') as any), projectPermissionAuthenticate(false)],
1315
patch: [verifyScope('editor', 'write'), projectPermissionAuthenticate(false)],
1416
remove: [verifyScope('editor', 'write'), projectPermissionAuthenticate(false)]
1517
},

packages/server-core/src/projects/scene/scene.service.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Params } from '@feathersjs/feathers'
2+
import express from 'express'
3+
import multer from 'multer'
24

35
import { SceneData } from '@xrengine/common/src/interfaces/SceneInterface'
46

57
import { Application, ServerMode } from '../../../declarations'
68
import { getStorageProvider } from '../../media/storageprovider/storageprovider'
9+
import { UploadParams } from '../../media/upload-asset/upload-asset.service'
710
import { getActiveInstancesForScene } from '../../networking/instance/instance.service'
811
import logger from '../../ServerLogger'
912
import { getAllPortals, getEnvMapBake, getPortal } from './scene-helper'
@@ -14,6 +17,9 @@ import hooks from './scene.hooks'
1417
declare module '@xrengine/common/declarations' {
1518
interface ServiceTypes {
1619
scene: Scene
20+
'scene/upload': {
21+
create: ReturnType<typeof uploadScene>
22+
}
1723
}
1824
interface ServiceTypes {
1925
portal: {
@@ -29,6 +35,24 @@ declare module '@xrengine/common/declarations' {
2935
}
3036
}
3137

38+
export const uploadScene = (app: Application) => async (data: any, params: UploadParams) => {
39+
if (typeof data === 'string') data = JSON.parse(data)
40+
if (typeof data.sceneData === 'string') data.sceneData = JSON.parse(data.sceneData)
41+
42+
const thumbnailBuffer = params.files.length > 0 ? params.files[0].buffer : undefined
43+
44+
const { projectName, sceneName, sceneData, storageProviderName } = data
45+
46+
const result = await app
47+
.service('scene')
48+
.update(projectName, { sceneName, sceneData, storageProviderName, thumbnailBuffer })
49+
50+
// Clear params otherwise all the files and auth details send back to client as response
51+
for (const prop of Object.getOwnPropertyNames(params)) delete params[prop]
52+
53+
return result
54+
}
55+
3256
export interface SceneParams extends Params {
3357
metadataOnly: boolean
3458
}
@@ -95,6 +119,8 @@ export const getAllScenes = (app: Application) => {
95119
}
96120
}
97121

122+
const multipartMiddleware = multer({ limits: { fieldSize: Infinity, files: 1 } })
123+
98124
export default (app: Application) => {
99125
/**
100126
* Initialize our service with any options it requires and docs
@@ -104,6 +130,21 @@ export default (app: Application) => {
104130

105131
app.use('scene', event)
106132

133+
app.use(
134+
'scene/upload',
135+
multipartMiddleware.any(),
136+
(req: express.Request, res: express.Response, next: express.NextFunction) => {
137+
if (req?.feathers && req.method !== 'GET') {
138+
;(req as any).feathers.files = (req as any).files.media ? (req as any).files.media : (req as any).files
139+
}
140+
141+
next()
142+
},
143+
{
144+
create: uploadScene(app)
145+
}
146+
)
147+
107148
app.use('scene-data', {
108149
get: getScenesForProject(app),
109150
find: getAllScenes(app)

0 commit comments

Comments
 (0)