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

Commit

Permalink
IR-3921: Copying resource should create a static-resource entry (#10949)
Browse files Browse the repository at this point in the history
* Copy operation should create a static-resource with `create`

Currently, if we copy a resource in studio's file browser, it does not create an entry in static-resource table. But it updates the existing entry with new key. This PR fixes it by identifying copy operations and creating a fresh entry for them.

* Add test
  • Loading branch information
CITIZENDOT authored Aug 16, 2024
1 parent a98fd43 commit 13ad7d1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
39 changes: 31 additions & 8 deletions packages/server-core/src/media/file-browser/file-browser.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,37 @@ export class FileBrowserService
const results = [] as StaticResourceType[]
for (const resource of staticResources) {
const newKey = resource.key.replace(path.join(oldDirectory, oldName), path.join(newDirectory, fileName))
const result = await this.app.service(staticResourcePath).patch(
resource.id,
{
key: newKey
},
{ isInternal: true }
)
results.push(result)

if (data.isCopy) {
const result = await this.app.service(staticResourcePath).create(
{
key: newKey,
hash: resource.hash,
mimeType: resource.mimeType,
project: data.newProject,
stats: resource.stats,
type: resource.type,
tags: resource.tags,
dependencies: resource.dependencies,
licensing: resource.licensing,
description: resource.description,
attribution: resource.attribution,
thumbnailKey: resource.thumbnailKey,
thumbnailMode: resource.thumbnailMode
},
{ isInternal: true }
)
results.push(result)
} else {
const result = await this.app.service(staticResourcePath).patch(
resource.id,
{
key: newKey
},
{ isInternal: true }
)
results.push(result)
}
}

if (config.fsProjectSyncEnabled) {
Expand Down
25 changes: 21 additions & 4 deletions packages/server-core/src/media/file-browser/file-browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import assert from 'assert'
import { fileBrowserPath } from '@etherealengine/common/src/schemas/media/file-browser.schema'
import { destroyEngine } from '@etherealengine/ecs/src/Engine'

import { ProjectType, projectPath } from '@etherealengine/common/src/schema.type.module'
import { ProjectType, projectPath, staticResourcePath } from '@etherealengine/common/src/schema.type.module'
import { Application } from '../../../declarations'
import { createFeathersKoaApp } from '../../createApp'
import { getStorageProvider } from '../storageprovider/storageprovider'
Expand Down Expand Up @@ -227,18 +227,35 @@ describe('file-browser.test', () => {
})

it('copies file', async () => {
const oldPath = 'projects/' + testProjectName2 + '/public/'
const newPath = 'projects/' + testProjectName + '/public/'

const copyFileResult = await app.service(fileBrowserPath).update(null, {
oldProject: testProjectName2,
newProject: testProjectName,
oldName: testFileName2,
newName: testFileName2,
oldPath: 'projects/' + testProjectName2 + '/public/',
newPath: 'projects/' + testProjectName + '/public/',
oldPath,
newPath,
isCopy: true
})

assert.equal(copyFileResult.length, 1)
assert(copyFileResult[0].key === 'projects/' + testProjectName + '/public/' + testFileName2)
assert(copyFileResult[0].key === newPath + testFileName2)

const originalResource = await app.service(staticResourcePath).find({
query: {
key: oldPath + testFileName2
}
})
assert.ok(originalResource.data.length === 1, 'Original resource not found')

const copiedResource = await app.service(staticResourcePath).find({
query: {
key: newPath + testFileName2
}
})
assert.ok(copiedResource.data.length === 1, 'Copied resource not found')
})

it('copies directory', async () => {
Expand Down

0 comments on commit 13ad7d1

Please sign in to comment.