Skip to content

Commit

Permalink
Merge pull request #1077 from momentum-xyz/feat/plugins/creator
Browse files Browse the repository at this point in the history
Plugins: infrastructure and Creator
  • Loading branch information
dmitry-yudakov authored Oct 25, 2023
2 parents 3d55bf2 + e90dd3a commit 9192ad5
Show file tree
Hide file tree
Showing 53 changed files with 1,784 additions and 490 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const mediaRepositoryEndpoints = () => {
return {
uploadImage: `${BASE_URL}/image`,
uploadVideo: `${BASE_URL}/video`,
uploadAudio: `${BASE_URL}/audio`
uploadAudio: `${BASE_URL}/audio`,
uploadPlugin: `${BASE_URL}/plugin`
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,20 @@ export const uploadAudio: RequestInterface<UploadFileRequest, UploadFileResponse

return request.post(mediaRepositoryEndpoints().uploadAudio, formData, requestOptions);
};

export const uploadPlugin: RequestInterface<UploadFileRequest, UploadFileResponse> = (options) => {
const {file, headers, ...restOptions} = options;

const formData: FormData = new FormData();
formData.append('file', file);

const requestOptions = {
headers: {
'Content-Type': 'multipart/form-data',
...headers
},
...restOptions
};

return request.post(mediaRepositoryEndpoints().uploadPlugin, formData, requestOptions);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const configRepositoryEndpoints = () => {
return {
getChallenge: `${BASE_URL}/get-challenge`,
hostingAllowList: `${BASE_URL}/hosting-allow-list`,
hostingAllowListRemove: `${BASE_URL}/hosting-allow-list/:userId`
hostingAllowListRemove: `${BASE_URL}/hosting-allow-list/:userId`,
activatePlugin: `${BASE_URL}/activate-plugin`
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {request} from 'api/request';
import {RequestInterface} from 'api/interfaces';

import {
ActivatePluginRequest,
AddToHostingAllowListRequest,
GetHostingAllowListRequest,
GetHostingAllowListResponse,
Expand Down Expand Up @@ -46,3 +47,7 @@ export const removeFromHostingAllowList: RequestInterface<
restOptions
);
};

export const activatePlugin: RequestInterface<ActivatePluginRequest, null> = (options) => {
return request.post(configRepositoryEndpoints().activatePlugin, options);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ export interface HostingAllowListItemInterface {
export interface GetHostingAllowListRequest {}

export interface GetHostingAllowListResponse extends Array<HostingAllowListItemInterface> {}

export interface ActivatePluginRequest {
plugin_hash: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const createObject: RequestInterface<CreateObjectRequest, CreateObjectRes
object_type_id,
asset_2d_id,
asset_3d_id,
transform,
minimap,
...restOptions
} = options;
Expand All @@ -42,6 +43,7 @@ export const createObject: RequestInterface<CreateObjectRequest, CreateObjectRes
parent_id,
asset_2d_id,
asset_3d_id,
transform,
minimap
},
restOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AttributeValueInterface} from '@momentum-xyz/sdk';
import {AttributeValueInterface, Transform} from '@momentum-xyz/sdk';

import {MetadataInterface, OptionsInterface} from 'api/interfaces';

Expand Down Expand Up @@ -41,6 +41,8 @@ export interface CreateObjectRequest {
asset_2d_id?: string;
asset_3d_id?: string;

transform?: Transform;

minimap?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const pluginsRepositoryEndpoints = () => {
const BASE_URL = '/plugins';
const BASE_URL = '/plugin';

return {
list: `${BASE_URL}`,
Expand Down
12 changes: 12 additions & 0 deletions packages/app/src/core/models/MediaUploader/MediaUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ const MediaUploader = types.compose(
{file: file}
);

return fileResponse?.hash || null;
}),
uploadPlugin: flow(function* (file?: File) {
if (!file) {
return null;
}

const fileResponse: UploadFileResponse = yield self.fileRequest.send(
api.mediaRepository.uploadPlugin,
{file: file}
);

return fileResponse?.hash || null;
})
}))
Expand Down
51 changes: 35 additions & 16 deletions packages/app/src/core/models/ObjectAttribute/ObjectAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export const ObjectAttribute = types
response
);

if (self.request.isError) {
throw new Error(
'Error loading attribute: ' +
((response?.error as any)?.message || self.request.errorCode)
);
}

