@@ -23,8 +23,8 @@ import tornadofx.*
2323private const val MAX_SHOW_LENGTH = 1_000_000
2424
2525class 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 " \n success/total: $success /$count " +
406413 " \n detail :\n ${
407414 countMap.map { " \t\t resp 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 }
0 commit comments