Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for asset-library service to use schema, knex & feathers 5 #8681

Merged
merged 9 commits into from
Sep 12, 2023
5 changes: 3 additions & 2 deletions packages/editor/src/functions/assetFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { PrefabComponent } from '@etherealengine/engine/src/scene/components/Pre
import { sceneToGLTF } from '@etherealengine/engine/src/scene/functions/GLTFConversion'
import { getState } from '@etherealengine/hyperflux'

import { assetLibraryPath } from '@etherealengine/engine/src/schemas/assets/asset-library.schema'
import { EditorState } from '../services/EditorServices'

export const exportPrefab = async (entity: Entity) => {
Expand Down Expand Up @@ -175,8 +176,8 @@ export const getEntries = async (directoryReader: FileSystemDirectoryReader): Pr

export const extractZip = async (path: string): Promise<any> => {
try {
const parms = { path: path }
await Engine.instance.api.service('asset-library').create(parms)
const params = { path: path }
await Engine.instance.api.service(assetLibraryPath).create(params)
} catch (err) {
console.error('error extracting zip: ', err)
}
Expand Down
28 changes: 28 additions & 0 deletions packages/engine/src/schemas/assets/asset-library.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
CPAL-1.0 License

The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.

The Original Code is Ethereal Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.

All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
export const assetLibraryPath = 'asset-library'
export const assetLibraryMethods = ['create'] as const
41 changes: 12 additions & 29 deletions packages/server-core/src/assets/assetLibrary/asset-library.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,34 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { Id, Params, ServiceMethods } from '@feathersjs/feathers'
import appRootPath from 'app-root-path'
import { ServiceInterface } from '@feathersjs/feathers'
import extract from 'extract-zip'
import fs from 'fs'
import path from 'path'

import { Application } from '@etherealengine/server-core/declarations'
import appRootPath from 'app-root-path'
import { RootParams } from '../../api/root-params'

interface CreateParams {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AssetLibraryParams extends RootParams {
path: string
}

export class AssetLibrary implements ServiceMethods<any> {
/**
* A class for AssetLibrary service
*/

export class AssetLibraryService implements ServiceInterface<AssetLibraryParams> {
app: Application
docs: any
rootPath: string

constructor(app: Application) {
this.app = app
this.rootPath = path.join(appRootPath.path, 'packages/projects/projects/')
}

async find(params?: Params): Promise<any> {
return {}
}

async get(id: Id, params?: Params): Promise<any> {
return {}
}

async update(id: Id, params?: Params): Promise<any> {
return {}
}

async patch(id: Id, params?: Params): Promise<any> {
return {}
}

async remove(id: Id, params?: Params): Promise<any> {
return {}
}

async setup() {}

async create(createParams: CreateParams, params?: Params): Promise<any> {
async create(createParams: AssetLibraryParams) {
try {
const inPath = decodeURI(createParams.path)
const pathData = /.*projects\/([\w\d\s\-_]+)\/assets\/([\w\d\s\-_\\\/]+).zip$/.exec(inPath)
Expand All @@ -77,7 +60,7 @@ export class AssetLibrary implements ServiceMethods<any> {
const fullPath = path.join(this.rootPath, assetRoot)
fs.mkdirSync(fullPath)
await extract(`${fullPath}.zip`, { dir: fullPath })
return { assetRoot }
return { ...createParams, assetRoot }
hurairahmateen marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
throw new Error('error unzipping archive:', e)
}
Expand Down
21 changes: 7 additions & 14 deletions ...ets/assetLibrary/asset-library.service.ts → ...assets/assetLibrary/asset-library.docs.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { Application } from '../../../declarations'
import { AssetLibrary } from './asset-library.class'
import hooks from './asset-library.hooks'
import { createSwaggerServiceOptions } from 'feathers-swagger'

declare module '@etherealengine/common/declarations' {
interface ServiceTypes {
'asset-library': AssetLibrary
export default createSwaggerServiceOptions({
schemas: {},
docs: {
description: 'Asset library service description',
securities: ['all']
}
}

export default (app: Application) => {
const libClass = new AssetLibrary(app)
app.use('asset-library', libClass)
const service = app.service('asset-library')
service.hooks(hooks)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export default {
all: [authenticate()],
find: [disallow()],
get: [disallow()],
create: [iff(isProvider('external'), verifyScope('editor', 'write') as any)],
update: [disallow() /*verifyScope('editor', 'write')*/],
patch: [disallow() /*verifyScope('editor', 'write')*/],
remove: [disallow() /*verifyScope('editor', 'write')*/]
create: [iff(isProvider('external'), verifyScope('editor', 'write'))],
update: [disallow()],
patch: [disallow()],
remove: [disallow()]
},

after: {
Expand Down
49 changes: 49 additions & 0 deletions packages/server-core/src/assets/assetLibrary/asset-library.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
CPAL-1.0 License

The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.

The Original Code is Ethereal Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.

All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

import { assetLibraryMethods, assetLibraryPath } from '@etherealengine/engine/src/schemas/assets/asset-library.schema'
import { Application } from '../../../declarations'
import { AssetLibraryService } from './asset-library.class'
import assetLibraryDocs from './asset-library.docs'
import hooks from './asset-library.hooks'

declare module '@etherealengine/common/declarations' {
interface ServiceTypes {
[assetLibraryPath]: AssetLibraryService
}
}

export default (app: Application): void => {
app.use(assetLibraryPath, new AssetLibraryService(app), {
// A list of all methods this service exposes externally
methods: assetLibraryMethods,
// You can add additional custom events to be sent to clients here
events: [],
docs: assetLibraryDocs
})

const service = app.service(assetLibraryPath)
service.hooks(hooks)
}
2 changes: 1 addition & 1 deletion packages/server-core/src/assets/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import AssetLibrary from './assetLibrary/asset-library.service'
import AssetLibrary from './assetLibrary/asset-library'
import ImageConvert from './image-convert/image-convert.service'
import KTX2Encode from './ktx2-encode/ktx2-encode.service'
import ModelTransform from './model-transform/model-transform.service'
Expand Down
Loading