From 0ae6c23dc902f49f7c79e557c8b28b6f3ea18971 Mon Sep 17 00:00:00 2001 From: Faran Javed Date: Mon, 23 Jun 2025 16:29:41 +0500 Subject: [PATCH 1/6] console log curl to json --- client/packages/lowcoder/package.json | 1 + .../lowcoder/src/components/CurlImport.tsx | 90 +++++++++++++++++++ .../src/components/ResCreatePanel.tsx | 24 +++++ client/yarn.lock | 12 ++- 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 client/packages/lowcoder/src/components/CurlImport.tsx diff --git a/client/packages/lowcoder/package.json b/client/packages/lowcoder/package.json index e838c870d..7137e23b6 100644 --- a/client/packages/lowcoder/package.json +++ b/client/packages/lowcoder/package.json @@ -7,6 +7,7 @@ "types": "src/index.sdk.ts", "dependencies": { "@ant-design/icons": "^5.3.0", + "@bany/curl-to-json": "^1.2.8", "@codemirror/autocomplete": "^6.11.1", "@codemirror/commands": "^6.3.2", "@codemirror/lang-css": "^6.2.1", diff --git a/client/packages/lowcoder/src/components/CurlImport.tsx b/client/packages/lowcoder/src/components/CurlImport.tsx new file mode 100644 index 000000000..e3b26936b --- /dev/null +++ b/client/packages/lowcoder/src/components/CurlImport.tsx @@ -0,0 +1,90 @@ +import React, { useState } from "react"; +import { Modal, Input, Button, message } from "antd"; +import { trans } from "i18n"; +import parseCurl from "@bany/curl-to-json"; +const { TextArea } = Input; +interface CurlImportModalProps { + open: boolean; + onCancel: () => void; + onSuccess: (parsedData: any) => void; +} + +export function CurlImportModal(props: CurlImportModalProps) { + const { open, onCancel, onSuccess } = props; + const [curlCommand, setCurlCommand] = useState(""); + const [loading, setLoading] = useState(false); + + const handleImport = async () => { + if (!curlCommand.trim()) { + message.error("Please enter a cURL command"); + return; + } + + setLoading(true); + try { + // Parse the cURL command using the correct import + const parsedData = parseCurl(curlCommand); + console.log("CURL JSON", parsedData) + + + + // Log the result for now as requested + // console.log("Parsed cURL data:", parsedData); + + // Call success callback with parsed data + onSuccess(parsedData); + + // Reset form and close modal + setCurlCommand(""); + onCancel(); + + message.success("cURL command imported successfully!"); + } catch (error: any) { + console.error("Error parsing cURL command:", error); + message.error(`Failed to parse cURL command: ${error.message}`); + } finally { + setLoading(false); + } + }; + + const handleCancel = () => { + setCurlCommand(""); + onCancel(); + }; + + return ( + + Cancel + , + , + ]} + width={600} + > +
+
+ Paste cURL Command Here +
+
+ Hint: Try typing in the following curl command and then click on the 'Import' button: + curl -X GET https://mock-api.appsmith.com/users +
+