From 01ea9222b8c287724bf35ea9ec24889b129fd135 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Thu, 14 Mar 2024 18:25:16 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20(utils.ts):=20add=20support=20fo?= =?UTF-8?q?r=20retrieving=20output=20IDs=20from=20flow=20data=20to=20inclu?= =?UTF-8?q?de=20in=20the=20curl=20code=20=F0=9F=93=9D=20(utils.ts):=20upda?= =?UTF-8?q?te=20getCurlCode=20function=20to=20include=20the=20arrayOfOutpu?= =?UTF-8?q?ts=20in=20the=20curl=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/utils.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index eda9a2707..35326a456 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -381,16 +381,39 @@ export function getCurlCode( const tweaks = buildTweaks(flow); const inputs = buildInputs(); + const arrayOfOutputs = getOutputIds(flow); + return `curl -X POST \\ ${window.location.protocol}//${window.location.host}/api/v1/run/${flowId} \\ -H 'Content-Type: application/json'\\${ !isAuth ? `\n -H 'x-api-key: '\\` : "" } - -d '{"inputs": [${inputs}], "tweaks": ${ + -d '{"inputs": [${inputs}], + "outputs": [${arrayOfOutputs}], + "stream": false, + "tweaks": ${ tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2) - }}'`; + }}' + `; +} + +export function getOutputIds(flow) { + const nodes = flow.data!.nodes; + + const arrayOfOutputs = nodes.reduce((acc: string[], node) => { + if (node.data.type.toLowerCase().includes("output")) { + acc.push(node.id); + } + return acc; + }, []); + + const arrayOfOutputsJoin = arrayOfOutputs + .map((output) => `"${output}"`) + .join(", "); + + return arrayOfOutputsJoin; } /**