Browse Source

feat: allow disable timeout in HTTP Request block

Ahmad Kholid 2 years ago
parent
commit
35073db9b8

+ 4 - 1
src/components/newtab/workflow/edit/EditWebhook.vue

@@ -45,7 +45,10 @@
     </ui-select>
     <ui-input
       :model-value="data.timeout"
-      :label="t('workflow.blocks.webhook.timeout.placeholder')"
+      :label="
+        t('workflow.blocks.webhook.timeout.placeholder') +
+        ` (${t('common.0disable')})`
+      "
       :title="t('workflow.blocks.webhook.timeout.title')"
       class="mb-2 w-full"
       type="number"

+ 2 - 1
src/locales/en/common.json

@@ -43,7 +43,8 @@
     "duplicate": "Duplicate",
     "password": "Password",
     "category": "Category",
-    "optional": "Optional"
+    "optional": "Optional",
+    "0disable": "0 to disable"
   },
   "message": {
     "noBlock": "No block",

+ 13 - 7
src/workflowEngine/utils/webhookUtil.js

@@ -89,10 +89,15 @@ export async function executeWebhook({
   body,
   method,
 }) {
-  const controller = new AbortController();
-  const timeoutId = setTimeout(() => {
-    controller.abort();
-  }, timeout);
+  let timeoutId = null;
+  let controller = null;
+
+  if (timeout > 0) {
+    controller = new AbortController();
+    timeoutId = setTimeout(() => {
+      controller.abort();
+    }, timeout);
+  }
 
   try {
     const finalHeaders = filterHeaders(headers);
@@ -102,8 +107,8 @@ export async function executeWebhook({
     const payload = {
       headers: finalHeaders,
       method: method || 'POST',
-      signal: controller.signal,
     };
+    if (controller) payload.signal = controller.signal;
 
     if (!notHaveBody.includes(method || 'POST') && !isWhitespace(body)) {
       payload.body = await renderContent(body, contentType);
@@ -111,11 +116,12 @@ export async function executeWebhook({
 
     const response = await fetch(url, payload);
 
-    clearTimeout(timeoutId);
+    if (timeoutId) clearTimeout(timeoutId);
 
     return response;
   } catch (error) {
-    clearTimeout(timeoutId);
+    if (timeoutId) clearTimeout(timeoutId);
+
     throw error;
   }
 }