fix: http variable (#3585)

This commit is contained in:
Archer
2025-01-14 13:45:45 +08:00
committed by GitHub
parent 781fd45e39
commit 05a357dffe

View File

@@ -100,10 +100,9 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
const concatVariables = { const concatVariables = {
...variables, ...variables,
...body, ...body,
// ...dynamicInput,
...systemVariables ...systemVariables
}; };
const allVariables = { const allVariables: Record<string, any> = {
[NodeInputKeyEnum.addInputParam]: concatVariables, [NodeInputKeyEnum.addInputParam]: concatVariables,
...concatVariables ...concatVariables
}; };
@@ -135,19 +134,11 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
return String(val); return String(val);
}; };
// 1. Replace {{key}} variables // 1. Replace {{key.key}} variables
const regex1 = /{{([^}]+)}}/g; const regex1 = /\{\{\$([^.]+)\.([^$]+)\$\}\}/g;
const matches1 = text.match(regex1) || []; const matches1 = [...text.matchAll(regex1)];
const uniqueKeys1 = [...new Set(matches1.map((match) => match.slice(2, -2)))]; if (matches1.length === 0) return text;
for (const key of uniqueKeys1) { matches1.forEach((match) => {
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), () => valToStr(variables[key]));
}
// 2. Replace {{key.key}} variables
const regex2 = /\{\{\$([^.]+)\.([^$]+)\$\}\}/g;
const matches2 = [...text.matchAll(regex2)];
if (matches2.length === 0) return text;
matches2.forEach((match) => {
const nodeId = match[1]; const nodeId = match[1];
const id = match[2]; const id = match[2];
@@ -173,6 +164,14 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
text = text.replace(regex, () => formatVal); text = text.replace(regex, () => formatVal);
}); });
// 2. Replace {{key}} variables
const regex2 = /{{([^}]+)}}/g;
const matches2 = text.match(regex2) || [];
const uniqueKeys2 = [...new Set(matches2.map((match) => match.slice(2, -2)))];
for (const key of uniqueKeys2) {
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), () => valToStr(allVariables[key]));
}
return text.replace(/(".*?")\s*:\s*undefined\b/g, '$1: null'); return text.replace(/(".*?")\s*:\s*undefined\b/g, '$1: null');
}; };