📝 (utils.ts): add support for retrieving output IDs from flow data to include in the curl code

📝 (utils.ts): update getCurlCode function to include the arrayOfOutputs in the curl code
This commit is contained in:
cristhianzl 2024-03-14 18:25:16 -03:00
commit 01ea9222b8

View file

@ -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: <your 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;
}
/**