| | |
| | | import { BodyType, type HttpNodeType, Method } from '../types' |
| | | import Modal from '@/app/components/base/modal' |
| | | import Button from '@/app/components/base/button' |
| | | import Textarea from '@/app/components/base/textarea' |
| | | import Toast from '@/app/components/base/toast' |
| | | import { useNodesInteractions } from '@/app/components/workflow/hooks' |
| | | |
| | |
| | | const node: Partial<HttpNodeType> = { |
| | | title: 'HTTP Request', |
| | | desc: 'Imported from cURL', |
| | | method: undefined, |
| | | method: Method.get, |
| | | url: '', |
| | | headers: '', |
| | | params: '', |
| | | body: { type: BodyType.none, data: '' }, |
| | | } |
| | | const args = curlCommand.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || [] |
| | | let hasData = false |
| | | |
| | | for (let i = 1; i < args.length; i++) { |
| | | const arg = args[i].replace(/^['"]|['"]$/g, '') |
| | |
| | | if (i + 1 >= args.length) |
| | | return { node: null, error: 'Missing HTTP method after -X or --request.' } |
| | | node.method = (args[++i].replace(/^['"]|['"]$/g, '') as Method) || Method.get |
| | | hasData = true |
| | | break |
| | | case '-H': |
| | | case '--header': |
| | |
| | | } |
| | | } |
| | | |
| | | // Determine final method |
| | | node.method = node.method || (hasData ? Method.post : Method.get) |
| | | |
| | | if (!node.url) |
| | | return { node: null, error: 'Missing URL or url not start with http.' } |
| | | |
| | |
| | | className='!w-[400px] !max-w-[400px] !p-4' |
| | | > |
| | | <div> |
| | | <Textarea |
| | | <textarea |
| | | value={inputString} |
| | | className='my-3 h-40 w-full grow' |
| | | className='w-full my-3 p-3 text-sm text-gray-900 border-0 rounded-lg grow bg-gray-100 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200 h-40' |
| | | onChange={e => setInputString(e.target.value)} |
| | | placeholder={t('workflow.nodes.http.curl.placeholder')!} |
| | | /> |