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..a15d54bbf --- /dev/null +++ b/client/packages/lowcoder/src/components/CurlImport.tsx @@ -0,0 +1,97 @@ +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); + + + + // 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 +
+
+
+ Examples: +
+
+ GET: curl -X GET https://jsonplaceholder.typicode.com/posts/1 +
+
+ POST: curl -X POST https://jsonplaceholder.typicode.com/posts -H "Content-Type: application/json" -d '{"title":"foo","body":"bar","userId":1}' +
+
+ Users: curl -X GET https://jsonplaceholder.typicode.com/users +
+
+