Skip to content

Commit 456f4c4

Browse files
committed
feat(plugin-apipost): Proxy support importing from clipboard
1 parent 607f789 commit 456f4c4

3 files changed

Lines changed: 98 additions & 65 deletions

File tree

plugin-apipost/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = "me.leon.toolsfx"
2-
version = "1.9.2"
2+
version = "1.10.0"
33

44
plugins {
55
`java-library`

plugin-apipost/src/main/kotlin/me/leon/toolsfx/plugin/ApiPostView.kt

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import tornadofx.*
2323
private const val MAX_SHOW_LENGTH = 1_000_000
2424

2525
class ApiPostView : PluginFragment("ApiPost") {
26-
override val version = "v1.9.2"
27-
override val date: String = "2024-12-17"
26+
override val version = "v1.10.0"
27+
override val date: String = "2025-07-27"
2828
override val author = "Leon406"
2929
override val description = "ApiPost"
3030

@@ -134,12 +134,12 @@ class ApiPostView : PluginFragment("ApiPost") {
134134
tooltip(messages["copy"])
135135
action {
136136
Request(
137-
tfUrl.text,
138-
selectedMethod.get(),
139-
reqTableParams,
140-
reqHeaders,
141-
taReqContent.text,
142-
)
137+
tfUrl.text,
138+
selectedMethod.get(),
139+
reqTableParams,
140+
reqHeaders,
141+
taReqContent.text,
142+
)
143143
.apply {
144144
isJson = selectedBodyType.get() == BodyType.JSON.type
145145
requestParams
@@ -335,73 +335,80 @@ class ApiPostView : PluginFragment("ApiPost") {
335335

336336
fun req() =
337337
runCatching {
338-
if (selectedMethod.get() == "POST") {
339-
val bodyType = bodyTypeMap[selectedBodyType.get()]
340-
requireNotNull(bodyType)
341-
when (bodyType) {
342-
BodyType.JSON,
343-
BodyType.FORM_DATA ->
344-
uploadParams?.run {
345-
controller.uploadFile(
346-
tfUrl.text,
347-
this.value.split(",", ";").map { it.toFile() },
348-
this.key,
349-
reqTableParams,
350-
reqHeaders,
351-
)
338+
if (selectedMethod.get() == "POST") {
339+
val bodyType = bodyTypeMap[selectedBodyType.get()]
340+
requireNotNull(bodyType)
341+
when (bodyType) {
342+
BodyType.JSON,
343+
BodyType.FORM_DATA ->
344+
uploadParams?.run {
345+
controller.uploadFile(
346+
tfUrl.text,
347+
this.value.split(",", ";").map { it.toFile() },
348+
this.key,
349+
reqTableParams,
350+
reqHeaders,
351+
)
352+
}
353+
?: controller.post(
354+
tfUrl.text,
355+
reqTableParams,
356+
reqHeaders,
357+
bodyType == BodyType.JSON,
358+
)
359+
360+
BodyType.RAW ->
361+
controller.postRaw(
362+
tfUrl.text,
363+
taReqContent.text,
364+
reqHeaders,
365+
)
352366
}
353-
?: controller.post(
354-
tfUrl.text,
355-
reqTableParams,
356-
reqHeaders,
357-
bodyType == BodyType.JSON,
358-
)
359-
360-
BodyType.RAW ->
361-
controller.postRaw(tfUrl.text, taReqContent.text, reqHeaders)
362-
}
363-
} else {
364-
controller.request(
365-
tfUrl.text,
366-
selectedMethod.get(),
367-
reqTableParams,
368-
reqHeaders,
369-
)
370-
}.also { lastResp = it }
371-
.toLiteResponse()
372-
.also {
373-
if (it.code == 200) {
374-
success++
375-
countMap[it.hash] = countMap[it.hash]?.let { it + 1 } ?: 1
367+
} else {
368+
controller.request(
369+
tfUrl.text,
370+
selectedMethod.get(),
371+
reqTableParams,
372+
reqHeaders,
373+
)
376374
}
377-
}
378-
}.onFailure {
379-
Response(-1, it.message ?: "", mutableMapOf(), System.currentTimeMillis(),)
380-
}
375+
.also { lastResp = it }
376+
.toLiteResponse()
377+
.also {
378+
if (it.code == 200) {
379+
success++
380+
countMap[it.hash] = countMap[it.hash]?.let { it + 1 } ?: 1
381+
}
382+
}
383+
}
384+
.onFailure {
385+
Response(-1, it.message ?: "", mutableMapOf(), System.currentTimeMillis())
386+
}
381387

382388
runCatching {
383-
runBlocking {
384-
(1..count)
385-
.map {
386-
async(dispatcher) {
387-
req().also {
388-
if (delayMillis > 0) {
389-
// delay 无法阻塞其他
390-
Thread.sleep(delayMillis)
389+
runBlocking {
390+
(1..count)
391+
.map {
392+
async(dispatcher) {
393+
req().also {
394+
if (delayMillis > 0) {
395+
// delay 无法阻塞其他
396+
Thread.sleep(delayMillis)
397+
}
391398
}
392399
}
393400
}
394-
}
395-
.awaitAll()
401+
.awaitAll()
396402

397-
lastResp!!
403+
lastResp!!
404+
}
398405
}
399-
}
400406
.onSuccess {
401407
handleSuccess(it)
402408
if (count > 1) {
403409
ui {
404-
val statisticInfo = " time costs : ${System.currentTimeMillis() - start} ms" +
410+
val statisticInfo =
411+
" time costs : ${System.currentTimeMillis() - start} ms" +
405412
"\nsuccess/total: $success/$count" +
406413
"\n detail :\n${
407414
countMap.map { "\t\tresp hash: ${it.key} num: ${it.value}" }
@@ -466,7 +473,7 @@ class ApiPostView : PluginFragment("ApiPost") {
466473
valueProperty.value = mutableEntry.value.toString()
467474
fileProperty.value =
468475
mutableEntry.key in fileKeys ||
469-
mutableEntry.value.toString() == "@file"
476+
mutableEntry.value.toString() == "@file"
470477
}
471478
)
472479
}

plugin-apipost/src/main/kotlin/me/leon/toolsfx/plugin/SettingsView.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import javafx.geometry.Pos
66
import javafx.scene.control.TextField
77
import javafx.scene.control.TextInputControl
88
import javafx.scene.layout.Priority
9+
import me.leon.IMG_IMPORT
10+
import me.leon.ext.fx.clipboardText
911
import me.leon.ext.fx.fileDraggedHandler
1012
import me.leon.toolsfx.plugin.ApiConfig.saveConfig
1113
import me.leon.toolsfx.plugin.net.TrustManager
@@ -64,7 +66,31 @@ class SettingsView : View("Setting") {
6466
}
6567
checkbox("ignoreSSL", ignoreCert)
6668
}
67-
label("Proxy")
69+
hbox {
70+
spacing = 8.0
71+
alignment = Pos.CENTER_LEFT
72+
label("Proxy")
73+
button(graphic = imageview(IMG_IMPORT)) {
74+
tooltip(messages["pasteFromClipboard"])
75+
action {
76+
val proxyInfos = clipboardText().split("@").map { it.split(":") }
77+
runCatching {
78+
if (proxyInfos.size == 2) {
79+
tfIp.text = proxyInfos[1][0]
80+
tfPort.text = proxyInfos[1][1]
81+
tfUserName.text = proxyInfos[0][0]
82+
tfPassword.text = proxyInfos[0][1]
83+
} else {
84+
tfIp.text = proxyInfos[0][0]
85+
tfPort.text = proxyInfos[0][1]
86+
tfUserName.text = null
87+
tfPassword.text = null
88+
}
89+
}
90+
}
91+
}
92+
}
93+
6894
hbox {
6995
spacing = 8.0
7096
alignment = Pos.CENTER

0 commit comments

Comments
 (0)