if (response) {
self._value = response;
}
Expand All @@ -49,30 +56,37 @@ export const ObjectAttribute = types
set: flow(function* (value: AttributeValueInterface) {
console.log('ObjectAttribute set:', value);

yield self.request.send(api.objectAttributeRepository.setObjectAttribute, {
const response = yield self.request.send(api.objectAttributeRepository.setObjectAttribute, {
objectId: self.objectId,
plugin_id: self.pluginId,
attribute_name: self.attributeName,
value
});

if (self.request.isError) {
throw new Error('Error setting attribute: ' + self.request.errorCode);
throw new Error(
'Error setting attribute: ' + (response?.error?.message || self.request.errorCode)
);
}

self._value = value;
}),
setItem: flow(function* (itemName: string, value: unknown) {
yield self.request.send(api.objectAttributeRepository.setObjectAttributeItem, {
objectId: self.objectId,
plugin_id: self.pluginId,
attribute_name: self.attributeName,
sub_attribute_key: itemName,
value
});
const response = yield self.request.send(
api.objectAttributeRepository.setObjectAttributeItem,
{
objectId: self.objectId,
plugin_id: self.pluginId,
attribute_name: self.attributeName,
sub_attribute_key: itemName,
value
}
);

if (self.request.isError) {
throw new Error('Error setting attribute item: ' + self.request.errorCode);
throw new Error(
'Error setting attribute item: ' + (response?.error?.message || self.request.errorCode)
);
}

if (self._value) {
Expand All @@ -82,14 +96,19 @@ export const ObjectAttribute = types
}
}),
delete: flow(function* () {
yield self.request.send(api.objectAttributeRepository.deleteObjectAttribute, {
objectId: self.objectId,
plugin_id: self.pluginId,
attribute_name: self.attributeName
});
const response = yield self.request.send(
api.objectAttributeRepository.deleteObjectAttribute,
{
objectId: self.objectId,
plugin_id: self.pluginId,
attribute_name: self.attributeName
}
);

if (self.request.isError) {
throw new Error('Error deleting attribute: ' + self.request.errorCode);
throw new Error(
'Error deleting attribute: ' + (response?.error?.message || self.request.errorCode)
);
}
})
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export const ObjectUserAttribute = types
);

console.log('[ObjectUserAttribute] load', params, 'resp:', response);
if (self.request.isError) {
throw new Error(
'Error loading attribute: ' +
((response?.error as any)?.message || self.request.errorCode)
);
}

if (response) {
self._value = response;
Expand All @@ -54,10 +60,16 @@ export const ObjectUserAttribute = types
value
};

yield self.request.send(api.objectUserAttributeRepository.setObjectUserAttribute, data);
const response = yield self.request.send(
api.objectUserAttributeRepository.setObjectUserAttribute,
data
);

if (self.request.isError) {
throw new Error('Error setting attribute: ' + self.request.errorCode);
throw new Error(
'Error setting attribute: ' +
((response?.error as any)?.message || self.request.errorCode)
);
}

self._value = value;
Expand All @@ -72,10 +84,15 @@ export const ObjectUserAttribute = types
sub_attribute_key: itemName,
sub_attribute_value: value
};
yield self.request.send(api.objectUserAttributeRepository.setObjectUserSubAttribute, data);
const response = yield self.request.send(
api.objectUserAttributeRepository.setObjectUserSubAttribute,
data
);

if (self.request.isError) {
throw new Error('Error setting attribute item: ' + self.request.errorCode);
throw new Error(
'Error setting attribute item: ' + (response?.error?.message || self.request.errorCode)
);
}

if (self._value) {
Expand All @@ -92,10 +109,15 @@ export const ObjectUserAttribute = types
attributeName: self.attributeName
};
console.log('[ObjectUserAttribute] delete', params);
yield self.request.send(api.objectUserAttributeRepository.deleteObjectUserAttribute, params);
const response = yield self.request.send(
api.objectUserAttributeRepository.deleteObjectUserAttribute,
params
);

if (self.request.isError) {
throw new Error('Error deleting attribute: ' + self.request.errorCode);
throw new Error(
'Error deleting attribute: ' + (response?.error?.message || self.request.errorCode)
);
}

self._value = null;
Expand All @@ -109,13 +131,15 @@ export const ObjectUserAttribute = types
sub_attribute_key: itemName
};
console.log('[ObjectUserAttribute] deleteItem', params);
yield self.request.send(
const response = yield self.request.send(
api.objectUserAttributeRepository.deleteObjectUserSubAttribute,
params
);

if (self.request.isError) {
throw new Error('Error deleting attribute item: ' + self.request.errorCode);
throw new Error(
'Error deleting attribute item: ' + (response?.error?.message || self.request.errorCode)
);
}
}),
countAllUsers: flow(function* () {
Expand All @@ -125,13 +149,19 @@ export const ObjectUserAttribute = types
attributeName: self.attributeName
};
console.log('[ObjectUserAttribute] countAllUsers', params);
const response: {count: number} = yield self.request.send(
const response: {count: number; error?: any} = yield self.request.send(
api.objectUserAttributeRepository.getObjectUserAttributeCount,
params
);

console.log('[ObjectUserAttribute] countAllUsers', params, 'resp:', response);

if (self.request.isError) {
throw new Error(
'Error counting users: ' + (response?.error?.message || self.request.errorCode)
);
}

self.count = response?.count || 0;

return response;
Expand Down Expand Up @@ -172,6 +202,12 @@ export const ObjectUserAttribute = types
}
);

if (self.request.isError) {
throw new Error(
'Error getting users: ' + ((response as any)?.error?.message || self.request.errorCode)
);
}

if (response) {
const {items, count} = response;
self.count = count;
Expand Down
Loading

0 comments on commit 9192ad5

Please sign in to comment.