Przeglądaj źródła

request only one growi

itizawa 4 lat temu
rodzic
commit
758d30499e
1 zmienionych plików z 13 dodań i 18 usunięć
  1. 13 18
      packages/slackbot-proxy/src/controllers/slack.ts

+ 13 - 18
packages/slackbot-proxy/src/controllers/slack.ts

@@ -211,36 +211,31 @@ export class SlackCtrl {
     }
 
     /*
-     * forward to GROWI server
-     */
-    let relations = await this.relationRepository.find({ installation });
+    * forward to GROWI server
+    */
 
+    let growiUri;
     // For Modal, Send request to only one GROWI
     if (payload.view != null) {
-      const { growiUri } = JSON.parse(payload.view.private_metadata);
-      relations = relations.filter(relation => relation.growiUri === growiUri);
+      growiUri = JSON.parse(payload.view.private_metadata).growiUri;
     }
 
-    const promises = relations.map((relation: Relation) => {
+    const relation = await this.relationRepository.findOne({ installation, growiUri });
+
+    if (relation == null) {
+      return;
+    }
+
+    try {
       // generate API URL
-      const url = new URL('/_api/v3/slack-integration/proxied/interactions', relation.growiUri);
-      return axios.post(url.toString(), {
+      const url = new URL('/_api/v3/slack-integration/proxied/interactions', growiUri);
+      await axios.post(url.toString(), {
         ...body,
       }, {
         headers: {
           'x-growi-ptog-tokens': relation.tokenPtoG,
         },
       });
-    });
-
-    // pickup PromiseRejectedResult only
-    const results = await Promise.allSettled(promises);
-    const rejectedResults: PromiseRejectedResult[] = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected');
-    const botToken = installation?.data.bot?.token;
-
-    try {
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      return postEphemeralErrors(rejectedResults, body.channel_id, body.user_id, botToken!);
     }
     catch (err) {
       logger.error(err);