feat: import cURL on paste (#2037)
* feat: import cURL on paste * feat: import cURL on paste * feat: pasting cURL command on url field does not paste it in Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
focus-visible:bg-transparent
|
||||
"
|
||||
@enter="newSendRequest()"
|
||||
@paste="onPasteUrl($event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -196,6 +197,7 @@
|
||||
</span>
|
||||
</div>
|
||||
<HttpImportCurl
|
||||
:text="curlText"
|
||||
:show="showCurlImportModal"
|
||||
@hide-modal="showCurlImportModal = false"
|
||||
/>
|
||||
@@ -267,6 +269,7 @@ const nuxt = useNuxt()
|
||||
const { subscribeToStream } = useStreamSubscriber()
|
||||
|
||||
const newEndpoint = useStream(restEndpoint$, "", setRESTEndpoint)
|
||||
const curlText = ref("")
|
||||
const newMethod = useStream(restMethod$, "", updateRESTMethod)
|
||||
|
||||
const loading = ref(false)
|
||||
@@ -342,6 +345,27 @@ const newSendRequest = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const onPasteUrl = (e: { event: ClipboardEvent; previousValue: string }) => {
|
||||
if (!e) return
|
||||
|
||||
const clipboardData = e.event.clipboardData
|
||||
|
||||
const pastedData = clipboardData?.getData("Text")
|
||||
|
||||
if (!pastedData) return
|
||||
|
||||
if (isCURL(pastedData)) {
|
||||
e.event.preventDefault()
|
||||
showCurlImportModal.value = true
|
||||
curlText.value = pastedData
|
||||
newEndpoint.value = e.previousValue
|
||||
}
|
||||
}
|
||||
|
||||
function isCURL(curl: string) {
|
||||
return curl.includes("curl ")
|
||||
}
|
||||
|
||||
const cancelRequest = () => {
|
||||
loading.value = false
|
||||
updateRESTResponse(null)
|
||||
|
||||
Reference in New Issue
Block a user