From 81a92a5661ded2106c73674fcca741199e135798 Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Thu, 21 Dec 2023 12:12:17 +0800 Subject: [PATCH 1/5] feat: add HEAD method in the HTTP Request block(#1591) --- .../newtab/workflow/edit/EditWebhook.vue | 4 ++-- .../blocksHandler/handlerWebhook.js | 18 +++++++----------- src/workflowEngine/utils/webhookUtil.js | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/newtab/workflow/edit/EditWebhook.vue b/src/components/newtab/workflow/edit/EditWebhook.vue index 85d885c91..f41877f3a 100644 --- a/src/components/newtab/workflow/edit/EditWebhook.vue +++ b/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'); diff --git a/src/workflowEngine/blocksHandler/handlerWebhook.js b/src/workflowEngine/blocksHandler/handlerWebhook.js index 2d615cf22..8dc90be9e 100644 --- a/src/workflowEngine/blocksHandler/handlerWebhook.js +++ b/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 { diff --git a/src/workflowEngine/utils/webhookUtil.js b/src/workflowEngine/utils/webhookUtil.js index 5c3407e9e..f342c08c5 100644 --- a/src/workflowEngine/utils/webhookUtil.js +++ b/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, From 8aaabfc22dc57514dac403602aef49ff697038c9 Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Thu, 21 Dec 2023 15:09:21 +0800 Subject: [PATCH 2/5] feat: support full expression in conditions builder(#1596) --- src/stores/workflow.js | 2 +- .../templating/mustacheReplacer.js | 12 ++++++++++- src/workflowEngine/utils/testConditions.js | 20 ++++++++++++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/stores/workflow.js b/src/stores/workflow.js index b7b06a1ab..887e06da0 100644 --- a/src/stores/workflow.js +++ b/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, diff --git a/src/workflowEngine/templating/mustacheReplacer.js b/src/workflowEngine/templating/mustacheReplacer.js index fa7da730b..cd4a0a75f 100644 --- a/src/workflowEngine/templating/mustacheReplacer.js +++ b/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); diff --git a/src/workflowEngine/utils/testConditions.js b/src/workflowEngine/utils/testConditions.js index cabd6450e..3816c1e37 100644 --- a/src/workflowEngine/utils/testConditions.js +++ b/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); From 89964088e6d1c6fa9b9c0cfa27231fff876d3656 Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Fri, 22 Dec 2023 13:36:39 +0800 Subject: [PATCH 3/5] feat: support expression in variable name in the Insert Data block (#1598) --- src/workflowEngine/blocksHandler/handlerInsertData.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/workflowEngine/blocksHandler/handlerInsertData.js b/src/workflowEngine/blocksHandler/handlerInsertData.js index 312828f2d..e4f0bf428 100644 --- a/src/workflowEngine/blocksHandler/handlerInsertData.js +++ b/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); } } From 64f14ff301e0badc84c9bdde9d4fd695146c696f Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Fri, 22 Dec 2023 14:29:07 +0800 Subject: [PATCH 4/5] fix: eplaceTable param in javascript code block (#1597) --- src/workflowEngine/blocksHandler/handlerJavascriptCode.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/workflowEngine/blocksHandler/handlerJavascriptCode.js b/src/workflowEngine/blocksHandler/handlerJavascriptCode.js index 89d9a243c..16147ec1f 100644 --- a/src/workflowEngine/blocksHandler/handlerJavascriptCode.js +++ b/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); } From 3928ab1c83b62ab20ceee5e8997394e6ff237411 Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Fri, 22 Dec 2023 14:35:34 +0800 Subject: [PATCH 5/5] v1.28.25 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 939b12666..31167c9b5 100644 --- a/package.json +++ b/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",