mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-10 14:22:53 +01:00
feat: Command, add and use Cloud Service (#95)
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { CloudService } from '@noodl-models/CloudServices';
|
||||
import { ProjectModel } from '@noodl-models/projectmodel';
|
||||
import { setCloudServices } from '@noodl-models/projectmodel.editor';
|
||||
|
||||
import { ToastLayer } from '../../../views/ToastLayer';
|
||||
|
||||
export type Command = {
|
||||
kind: 'cloud-service';
|
||||
use?: boolean;
|
||||
|
||||
name: string;
|
||||
description?: string;
|
||||
endpoint: string;
|
||||
appId: string;
|
||||
masterKey: string;
|
||||
};
|
||||
|
||||
export async function execute(command: Command, _event: MessageEvent) {
|
||||
const environment = await getOrCreate(command);
|
||||
|
||||
if (command.use) {
|
||||
setCloudServices(ProjectModel.instance, environment);
|
||||
}
|
||||
}
|
||||
|
||||
async function getOrCreate(command: Command) {
|
||||
const cloudServices = await CloudService.instance.backend.fetch();
|
||||
const environment = cloudServices.find((c) => c.url === command.endpoint);
|
||||
if (environment) {
|
||||
if (
|
||||
environment.name !== command.name ||
|
||||
environment.description !== command.description ||
|
||||
environment.appId !== command.appId ||
|
||||
environment.masterKey !== command.masterKey
|
||||
) {
|
||||
await CloudService.instance.backend.update({
|
||||
id: environment.id,
|
||||
url: environment.url,
|
||||
|
||||
// Update the existing environment
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
appId: command.appId,
|
||||
masterKey: command.masterKey
|
||||
});
|
||||
|
||||
ToastLayer.showSuccess(`Cloud service "${command.name}" updated.`);
|
||||
}
|
||||
|
||||
return {
|
||||
id: environment.id,
|
||||
endpoint: environment.url,
|
||||
appId: command.appId
|
||||
};
|
||||
} else {
|
||||
const create = await CloudService.instance.backend.create({
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
appId: command.appId,
|
||||
url: command.endpoint,
|
||||
masterKey: command.masterKey
|
||||
});
|
||||
|
||||
ToastLayer.showSuccess(`Cloud service "${command.name}" added successfully.`);
|
||||
|
||||
return {
|
||||
id: create.id,
|
||||
endpoint: create.url,
|
||||
appId: create.appId
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import * as CloudService from './commands/cloud-service';
|
||||
import * as Notify from './commands/notify';
|
||||
import * as UploadAwsS3 from './commands/upload-aws-s3';
|
||||
|
||||
type IFrameCommand = Notify.Command | UploadAwsS3.Command;
|
||||
type IFrameCommand = Notify.Command | UploadAwsS3.Command | CloudService.Command;
|
||||
|
||||
const commands: Record<IFrameCommand['kind'], (command: IFrameCommand, event: MessageEvent) => Promise<void>> = {
|
||||
notify: Notify.execute,
|
||||
'upload-aws-s3': UploadAwsS3.execute
|
||||
'upload-aws-s3': UploadAwsS3.execute,
|
||||
'cloud-service': CloudService.execute
|
||||
};
|
||||
|
||||
export function commandEventHandler(event: MessageEvent) {
|
||||
|
||||
@@ -6,8 +6,6 @@ import { CloudService } from '@noodl-models/CloudServices';
|
||||
import { ActivityIndicator } from '@noodl-core-ui/components/common/ActivityIndicator';
|
||||
import { IconName, IconSize } from '@noodl-core-ui/components/common/Icon';
|
||||
import { IconButton } from '@noodl-core-ui/components/inputs/IconButton';
|
||||
import { PrimaryButton } from '@noodl-core-ui/components/inputs/PrimaryButton';
|
||||
import { Box } from '@noodl-core-ui/components/layout/Box';
|
||||
import { ConditionalContainer } from '@noodl-core-ui/components/layout/ConditionalContainer';
|
||||
import { Container } from '@noodl-core-ui/components/layout/Container';
|
||||
import { VStack } from '@noodl-core-ui/components/layout/Stack';
|
||||
|
||||
Reference in New Issue
Block a user