kaori 4 лет назад
Родитель
Сommit
a4aae0e84d

+ 1 - 6
packages/slackbot-proxy/src/controllers/slack.ts

@@ -187,12 +187,7 @@ export class SlackCtrl {
 
     // register
     if (callBackId === 'register') {
-      const insertOrderResults = await this.registerService.insertOrderRecord(this.orderRepository, installation, authorizeResult, payload);
-
-      if (insertOrderResults != null && insertOrderResults.error != null) {
-        return;
-      }
-
+      await this.registerService.insertOrderRecord(this.orderRepository, installation, authorizeResult, payload);
       await this.registerService.notifyServerUriToSlack(authorizeResult, payload);
       return;
     }

+ 9 - 6
packages/slackbot-proxy/src/services/RegisterService.ts

@@ -58,11 +58,7 @@ export class RegisterService implements GrowiCommandProcessor {
 
     const client = new WebClient(botToken, { logLevel: isProduction ? LogLevel.DEBUG : LogLevel.INFO });
 
-    const isUrl = (url: string) => {
-      return url.match(/^(https?:\/\/)/);
-    };
-
-    if (isUrl(growiUrl) == null) {
+    const postInvalidUrlErr = async() => {
       const invalidErrorMsg = 'Please enter a valid URL';
 
       await client.chat.postEphemeral({
@@ -75,7 +71,14 @@ export class RegisterService implements GrowiCommandProcessor {
           generateMarkdownSectionBlock(invalidErrorMsg),
         ],
       });
-      return { error: invalidErrorMsg };
+    };
+
+    try {
+      const url = new URL(growiUrl);
+      return url;
+    }
+    catch (err) {
+      postInvalidUrlErr();
     }
 
     orderRepository.save({