add microutils and support of native platforms

This commit is contained in:
InsanusMokrassar 2023-05-11 16:24:38 +06:00
parent 33775f3304
commit 1ed123596c
7 changed files with 52 additions and 39 deletions

View File

@ -2,6 +2,8 @@
## 0.16.0
Add `MicroUtils` as used micro utils
* Versions:
* `Kotlin`: `1.8.21`
* `Ktor`: `2.3.0`

View File

@ -28,11 +28,19 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
}
linuxX64()
mingwX64()
sourceSets {
@ -44,6 +52,9 @@ kotlin {
api libs.kt.serialization
api libs.klock
api libs.ktor.client
api libs.microutils.common
api libs.microutils.ktor.common
api libs.microutils.mimetypes
}
}
commonTest {
@ -65,3 +76,8 @@ kotlin {
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@ -7,6 +7,10 @@ kt-coroutines = "1.6.4"
klock = "3.4.0"
ktor = "2.3.0"
microutils = "0.18.2"
okio = "3.3.0"
gh-release = "2.4.1"
[libraries]
@ -20,6 +24,10 @@ klock = { module = "com.soywiz.korlibs.klock:klock", version.ref = "klock" }
ktor-client = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
microutils-common = { module = "dev.inmo:micro_utils.common", version.ref = "microutils" }
microutils-ktor-common = { module = "dev.inmo:micro_utils.ktor.common", version.ref = "microutils" }
microutils-mimetypes = { module = "dev.inmo:micro_utils.mime_types", version.ref = "microutils" }
buildscript-kt-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kt" }
buildscript-kt-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kt" }
buildscript-gh-release = { module = "com.github.breadmoirai:github-release", version.ref = "gh-release" }

View File

@ -1,5 +1,7 @@
package dev.inmo.saucenaoapi
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.micro_utils.ktor.common.input
import dev.inmo.saucenaoapi.exceptions.TooManyRequestsException
import dev.inmo.saucenaoapi.exceptions.sauceNaoAPIException
import dev.inmo.saucenaoapi.models.*
@ -189,7 +191,7 @@ data class SauceNaoAPI(
resultsCount: Int? = null,
minSimilarity: Float? = null
): SauceNaoAnswer = request(
file.input,
file.input(),
file.contentType,
resultsCount,
minSimilarity
@ -206,7 +208,7 @@ data class SauceNaoAPI(
resultsCount: Int? = null,
minSimilarity: Float? = null
): SauceNaoAnswer = requestByDBs(
file.input,
file.input(),
file.contentType,
db,
dbs,
@ -228,7 +230,7 @@ data class SauceNaoAPI(
resultsCount: Int? = null,
minSimilarity: Float? = null
): SauceNaoAnswer = requestByMasks(
file.input,
file.input(),
file.contentType,
mask,
excludedMask,

View File

@ -1,9 +1,26 @@
package dev.inmo.saucenaoapi.utils
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.micro_utils.common.filename
import dev.inmo.micro_utils.ktor.common.input
import dev.inmo.micro_utils.mime_types.KnownMimeTypes
import dev.inmo.micro_utils.mime_types.getMimeType
import io.ktor.http.ContentType
import io.ktor.utils.io.core.Input
expect class MPPFile
@Deprecated(
"MPPFile from microutils is preferable since 0.16.0",
ReplaceWith("MPPFile", "dev.inmo.micro_utils.common.MPPFile")
)
typealias MPPFile = MPPFile
expect val MPPFile.input: Input
expect val MPPFile.contentType: ContentType
@Deprecated(
"input() from microutils is preferable since 0.16.0",
ReplaceWith("this.input()", "dev.inmo.micro_utils.ktor.common.input")
)
val MPPFile.input: Input
get() = input()
val MPPFile.contentType: ContentType
get() = ContentType.parse(
getMimeType(stringWithExtension = filename.extension) ?.raw ?: KnownMimeTypes.Any.raw
)

View File

@ -1,18 +0,0 @@
package dev.inmo.saucenaoapi.utils
import io.ktor.http.ContentType
import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input
import org.khronos.webgl.Int8Array
import org.w3c.files.File
import org.w3c.files.FileReaderSync
actual typealias MPPFile = File
actual val MPPFile.input: Input
get() {
val reader = FileReaderSync()
return ByteReadPacket(Int8Array(reader.readAsArrayBuffer(this)) as ByteArray)
}
actual val MPPFile.contentType: ContentType
get() = ContentType.parse(type)

View File

@ -1,14 +0,0 @@
package dev.inmo.saucenaoapi.utils
import io.ktor.http.ContentType
import io.ktor.utils.io.core.Input
import io.ktor.utils.io.streams.asInput
import java.io.File
import java.nio.file.Files
actual typealias MPPFile = File
actual val MPPFile.input: Input
get() = inputStream().asInput()
actual val MPPFile.contentType: ContentType
get() = ContentType.parse(Files.probeContentType(toPath()))