mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-09-12 19:24:26 +00:00
start migration onto new dependencies
This commit is contained in:
@@ -11,6 +11,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api libs.klock
|
||||
api libs.kt.io
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package dev.inmo.micro_utils.common
|
||||
|
||||
import kotlinx.io.Buffer
|
||||
import kotlinx.io.Source
|
||||
import kotlinx.io.buffered
|
||||
import kotlinx.io.files.Path
|
||||
import kotlinx.io.files.SystemFileSystem
|
||||
import kotlinx.io.readByteArray
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
@@ -32,3 +38,17 @@ expect val MPPFile.bytesAllocator: SuspendByteArrayAllocator
|
||||
fun MPPFile.bytesSync() = bytesAllocatorSync()
|
||||
suspend fun MPPFile.bytes() = bytesAllocator()
|
||||
|
||||
val Path.filename: FileName
|
||||
get() = FileName(name)
|
||||
val Path.filesize: Long
|
||||
get() = SystemFileSystem.metadataOrNull(this) ?.size ?.takeIf { it > -1 } ?: error("Path $filename does not exists or is folder")
|
||||
val Path.bytesAllocatorSync: ByteArrayAllocator
|
||||
get() = {
|
||||
source().buffered().readByteArray()
|
||||
}
|
||||
val Path.bytesAllocator: SuspendByteArrayAllocator
|
||||
get() = {
|
||||
bytesAllocatorSync()
|
||||
}
|
||||
|
||||
fun Path.source(): Source = SystemFileSystem.source(this).buffered()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.inmo.micro_utils.common
|
||||
|
||||
import kotlinx.io.files.Path
|
||||
import org.khronos.webgl.ArrayBuffer
|
||||
import org.w3c.dom.ErrorEvent
|
||||
import org.w3c.files.*
|
||||
|
||||
@@ -4,6 +4,8 @@ kt = "2.0.10"
|
||||
kt-serialization = "1.7.1"
|
||||
kt-coroutines = "1.8.1"
|
||||
|
||||
kt-io = "0.5.2"
|
||||
|
||||
kslog = "1.3.5"
|
||||
|
||||
jb-compose = "1.7.0-alpha02"
|
||||
@@ -15,11 +17,11 @@ sqlite = "3.46.0.1"
|
||||
korlibs = "5.4.0"
|
||||
uuid = "0.8.4"
|
||||
|
||||
ktor = "2.3.11"
|
||||
ktor = "3.0.0-beta-2"
|
||||
|
||||
gh-release = "2.5.2"
|
||||
|
||||
koin = "3.5.6"
|
||||
koin = "4.0.0-RC1"
|
||||
|
||||
okio = "3.9.0"
|
||||
|
||||
@@ -56,6 +58,7 @@ kt-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-and
|
||||
kt-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kt-coroutines" }
|
||||
kt-coroutines-debug = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-debug", version.ref = "kt-coroutines" }
|
||||
|
||||
kt-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kt-io" }
|
||||
|
||||
ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor" }
|
||||
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
|
||||
|
||||
@@ -3,9 +3,10 @@ package dev.inmo.micro_utils.ktor.client
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
|
||||
expect suspend fun HttpClient.tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback = { _, _ -> }
|
||||
onUpload: ProgressListener = ProgressListener { _, _ -> }
|
||||
): TemporalFileId
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.inmo.micro_utils.common.FileName
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.ktor.common.LambdaInputProvider
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.utils.io.core.Input
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
@@ -31,7 +32,7 @@ expect suspend fun <T> HttpClient.uniUpload(
|
||||
resultDeserializer: DeserializationStrategy<T>,
|
||||
headers: Headers = Headers.Empty,
|
||||
stringFormat: StringFormat = Json,
|
||||
onUpload: OnUploadCallback = { _, _ -> }
|
||||
onUpload: ProgressListener = ProgressListener { _, _ -> }
|
||||
): T?
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,7 @@ suspend fun <T> HttpClient.uniUpload(
|
||||
additionalData: Map<String, Any> = emptyMap(),
|
||||
headers: Headers = Headers.Empty,
|
||||
stringFormat: StringFormat = Json,
|
||||
onUpload: OnUploadCallback = { _, _ -> }
|
||||
onUpload: ProgressListener = ProgressListener { _, _ -> }
|
||||
): T? = uniUpload(
|
||||
url,
|
||||
additionalData + ("bytes" to file),
|
||||
@@ -68,7 +69,7 @@ suspend fun <T> HttpClient.uniUpload(
|
||||
additionalData: Map<String, Any> = emptyMap(),
|
||||
headers: Headers = Headers.Empty,
|
||||
stringFormat: StringFormat = Json,
|
||||
onUpload: OnUploadCallback = { _, _ -> }
|
||||
onUpload: ProgressListener = ProgressListener { _, _ -> }
|
||||
): T? = uniUpload(
|
||||
url,
|
||||
additionalData + ("bytes" to info),
|
||||
@@ -93,7 +94,7 @@ suspend fun <T> HttpClient.uniUpload(
|
||||
additionalData: Map<String, Any> = emptyMap(),
|
||||
headers: Headers = Headers.Empty,
|
||||
stringFormat: StringFormat = Json,
|
||||
onUpload: OnUploadCallback = { _, _ -> }
|
||||
onUpload: ProgressListener = ProgressListener { _, _ -> }
|
||||
): T? = uniUpload(
|
||||
url,
|
||||
UniUploadFileInfo(fileName, mimeType, inputAllocator),
|
||||
|
||||
@@ -5,16 +5,19 @@ import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.io.files.SystemFileSystem
|
||||
import org.w3c.dom.mediasource.ENDED
|
||||
import org.w3c.dom.mediasource.ReadyState
|
||||
import org.w3c.files.File
|
||||
import org.w3c.xhr.*
|
||||
import org.w3c.xhr.XMLHttpRequest.Companion.DONE
|
||||
|
||||
suspend fun tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): TemporalFileId {
|
||||
val formData = FormData()
|
||||
val answer = CompletableDeferred<TemporalFileId>(currentCoroutineContext().job)
|
||||
@@ -28,7 +31,7 @@ suspend fun tempUpload(
|
||||
val request = XMLHttpRequest()
|
||||
request.responseType = XMLHttpRequestResponseType.TEXT
|
||||
request.upload.onprogress = {
|
||||
subscope.launchSafelyWithoutExceptions { onUpload(it.loaded.toLong(), it.total.toLong()) }
|
||||
subscope.launchSafelyWithoutExceptions { onUpload.onProgress(it.loaded.toLong(), it.total.toLong()) }
|
||||
}
|
||||
request.onload = {
|
||||
if (request.status == 200.toShort()) {
|
||||
@@ -60,5 +63,5 @@ suspend fun tempUpload(
|
||||
actual suspend fun HttpClient.tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): TemporalFileId = dev.inmo.micro_utils.ktor.client.tempUpload(fullTempUploadDraftPath, file, onUpload)
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.inmo.micro_utils.common.Progress
|
||||
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.utils.io.core.readBytes
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
@@ -36,7 +37,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
resultDeserializer: DeserializationStrategy<T>,
|
||||
headers: Headers,
|
||||
stringFormat: StringFormat,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): T? {
|
||||
val formData = FormData()
|
||||
val answer = CompletableDeferred<T?>(currentCoroutineContext().job)
|
||||
@@ -66,7 +67,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
}
|
||||
request.responseType = XMLHttpRequestResponseType.TEXT
|
||||
request.upload.onprogress = {
|
||||
subscope.launchSafelyWithoutExceptions { onUpload(it.loaded.toLong(), it.total.toLong()) }
|
||||
subscope.launchSafelyWithoutExceptions { onUpload.onProgress(it.loaded.toLong(), it.total.toLong()) }
|
||||
}
|
||||
request.onload = {
|
||||
if (request.status == 200.toShort()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.filename
|
||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.forms.submitFormWithBinaryData
|
||||
@@ -18,7 +19,7 @@ internal val MPPFile.mimeType: String
|
||||
actual suspend fun HttpClient.tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): TemporalFileId {
|
||||
val inputProvider = file.inputProvider()
|
||||
val fileId = submitFormWithBinaryData(
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.inmo.micro_utils.ktor.client
|
||||
|
||||
import dev.inmo.micro_utils.common.Progress
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.engine.mergeHeaders
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
@@ -39,7 +40,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
resultDeserializer: DeserializationStrategy<T>,
|
||||
headers: Headers,
|
||||
stringFormat: StringFormat,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): T? {
|
||||
val withBinary = data.values.any { it is File || it is UniUploadFileInfo }
|
||||
|
||||
@@ -75,9 +76,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
headers {
|
||||
appendAll(headers)
|
||||
}
|
||||
onUpload { bytesSentTotal, contentLength ->
|
||||
onUpload(bytesSentTotal, contentLength)
|
||||
}
|
||||
onUpload(onUpload)
|
||||
}
|
||||
|
||||
val response = if (withBinary) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.inmo.micro_utils.common.filename
|
||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||
import dev.inmo.micro_utils.mime_types.getMimeTypeOrAny
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.forms.submitFormWithBinaryData
|
||||
@@ -18,7 +19,7 @@ internal val MPPFile.mimeType: String
|
||||
actual suspend fun HttpClient.tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): TemporalFileId {
|
||||
val inputProvider = file.inputProvider()
|
||||
val fileId = submitFormWithBinaryData(
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.micro_utils.ktor.client
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.Progress
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.engine.mergeHeaders
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
@@ -39,7 +40,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
resultDeserializer: DeserializationStrategy<T>,
|
||||
headers: Headers,
|
||||
stringFormat: StringFormat,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): T? {
|
||||
val withBinary = data.values.any { it is MPPFile || it is UniUploadFileInfo }
|
||||
|
||||
@@ -75,9 +76,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
headers {
|
||||
appendAll(headers)
|
||||
}
|
||||
onUpload { bytesSentTotal, contentLength ->
|
||||
onUpload(bytesSentTotal, contentLength)
|
||||
}
|
||||
onUpload(onUpload)
|
||||
}
|
||||
|
||||
val response = if (withBinary) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.inmo.micro_utils.common.filename
|
||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||
import dev.inmo.micro_utils.mime_types.getMimeTypeOrAny
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.forms.submitFormWithBinaryData
|
||||
@@ -18,7 +19,7 @@ internal val MPPFile.mimeType: String
|
||||
actual suspend fun HttpClient.tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): TemporalFileId {
|
||||
val inputProvider = file.inputProvider()
|
||||
val fileId = submitFormWithBinaryData(
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.micro_utils.ktor.client
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.Progress
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.engine.mergeHeaders
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
@@ -39,7 +40,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
resultDeserializer: DeserializationStrategy<T>,
|
||||
headers: Headers,
|
||||
stringFormat: StringFormat,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): T? {
|
||||
val withBinary = data.values.any { it is MPPFile || it is UniUploadFileInfo }
|
||||
|
||||
@@ -75,9 +76,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
headers {
|
||||
appendAll(headers)
|
||||
}
|
||||
onUpload { bytesSentTotal, contentLength ->
|
||||
onUpload(bytesSentTotal, contentLength)
|
||||
}
|
||||
onUpload(onUpload)
|
||||
}
|
||||
|
||||
val response = if (withBinary) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.inmo.micro_utils.common.filename
|
||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||
import dev.inmo.micro_utils.mime_types.getMimeTypeOrAny
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.forms.submitFormWithBinaryData
|
||||
@@ -18,7 +19,7 @@ internal val MPPFile.mimeType: String
|
||||
actual suspend fun HttpClient.tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): TemporalFileId {
|
||||
val inputProvider = file.inputProvider()
|
||||
val fileId = submitFormWithBinaryData(
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.micro_utils.ktor.client
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.Progress
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.content.*
|
||||
import io.ktor.client.engine.mergeHeaders
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
@@ -39,7 +40,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
resultDeserializer: DeserializationStrategy<T>,
|
||||
headers: Headers,
|
||||
stringFormat: StringFormat,
|
||||
onUpload: OnUploadCallback
|
||||
onUpload: ProgressListener
|
||||
): T? {
|
||||
val withBinary = data.values.any { it is MPPFile || it is UniUploadFileInfo }
|
||||
|
||||
@@ -75,9 +76,7 @@ actual suspend fun <T> HttpClient.uniUpload(
|
||||
headers {
|
||||
appendAll(headers)
|
||||
}
|
||||
onUpload { bytesSentTotal, contentLength ->
|
||||
onUpload(bytesSentTotal, contentLength)
|
||||
}
|
||||
onUpload(onUpload)
|
||||
}
|
||||
|
||||
val response = if (withBinary) {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import io.ktor.utils.io.core.Input
|
||||
import io.ktor.utils.io.core.copyTo
|
||||
import io.ktor.utils.io.streams.asOutput
|
||||
import io.ktor.utils.io.core.*
|
||||
import kotlinx.io.asSink
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.util.UUID
|
||||
import kotlin.io.use
|
||||
|
||||
fun Input.downloadToTempFile(
|
||||
fileName: String = UUID.randomUUID().toString(),
|
||||
@@ -16,8 +15,8 @@ fun Input.downloadToTempFile(
|
||||
fileExtension,
|
||||
folder
|
||||
).apply {
|
||||
outputStream().use {
|
||||
copyTo(it.asOutput())
|
||||
outputStream().use { output ->
|
||||
this@downloadToTempFile.transferTo(output.asSink())
|
||||
}
|
||||
deleteOnExit()
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import com.benasher44.uuid.uuid4
|
||||
import io.ktor.http.content.PartData
|
||||
import io.ktor.utils.io.copyTo
|
||||
import io.ktor.utils.io.core.copyTo
|
||||
import io.ktor.utils.io.jvm.javaio.copyTo
|
||||
import io.ktor.utils.io.streams.asOutput
|
||||
import io.ktor.utils.io.jvm.javaio.*
|
||||
import io.ktor.utils.io.streams.*
|
||||
import kotlinx.io.asSink
|
||||
import java.io.File
|
||||
|
||||
fun PartData.FileItem.download(target: File) {
|
||||
provider().use { input ->
|
||||
target.outputStream().asOutput().use {
|
||||
input.copyTo(it)
|
||||
provider().toInputStream().asInput().use { input ->
|
||||
target.outputStream().use { output ->
|
||||
input.transferTo(output.asSink())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,8 +27,8 @@ fun PartData.FileItem.downloadToTemporalFile(): File {
|
||||
|
||||
fun PartData.BinaryItem.download(target: File) {
|
||||
provider().use { input ->
|
||||
target.outputStream().use {
|
||||
input.copyTo(it.asOutput())
|
||||
target.outputStream().use { output ->
|
||||
input.transferTo(output.asSink())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ import dev.inmo.micro_utils.ktor.common.*
|
||||
import io.ktor.http.URLProtocol
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.application.pluginOrNull
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.application
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.websocket.*
|
||||
import io.ktor.websocket.send
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
|
||||
inline fun <reified T : Any> Route.includeWebsocketHandling(
|
||||
inline fun <reified T : Any> Routing.includeWebsocketHandling(
|
||||
suburl: String,
|
||||
flow: Flow<T>,
|
||||
protocol: URLProtocol? = null,
|
||||
|
||||
@@ -11,12 +11,12 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
|
||||
engine: ApplicationEngineFactory<TEngine, TConfiguration>,
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
|
||||
block: Application.() -> Unit
|
||||
): TEngine = embeddedServer(
|
||||
engine,
|
||||
applicationEngineEnvironment {
|
||||
applicationEnvironment {
|
||||
module(block)
|
||||
connector {
|
||||
this.host = host
|
||||
@@ -35,7 +35,7 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
|
||||
fun createKtorServer(
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
|
||||
block: Application.() -> Unit
|
||||
): CIOApplicationEngine = createKtorServer(
|
||||
@@ -51,7 +51,7 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
|
||||
engine: ApplicationEngineFactory<TEngine, TConfiguration>,
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
|
||||
configurators: List<KtorApplicationConfigurator>
|
||||
): TEngine = createKtorServer(
|
||||
@@ -73,6 +73,6 @@ fun createKtorServer(
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
configurators: List<KtorApplicationConfigurator>,
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
|
||||
): ApplicationEngine = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, configurators)
|
||||
|
||||
@@ -14,7 +14,7 @@ import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receiveMultipart
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.response.respondText
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.post
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
@@ -77,7 +77,7 @@ class TemporalFilesRoutingConfigurator(
|
||||
private val filesFlow = MutableSharedFlow<TemporalFileId>()
|
||||
val utilizerJob = temporalFilesUtilizer.start(temporalFilesMap, temporalFilesMutex, filesFlow.asSharedFlow())
|
||||
|
||||
override fun Route.invoke() {
|
||||
override fun Routing.invoke() {
|
||||
post(subpath) {
|
||||
val multipart = call.receiveMultipart()
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.ktor.server.configurators
|
||||
|
||||
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator.Element
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Routing
|
||||
import kotlinx.serialization.Contextual
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -11,7 +11,7 @@ import kotlinx.serialization.Serializable
|
||||
class ApplicationRoutingConfigurator(
|
||||
private val elements: List<@Contextual Element>
|
||||
) : KtorApplicationConfigurator {
|
||||
fun interface Element { operator fun Route.invoke() }
|
||||
fun interface Element { operator fun Routing.invoke() }
|
||||
private val rootInstaller = Element {
|
||||
elements.forEach {
|
||||
it.apply { invoke() }
|
||||
|
||||
@@ -2,10 +2,10 @@ package dev.inmo.micro_utils.repos.ktor.server.crud
|
||||
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.repos.CRUDRepo
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import kotlinx.serialization.*
|
||||
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureCRUDRepoRoutes(
|
||||
originalRepo: CRUDRepo<ObjectType, IdType, InputValue>,
|
||||
noinline idDeserializer: suspend (String) -> IdType
|
||||
) {
|
||||
@@ -13,7 +13,7 @@ inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue :
|
||||
configureWriteCRUDRepoRoutes(originalRepo)
|
||||
}
|
||||
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureCRUDRepoRoutes(
|
||||
originalRepo: CRUDRepo<ObjectType, IdType, InputValue>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: StringFormat
|
||||
@@ -21,7 +21,7 @@ inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue :
|
||||
serialFormat.decodeFromString(idsSerializer, it)
|
||||
}
|
||||
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureCRUDRepoRoutes(
|
||||
originalRepo: CRUDRepo<ObjectType, IdType, InputValue>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: BinaryFormat
|
||||
|
||||
@@ -11,11 +11,11 @@ import dev.inmo.micro_utils.repos.ktor.common.idParameterName
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.get
|
||||
import kotlinx.serialization.*
|
||||
|
||||
inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes(
|
||||
originalRepo: ReadCRUDRepo<ObjectType, IdType>,
|
||||
noinline idDeserializer: suspend (String) -> IdType
|
||||
) {
|
||||
@@ -65,7 +65,7 @@ inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoute
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes(
|
||||
originalRepo: ReadCRUDRepo<ObjectType, IdType>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: StringFormat
|
||||
@@ -73,7 +73,7 @@ inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoute
|
||||
serialFormat.decodeFromString(idsSerializer, it)
|
||||
}
|
||||
|
||||
inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes(
|
||||
originalRepo: ReadCRUDRepo<ObjectType, IdType>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: BinaryFormat
|
||||
|
||||
@@ -7,10 +7,10 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receive
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.post
|
||||
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureWriteCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureWriteCRUDRepoRoutes(
|
||||
originalRepo: WriteCRUDRepo<ObjectType, IdType, InputValue>
|
||||
) {
|
||||
includeWebsocketHandling(
|
||||
|
||||
@@ -3,10 +3,10 @@ package dev.inmo.micro_utils.repos.ktor.server.key.value
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import kotlinx.serialization.*
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes (
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRepoRoutes (
|
||||
originalRepo: KeyValueRepo<Key, Value>,
|
||||
noinline idDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
@@ -15,7 +15,7 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoR
|
||||
configureWriteKeyValueRepoRoutes(originalRepo)
|
||||
}
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes(
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRepoRoutes(
|
||||
originalRepo: KeyValueRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
@@ -30,7 +30,7 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoR
|
||||
}
|
||||
)
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes(
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRepoRoutes(
|
||||
originalRepo: KeyValueRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
||||
@@ -14,14 +14,14 @@ import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.util.InternalAPI
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@OptIn(InternalAPI::class)
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes (
|
||||
originalRepo: ReadKeyValueRepo<Key, Value>,
|
||||
noinline idDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
@@ -79,7 +79,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes(
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes(
|
||||
originalRepo: ReadKeyValueRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
@@ -94,7 +94,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes(
|
||||
}
|
||||
)
|
||||
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes(
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes(
|
||||
originalRepo: ReadKeyValueRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
||||
@@ -7,11 +7,11 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receive
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.post
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureWriteKeyValueRepoRoutes (
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureWriteKeyValueRepoRoutes (
|
||||
originalRepo: WriteKeyValueRepo<Key, Value>
|
||||
) {
|
||||
includeWebsocketHandling(
|
||||
|
||||
@@ -3,10 +3,10 @@ package dev.inmo.micro_utils.repos.ktor.server.key.values
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import kotlinx.serialization.*
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes (
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRepoRoutes (
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
noinline keyDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
@@ -15,7 +15,7 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepo
|
||||
configureWriteKeyValuesRepoRoutes(originalRepo)
|
||||
}
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRepoRoutes(
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
@@ -30,7 +30,7 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepo
|
||||
}
|
||||
)
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRepoRoutes(
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
||||
@@ -12,14 +12,14 @@ import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.util.InternalAPI
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@OptIn(InternalAPI::class)
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes (
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
noinline keyDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
@@ -76,7 +76,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes(
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
@@ -91,7 +91,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
|
||||
}
|
||||
)
|
||||
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes(
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
||||
@@ -7,11 +7,11 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receive
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.post
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureWriteKeyValuesRepoRoutes (
|
||||
inline fun <reified Key : Any, reified Value : Any> Routing.configureWriteKeyValuesRepoRoutes (
|
||||
originalRepo: WriteKeyValuesRepo<Key, Value>
|
||||
) {
|
||||
includeWebsocketHandling(
|
||||
|
||||
Reference in New Issue
Block a user