mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-26 15:54:11 +00:00
fix: http variable (#3585)
This commit is contained in:
@@ -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');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user