mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 12:08:45 +00:00
several fixes
This commit is contained in:
parent
175dd980f8
commit
db10fe1b2c
@ -4,6 +4,7 @@ import dev.inmo.micro_utils.common.MPPFile
|
|||||||
import dev.inmo.micro_utils.common.filename
|
import dev.inmo.micro_utils.common.filename
|
||||||
import dev.inmo.micro_utils.ktor.common.*
|
import dev.inmo.micro_utils.ktor.common.*
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.call.body
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.request.forms.*
|
import io.ktor.client.request.forms.*
|
||||||
import io.ktor.client.statement.readBytes
|
import io.ktor.client.statement.readBytes
|
||||||
@ -104,10 +105,8 @@ suspend fun <ResultType> HttpClient.uniget(
|
|||||||
url: String,
|
url: String,
|
||||||
resultDeserializer: DeserializationStrategy<ResultType>,
|
resultDeserializer: DeserializationStrategy<ResultType>,
|
||||||
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat
|
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat
|
||||||
) = get(
|
) = get(url).let {
|
||||||
url
|
serialFormat.decodeDefault(resultDeserializer, it.body<StandardKtorSerialInputData>())
|
||||||
).let {
|
|
||||||
serialFormat.decodeDefault(resultDeserializer, it.readBytes())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -129,7 +128,7 @@ suspend fun <BodyType, ResultType> HttpClient.unipost(
|
|||||||
serialFormat.encodeDefault(bodyInfo.first, bodyInfo.second)
|
serialFormat.encodeDefault(bodyInfo.first, bodyInfo.second)
|
||||||
)
|
)
|
||||||
}.let {
|
}.let {
|
||||||
serialFormat.decodeDefault(resultDeserializer, it.readBytes())
|
serialFormat.decodeDefault(resultDeserializer, it.body<StandardKtorSerialInputData>())
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun <ResultType> HttpClient.unimultipart(
|
suspend fun <ResultType> HttpClient.unimultipart(
|
||||||
@ -158,7 +157,7 @@ suspend fun <ResultType> HttpClient.unimultipart(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
requestBuilder()
|
requestBuilder()
|
||||||
}.let { serialFormat.decodeDefault(resultDeserializer, it.readBytes()) }
|
}.let { serialFormat.decodeDefault(resultDeserializer, it.body<StandardKtorSerialInputData>()) }
|
||||||
|
|
||||||
suspend fun <BodyType, ResultType> HttpClient.unimultipart(
|
suspend fun <BodyType, ResultType> HttpClient.unimultipart(
|
||||||
url: String,
|
url: String,
|
||||||
|
@ -14,8 +14,7 @@ import io.ktor.server.response.respondBytes
|
|||||||
import io.ktor.server.routing.Route
|
import io.ktor.server.routing.Route
|
||||||
import io.ktor.server.websocket.WebSocketServerSession
|
import io.ktor.server.websocket.WebSocketServerSession
|
||||||
import io.ktor.util.pipeline.PipelineContext
|
import io.ktor.util.pipeline.PipelineContext
|
||||||
import io.ktor.utils.io.core.Input
|
import io.ktor.utils.io.core.*
|
||||||
import io.ktor.utils.io.core.use
|
|
||||||
import io.ktor.utils.io.streams.asInput
|
import io.ktor.utils.io.streams.asInput
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.serialization.DeserializationStrategy
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
@ -132,7 +131,7 @@ suspend fun ApplicationCall.uniloadMultipart(
|
|||||||
is PartData.FormItem -> onFormItem(it)
|
is PartData.FormItem -> onFormItem(it)
|
||||||
is PartData.FileItem -> {
|
is PartData.FileItem -> {
|
||||||
when (it.name) {
|
when (it.name) {
|
||||||
"bytes" -> resultInput = it.streamProvider().asInput()
|
"bytes" -> resultInput = it.provider()
|
||||||
else -> onCustomFileItem(it)
|
else -> onCustomFileItem(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +153,7 @@ suspend fun <T> ApplicationCall.uniloadMultipart(
|
|||||||
onFormItem,
|
onFormItem,
|
||||||
{
|
{
|
||||||
if (it.name == "data") {
|
if (it.name == "data") {
|
||||||
data = standardKtorSerialFormat.decodeDefault(deserializer, it.streamProvider().readBytes()).optional
|
data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional
|
||||||
} else {
|
} else {
|
||||||
onCustomFileItem(it)
|
onCustomFileItem(it)
|
||||||
}
|
}
|
||||||
@ -201,7 +200,7 @@ suspend fun <T> ApplicationCall.uniloadMultipartFile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.streamProvider().readBytes()).optional
|
"data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional
|
||||||
else -> onCustomFileItem(it)
|
else -> onCustomFileItem(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user