Skip to content

Commit

Permalink
v1.28.25
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Dec 23, 2023
2 parents c12f395 + 3928ab1 commit 6972828
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/components/newtab/workflow/edit/EditWebhook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/stores/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const defaultWorkflow = (data = null, options = {}) => {
settings: {
publicId: '',
blockDelay: 0,
saveLog: true,
saveLog: false,
debugMode: false,
restartTimes: 3,
notification: true,
Expand Down
7 changes: 6 additions & 1 deletion src/workflowEngine/blocksHandler/handlerInsertData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/workflowEngine/blocksHandler/handlerJavascriptCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 7 additions & 11 deletions src/workflowEngine/blocksHandler/handlerWebhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion src/workflowEngine/templating/mustacheReplacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -144,6 +153,7 @@ export default function (str, refData, options = {}) {
tagLen: 1,
regex: /\[(.*?)\]/g,
...options,
checkExistence: false,
});
Object.assign(replacedList, list);

Expand Down
20 changes: 13 additions & 7 deletions src/workflowEngine/utils/testConditions.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/workflowEngine/utils/webhookUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6972828

Please sign in to comment.