Przeglądaj źródła

feat: support base64 in HTTP Request block

Ahmad Kholid 2 lat temu
rodzic
commit
45bf401135

+ 2 - 5
src/components/newtab/workflow/edit/EditWebhook.vue

@@ -86,11 +86,7 @@
             <v-remixicon name="riCloseCircleLine" size="20" />
           </button>
         </template>
-        <ui-button
-          class="col-span-4 mt-4 block w-full"
-          variant="accent"
-          @click="addHeader"
-        >
+        <ui-button class="col-span-4 mt-4 block w-full" @click="addHeader">
           <span> {{ t('workflow.blocks.webhook.buttons.header') }} </span>
         </ui-button>
       </ui-tab-panel>
@@ -111,6 +107,7 @@
         >
           <option value="json">JSON</option>
           <option value="text">Text</option>
+          <option value="base64">Base64</option>
         </ui-select>
         <ui-input
           v-if="data.responseType === 'json'"

+ 16 - 1
src/newtab/workflowEngine/blocksHandler/handlerWebhook.js

@@ -3,6 +3,16 @@ import { isWhitespace } from '@/utils/helper';
 import { executeWebhook } from '@/utils/webhookUtil';
 import renderString from '../templating/renderString';
 
+function fileReader(blob) {
+  return new Promise((resolve) => {
+    const reader = new FileReader();
+    reader.onload = () => {
+      resolve(reader.result);
+    };
+    reader.readAsDataURL(blob);
+  });
+}
+
 export async function webhook({ data, id }, { refData }) {
   const nextBlockId = this.getBlockConnections(id);
   const fallbackOutput = this.getBlockConnections(id, 'fallback');
@@ -47,8 +57,13 @@ export async function webhook({ data, id }, { refData }) {
 
     if (data.responseType === 'json') {
       const jsonRes = await response.json();
-
       returnData = objectPath.get(jsonRes, data.dataPath);
+    } else if (data.responseType === 'base64') {
+      const blob = await response.blob();
+      const base64 = await fileReader(blob);
+
+      console.log(base64);
+      returnData = base64;
     } else {
       returnData = await response.text();
     }