Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
05a357df
authored
Jan 14, 2025
by
Archer
Committed by
GitHub
Jan 14, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: http variable (#3585)
parent
781fd45e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
15 deletions
+14
-15
packages/service/core/workflow/dispatch/tools/http468.ts
+14
-15
No files found.
packages/service/core/workflow/dispatch/tools/http468.ts
View file @
05a357df
...
...
@@ -100,10 +100,9 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
const
concatVariables
=
{
...
variables
,
...
body
,
// ...dynamicInput,
...
systemVariables
};
const
allVariables
=
{
const
allVariables
:
Record
<
string
,
any
>
=
{
[
NodeInputKeyEnum
.
addInputParam
]:
concatVariables
,
...
concatVariables
};
...
...
@@ -135,19 +134,11 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
return
String
(
val
);
};
// 1. Replace {{key}} variables
const
regex1
=
/{{
([^
}
]
+
)
}}/g
;
const
matches1
=
text
.
match
(
regex1
)
||
[];
const
uniqueKeys1
=
[...
new
Set
(
matches1
.
map
((
match
)
=>
match
.
slice
(
2
,
-
2
)))];
for
(
const
key
of
uniqueKeys1
)
{
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
)
=>
{
// 1. Replace {{key.key}} variables
const
regex1
=
/
\{\{\$([^
.
]
+
)\.([^
$
]
+
)\$\}\}
/g
;
const
matches1
=
[...
text
.
matchAll
(
regex1
)];
if
(
matches1
.
length
===
0
)
return
text
;
matches1
.
forEach
((
match
)
=>
{
const
nodeId
=
match
[
1
];
const
id
=
match
[
2
];
...
...
@@ -173,6 +164,14 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
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'
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment