|
@@ -19,7 +19,7 @@ import { OrderRepository } from '~/repositories/order';
|
|
|
import { InstallerService } from '~/services/InstallerService';
|
|
import { InstallerService } from '~/services/InstallerService';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
import { ViewInteractionPayloadDelegator } from '~/services/growi-uri-injector/ViewInteractionPayloadDelegator';
|
|
import { ViewInteractionPayloadDelegator } from '~/services/growi-uri-injector/ViewInteractionPayloadDelegator';
|
|
|
-import { BlockActionsPayloadDelegator } from '~/services/growi-uri-injector/BlockActionsPayloadDelegator';
|
|
|
|
|
|
|
+import { ActionsBlockPayloadDelegator } from '~/services/growi-uri-injector/ActionsBlockPayloadDelegator';
|
|
|
import { BlockElement, ViewElement } from '~/interfaces/growi-uri-injector';
|
|
import { BlockElement, ViewElement } from '~/interfaces/growi-uri-injector';
|
|
|
|
|
|
|
|
|
|
|
|
@@ -43,6 +43,12 @@ export class GrowiToSlackCtrl {
|
|
|
@Inject()
|
|
@Inject()
|
|
|
orderRepository: OrderRepository;
|
|
orderRepository: OrderRepository;
|
|
|
|
|
|
|
|
|
|
+ @Inject()
|
|
|
|
|
+ viewInteractionPayloadDelegator: ViewInteractionPayloadDelegator;
|
|
|
|
|
+
|
|
|
|
|
+ @Inject()
|
|
|
|
|
+ actionsBlockPayloadDelegator: ActionsBlockPayloadDelegator;
|
|
|
|
|
+
|
|
|
async requestToGrowi(growiUrl:string, tokenPtoG:string):Promise<void> {
|
|
async requestToGrowi(growiUrl:string, tokenPtoG:string):Promise<void> {
|
|
|
const url = new URL('/_api/v3/slack-integration/proxied/commands', growiUrl);
|
|
const url = new URL('/_api/v3/slack-integration/proxied/commands', growiUrl);
|
|
|
await axios.post(url.toString(), {
|
|
await axios.post(url.toString(), {
|
|
@@ -174,53 +180,20 @@ export class GrowiToSlackCtrl {
|
|
|
|
|
|
|
|
injectGrowiUri(req: GrowiReq, growiUri: string):WebAPICallOptions {
|
|
injectGrowiUri(req: GrowiReq, growiUri: string):WebAPICallOptions {
|
|
|
|
|
|
|
|
- // TODO: get list from decorator
|
|
|
|
|
- const vipDelegators: ViewInteractionPayloadDelegator[] = [new ViewInteractionPayloadDelegator()];
|
|
|
|
|
- const bapDelegators: BlockActionsPayloadDelegator[] = [];
|
|
|
|
|
-
|
|
|
|
|
const parsedView = JSON.parse(req.body.view) as ViewElement;
|
|
const parsedView = JSON.parse(req.body.view) as ViewElement;
|
|
|
const parsedBlocks = JSON.parse(req.body.blocks) as BlockElement[];
|
|
const parsedBlocks = JSON.parse(req.body.blocks) as BlockElement[];
|
|
|
|
|
|
|
|
- vipDelegators.forEach((delegator) => {
|
|
|
|
|
- if (delegator.shouldHandleToInject(parsedView)) {
|
|
|
|
|
- delegator.inject(parsedView, growiUri);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- req.body.view = JSON.stringify(parsedView);
|
|
|
|
|
-
|
|
|
|
|
- // bapDelegators.forEach((delegator) => {
|
|
|
|
|
- // if (delegator.shouldHandleToInject(parsedBlocks)) {
|
|
|
|
|
- // delegator.inject(parsedBlocks, growiUri);
|
|
|
|
|
- // }
|
|
|
|
|
- // });
|
|
|
|
|
- // req.body.blocks = JSON.stringify(parsedBlocks);
|
|
|
|
|
-
|
|
|
|
|
- // const vipd = new ViewInteractionPayloadDelegator();
|
|
|
|
|
- // if (vipd.shouldHandleToInject(req)) {
|
|
|
|
|
- // vipd.inject(req.body, growiUri);
|
|
|
|
|
- // }
|
|
|
|
|
- // else if (req.body.blocks != null) {
|
|
|
|
|
- // const parsedBlocks = JSON.parse(req.body.blocks) as any[];
|
|
|
|
|
- // req.parsedBlocks = parsedBlocks;
|
|
|
|
|
-
|
|
|
|
|
- // // TODO: iterate with decorator
|
|
|
|
|
-
|
|
|
|
|
- // parsedBlocks.forEach((parsedBlock) => {
|
|
|
|
|
- // if (parsedBlock.type !== 'actions') {
|
|
|
|
|
- // return;
|
|
|
|
|
- // }
|
|
|
|
|
- // parsedBlock.elements.forEach((element) => {
|
|
|
|
|
- // const growiUriInjector = findInjectorByType(element.type);
|
|
|
|
|
- // if (growiUriInjector != null) {
|
|
|
|
|
- // growiUriInjector.inject(element, growiUri);
|
|
|
|
|
- // }
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- // return;
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- // req.body.blocks = JSON.stringify(parsedBlocks);
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ // delegate to ViewInteractionPayloadDelegator
|
|
|
|
|
+ if (this.viewInteractionPayloadDelegator.shouldHandleToInject(parsedView)) {
|
|
|
|
|
+ this.viewInteractionPayloadDelegator.inject(parsedView, growiUri);
|
|
|
|
|
+ req.body.view = JSON.stringify(parsedView);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // delegate to ActionsBlockPayloadDelegator
|
|
|
|
|
+ if (this.actionsBlockPayloadDelegator.shouldHandleToInject(parsedBlocks)) {
|
|
|
|
|
+ this.actionsBlockPayloadDelegator.inject(parsedBlocks, growiUri);
|
|
|
|
|
+ req.body.blocks = JSON.stringify(parsedBlocks);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const opt = req.body;
|
|
const opt = req.body;
|
|
|
opt.headers = req.headers;
|
|
opt.headers = req.headers;
|