From 9bd70b2616fc362bd6bbe530f269f7cd38b63fe4 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Tue, 21 May 2024 19:54:01 -0300 Subject: [PATCH] Refactor: move getCurlCode to apiModal folder --- .../modals/apiModal/utils/get-curl-code.tsx | 26 ++++++++++++++++++ .../src/modals/apiModal/views/index.tsx | 2 +- src/frontend/src/utils/utils.ts | 27 ------------------- 3 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 src/frontend/src/modals/apiModal/utils/get-curl-code.tsx diff --git a/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx b/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx new file mode 100644 index 000000000..9ae8ec48f --- /dev/null +++ b/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx @@ -0,0 +1,26 @@ +/** + * Function to get the curl code for the API + * @param {string} flowId - The id of the flow + * @param {boolean} isAuth - If the API is authenticated + * @returns {string} - The curl code + */ +export default function getCurlCode( + flowId: string, + isAuth: boolean, + tweaksBuildedObject, + ): string { + const tweaksObject = tweaksBuildedObject[0]; + + return `curl -X POST \\ + ${window.location.protocol}//${ + window.location.host + }/api/v1/run/${flowId}?stream=false \\ + -H 'Content-Type: application/json'\\${ + !isAuth ? `\n -H 'x-api-key: '\\` : "" + } + -d '{"input_value": "message", + "output_type": "chat", + "input_type": "chat", + "tweaks": ${JSON.stringify(tweaksObject, null, 2)}' + `; + } diff --git a/src/frontend/src/modals/apiModal/views/index.tsx b/src/frontend/src/modals/apiModal/views/index.tsx index 5165949ea..26b9d765f 100644 --- a/src/frontend/src/modals/apiModal/views/index.tsx +++ b/src/frontend/src/modals/apiModal/views/index.tsx @@ -14,7 +14,6 @@ import { TemplateVariableType } from "../../../types/api"; import { uniqueTweakType } from "../../../types/components"; import { FlowType } from "../../../types/flow/index"; import { - getCurlCode, getPythonCode, getWidgetCode, tabsArray, @@ -27,6 +26,7 @@ import { getChangesType } from "../utils/get-changes-types"; import { getNodesWithDefaultValue } from "../utils/get-nodes-with-default-value"; import { getValue } from "../utils/get-value"; import getPythonApiCode from "../utils/get-python-api-code"; +import getCurlCode from "../utils/get-curl-code"; const ApiModal = forwardRef( ( diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 276585b18..7bd08208d 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -141,33 +141,6 @@ export function getChatInputField(flowState?: FlowState) { return chat_input_field; } -/** - * Function to get the curl code for the API - * @param {string} flowId - The id of the flow - * @param {boolean} isAuth - If the API is authenticated - * @returns {string} - The curl code - */ -export function getCurlCode( - flowId: string, - isAuth: boolean, - tweaksBuildedObject, -): string { - const tweaksObject = tweaksBuildedObject[0]; - - return `curl -X POST \\ - ${window.location.protocol}//${ - window.location.host - }/api/v1/run/${flowId}?stream=false \\ - -H 'Content-Type: application/json'\\${ - !isAuth ? `\n -H 'x-api-key: '\\` : "" - } - -d '{"input_value": "message", - "output_type": "chat", - "input_type": "chat", - "tweaks": ${JSON.stringify(tweaksObject, null, 2)}' - `; -} - export function getOutputIds(flow) { const nodes = flow.data!.nodes;