Ahmad Kholid il y a 1 an
Parent
commit
697282878c

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "automa",
-  "version": "1.28.24",
+  "version": "1.28.25",
   "description": "An extension for automating your browser by connecting blocks",
   "repository": {
     "type": "git",

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

@@ -173,8 +173,8 @@ const emit = defineEmits(['update:data']);
 
 const { t } = useI18n();
 
-const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
-const notHaveBody = ['GET'];
+const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'];
+const notHaveBody = ['GET', 'HEAD'];
 const copyHeaders = JSON.parse(JSON.stringify(props.data.headers));
 
 const activeTab = ref('headers');

+ 1 - 1
src/stores/workflow.js

@@ -47,7 +47,7 @@ const defaultWorkflow = (data = null, options = {}) => {
     settings: {
       publicId: '',
       blockDelay: 0,
-      saveLog: true,
+      saveLog: false,
       debugMode: false,
       restartTimes: 3,
       notification: true,

+ 6 - 1
src/workflowEngine/blocksHandler/handlerInsertData.js

@@ -81,7 +81,12 @@ async function insertData({ id, data }, { refData }) {
         this.addDataToColumn(item.name, tableValue);
       });
     } else {
-      await this.setVariable(item.name, value);
+      const variableName = await renderString(
+        item.name,
+        refData,
+        this.engine.isPopup
+      );
+      await this.setVariable(variableName.value, value);
     }
   }
 

+ 6 - 1
src/workflowEngine/blocksHandler/handlerJavascriptCode.js

@@ -257,7 +257,12 @@ export async function javascriptCode({ outputs, data, ...block }, { refData }) {
           ? columnDataObj
           : [columnDataObj];
 
-        if (replaceTable) this.engine.referenceData.table = [];
+        if (replaceTable) {
+          this.engine.referenceData.table = [];
+          Object.keys(this.engine.columns).forEach((key) => {
+            this.engine.columns[key].index = 0;
+          });
+        }
 
         this.addDataToColumn(params);
       }

+ 7 - 11
src/workflowEngine/blocksHandler/handlerWebhook.js

@@ -3,16 +3,6 @@ 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);
-  });
-}
-
 const ALL_HTTP_RESPONSE_KEYWORD = '$response';
 
 export async function webhook({ data, id }, { refData }) {
@@ -83,7 +73,13 @@ export async function webhook({ data, id }, { refData }) {
       }
     } else if (data.responseType === 'base64') {
       const blob = await response.blob();
-      const base64 = await fileReader(blob);
+      const base64 = await new Promise((resolve) => {
+        const reader = new FileReader();
+        reader.onload = () => {
+          resolve(reader.result);
+        };
+        reader.readAsDataURL(blob);
+      });
 
       returnData = base64;
     } else {

+ 11 - 1
src/workflowEngine/templating/mustacheReplacer.js

@@ -63,7 +63,14 @@ export function keyParser(key, data) {
 
 function replacer(
   str,
-  { regex, tagLen, modifyPath, data, disableStringify = false }
+  {
+    data,
+    regex,
+    tagLen,
+    modifyPath,
+    checkExistence = false,
+    disableStringify = false,
+  }
 ) {
   const replaceResult = {
     list: {},
@@ -106,6 +113,8 @@ function replacer(
         dataKey = dataKey.slice(1);
       }
 
+      if (checkExistence) return objectPath.has(data[dataKey], path);
+
       result = objectPath.get(data[dataKey], path);
       if (typeof result === 'undefined') result = match;
 
@@ -144,6 +153,7 @@ export default function (str, refData, options = {}) {
         tagLen: 1,
         regex: /\[(.*?)\]/g,
         ...options,
+        checkExistence: false,
       });
       Object.assign(replacedList, list);
 

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

@@ -1,9 +1,7 @@
 import cloneDeep from 'lodash.clonedeep';
-import objectPath from 'object-path';
 import { parseJSON } from '@/utils/helper';
 import { conditionBuilder } from '@/utils/shared';
 import renderString from '../templating/renderString';
-import { keyParser } from '../templating/mustacheReplacer';
 
 const isBoolStr = (str) => {
   if (str === 'true') return true;
@@ -56,14 +54,22 @@ export default async function (conditionsArr, workflowData) {
       const isInsideBrackets =
         dataPath.startsWith('{{') && dataPath.endsWith('}}');
 
-      if (isInsideBrackets) {
-        dataPath = dataPath.slice(2, -2).trim();
+      if (!isInsideBrackets) {
+        dataPath = `{{${dataPath}}}`;
       }
 
-      const parsedPath = keyParser(dataPath, workflowData.refData);
-      dataPath = `${parsedPath.dataKey}.${parsedPath.path}`;
+      let dataExists = await renderString(
+        dataPath,
+        workflowData.refData,
+        workflowData.isPopup,
+        {
+          checkExistence: true,
+        }
+      );
+      // It return string for some reason
+      dataExists = Boolean(parseJSON(dataExists.value, false));
 
-      return objectPath.has(workflowData.refData, dataPath);
+      return dataExists;
     }
 
     const copyData = cloneDeep(data);

+ 1 - 1
src/workflowEngine/utils/webhookUtil.js

@@ -79,7 +79,7 @@ const contentTypes = {
   'form-data': 'multipart/form-data',
   form: 'application/x-www-form-urlencoded',
 };
-const notHaveBody = ['GET', 'DELETE'];
+const notHaveBody = ['GET', 'HEAD'];
 
 export async function executeWebhook({
   url,