mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2026-04-01 22:02:34 +00:00
improvements and actualization
This commit is contained in:
@@ -1,30 +1,27 @@
|
||||
import dev.inmo.saucenaoapi.SauceNaoAPI
|
||||
import dev.inmo.saucenaoapi.utils.useSafe
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.utils.io.streams.asInput
|
||||
import io.ktor.client.HttpClient
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
suspend fun main(vararg args: String) {
|
||||
val (key, requestSubject) = args
|
||||
|
||||
val scope = CoroutineScope(Dispatchers.Default)
|
||||
|
||||
val api = SauceNaoAPI(key, scope = scope)
|
||||
api.useSafe { _ ->
|
||||
println(
|
||||
when {
|
||||
requestSubject.startsWith("/") -> File(requestSubject).let {
|
||||
api.request(
|
||||
it.inputStream().asInput(),
|
||||
ContentType.parse(Files.probeContentType(it.toPath()))
|
||||
)
|
||||
}
|
||||
else -> api.request(requestSubject)
|
||||
}
|
||||
)
|
||||
val client = HttpClient()
|
||||
val scope = CoroutineScope(Dispatchers.IO).also {
|
||||
it.coroutineContext.job.invokeOnCompletion {
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
|
||||
val api = SauceNaoAPI(key, client, scope = scope)
|
||||
println(
|
||||
when {
|
||||
requestSubject.startsWith("/") -> File(requestSubject).let {
|
||||
api.request(it)
|
||||
}
|
||||
else -> api.request(requestSubject)
|
||||
}
|
||||
)
|
||||
|
||||
scope.cancel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user