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

Commit

Permalink
put back local project copy sync functions
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Sep 6, 2023
1 parent f435e58 commit 2d81324
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Ethereal Engine. All Rights Reserved.
import { Forbidden } from '@feathersjs/errors'
import { NullableId, Paginated, Params, ServiceMethods } from '@feathersjs/feathers/lib/declarations'
import appRootPath from 'app-root-path'
import fs from 'fs'
import path from 'path/posix'

import { FileContentType } from '@etherealengine/common/src/interfaces/FileContentType'
Expand All @@ -36,7 +37,7 @@ import { projectPermissionPath } from '@etherealengine/engine/src/schemas/projec
import { Knex } from 'knex'
import { Application } from '../../../declarations'
import { UserParams } from '../../api/root-params'
import { getIncrementalName } from '../FileUtil'
import { copyRecursiveSync, getIncrementalName } from '../FileUtil'
import { getCacheDomain } from '../storageprovider/getCacheDomain'
import { getCachedURL } from '../storageprovider/getCachedURL'
import { getStorageProvider } from '../storageprovider/storageprovider'
Expand Down Expand Up @@ -166,6 +167,8 @@ export class FileBrowserService implements ServiceMethods<any> {
isDirectory: true
})

fs.mkdirSync(path.join(projectsRootFolder, parentPath, key))

return result
}

Expand All @@ -187,6 +190,15 @@ export class FileBrowserService implements ServiceMethods<any> {
const fileName = await getIncrementalName(data.newName, _newPath, storageProvider, isDirectory)
const result = await storageProvider.moveObject(data.oldName, fileName, _oldPath, _newPath, data.isCopy)

const oldNamePath = path.join(projectsRootFolder, _oldPath, data.oldName)
const newNamePath = path.join(projectsRootFolder, _newPath, fileName)

if (data.isCopy) {
copyRecursiveSync(oldNamePath, newNamePath)
} else {
fs.renameSync(oldNamePath, newNamePath)
}

return result
}

Expand Down Expand Up @@ -215,6 +227,12 @@ export class FileBrowserService implements ServiceMethods<any> {
}
)

const filePath = path.join(projectsRootFolder, key)
const parentDirPath = path.dirname(filePath)

if (!fs.existsSync(parentDirPath)) fs.mkdirSync(parentDirPath, { recursive: true })
fs.writeFileSync(filePath, data.body)

const cacheDomain = getCacheDomain(storageProvider, params && params.provider == null)
return getCachedURL(key, cacheDomain)
}
Expand All @@ -234,6 +252,12 @@ export class FileBrowserService implements ServiceMethods<any> {

const filePath = path.join(projectsRootFolder, key)

if (fs.lstatSync(filePath).isDirectory()) {
fs.rmSync(filePath, { force: true, recursive: true })
} else {
fs.unlinkSync(filePath)
}

const staticResource = (await this.app.service(staticResourcePath).find({
query: {
key: filePath,
Expand Down

0 comments on commit 2d81324

Please sign in to comment.