Explorar o código

refactor modal

itizawa %!s(int64=4) %!d(string=hai) anos
pai
achega
6219bf2840

+ 22 - 8
packages/slackbot-proxy/src/middlewares/slack-to-growi/extract-growi-uri-from-req.ts

@@ -3,23 +3,37 @@ import {
 } from '@tsed/common';
 } from '@tsed/common';
 import { SlackOauthReq } from '~/interfaces/slack-to-growi/slack-oauth-req';
 import { SlackOauthReq } from '~/interfaces/slack-to-growi/slack-oauth-req';
 import { DelegatorType, factory as GrowiUriInjectorFactory } from '~/services/growi-uri-injector';
 import { DelegatorType, factory as GrowiUriInjectorFactory } from '~/services/growi-uri-injector';
+import { growiUriInjectionModalDelegator } from '~/services/growi-uri-injector/GrowiUriInjectionModalDelegator';
 
 
 @Middleware()
 @Middleware()
 export class ExtractGrowiUriFromReq implements IMiddleware {
 export class ExtractGrowiUriFromReq implements IMiddleware {
 
 
   use(@Req() req: Req & SlackOauthReq, @Res() res: Res, @Next() next: Next): void {
   use(@Req() req: Req & SlackOauthReq, @Res() res: Res, @Next() next: Next): void {
 
 
-    // break when uri is found
-    for (const type of Object.values(DelegatorType)) {
-      const growiUriInjector = GrowiUriInjectorFactory.getDelegator(type);
-      const { growiUri } = growiUriInjector.extract(req.body);
-      if (growiUri != null) {
-        req.growiUri = growiUri;
-        break;
+    const payload = JSON.parse(req.body.payload);
+
+    if (payload.view != null) {
+      const parsedValues = growiUriInjectionModalDelegator.extract(payload);
+      req.growiUri = parsedValues.growiUri;
+      payload.view.private_metadata = parsedValues.originalData;
+    }
+    else {
+      // break when uri is found
+      for (const type of Object.values(DelegatorType)) {
+        const growiUriInjector = GrowiUriInjectorFactory.getDelegator(type);
+        const parsedValues = growiUriInjector.extract(payload);
+        if (parsedValues.growiUri != null) {
+          req.growiUri = parsedValues.growiUri;
+          break;
+        }
+        console.log(22, parsedValues);
+
       }
       }
     }
     }
 
 
-    next();
+    req.body.payload = JSON.stringify(payload);
+
+    return next();
   }
   }
 
 
 }
 }

+ 2 - 0
packages/slackbot-proxy/src/services/growi-uri-injector/GrowiUriInjectionModalDelegator.ts

@@ -28,3 +28,5 @@ export class GrowiUriInjectionModalDelegator implements GrowiUriInjector {
   }
   }
 
 
 }
 }
+
+export const growiUriInjectionModalDelegator = new GrowiUriInjectionModalDelegator();

+ 0 - 3
packages/slackbot-proxy/src/services/growi-uri-injector/index.ts

@@ -1,15 +1,12 @@
 import { GrowiUriInjector } from './GrowiUriInjector';
 import { GrowiUriInjector } from './GrowiUriInjector';
-import { GrowiUriInjectionModalDelegator } from './GrowiUriInjectionModalDelegator';
 import { GrowiUriInjectionButtonDelegator } from './GrowiUriInjectionButtonDelegator';
 import { GrowiUriInjectionButtonDelegator } from './GrowiUriInjectionButtonDelegator';
 
 
 export const DelegatorType = {
 export const DelegatorType = {
-  MODAL: 'modal',
   BUTTON: 'button',
   BUTTON: 'button',
 } as const;
 } as const;
 export type DelegatorType = typeof DelegatorType[keyof typeof DelegatorType];
 export type DelegatorType = typeof DelegatorType[keyof typeof DelegatorType];
 
 
 const TypeToDelegatorMappings:{[key in DelegatorType]:GrowiUriInjector} = {
 const TypeToDelegatorMappings:{[key in DelegatorType]:GrowiUriInjector} = {
-  [DelegatorType.MODAL]: new GrowiUriInjectionModalDelegator(),
   [DelegatorType.BUTTON]: new GrowiUriInjectionButtonDelegator(),
   [DelegatorType.BUTTON]: new GrowiUriInjectionButtonDelegator(),
 };
 };