mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-16 10:17:27 +08:00
[+] AimeDB client
This commit is contained in:
@@ -192,8 +192,7 @@ val Any?.str get() = toString()
|
||||
// Collections
|
||||
fun <T> ls(vararg args: T) = args.toList()
|
||||
inline fun <reified T> arr(vararg args: T) = arrayOf(*args)
|
||||
operator fun <K, V> Map<K, V>.plus(map: Map<K, V>) =
|
||||
(if (this is MutableMap) this else mut).apply { putAll(map) }
|
||||
operator fun <K, V> Map<K, V>.plus(map: Map<K, V>) = mut.apply { putAll(map) }
|
||||
operator fun <K, V> MutableMap<K, V>.plusAssign(map: Map<K, V>) { putAll(map) }
|
||||
fun <K, V: Any> Map<K, V?>.vNotNull(): Map<K, V> = filterValues { it != null }.mapValues { it.value!! }
|
||||
fun <T> MutableList<T>.popAll(list: List<T>) = list.also { removeAll(it) }
|
||||
|
||||
@@ -10,6 +10,7 @@ val client = HttpClient.newBuilder().build()
|
||||
fun HttpRequest.Builder.send() = client.send(this.build(), HttpResponse.BodyHandlers.ofString())
|
||||
fun HttpRequest.Builder.header(pair: Pair<Any, Any>) = this.header(pair.first.toString(), pair.second.toString())
|
||||
fun String.request() = HttpRequest.newBuilder(URI.create(this))
|
||||
inline fun <reified T> String.postJson(body: Any) = request().post(body).json<T>()
|
||||
|
||||
fun HttpRequest.Builder.post(body: Any? = null) = this.POST(when (body) {
|
||||
is ByteArray -> HttpRequest.BodyPublishers.ofByteArray(body)
|
||||
@@ -17,3 +18,6 @@ fun HttpRequest.Builder.post(body: Any? = null) = this.POST(when (body) {
|
||||
is HttpRequest.BodyPublisher -> body
|
||||
else -> throw Exception("Unsupported body type")
|
||||
}).send()
|
||||
|
||||
inline fun <reified T> HttpResponse<String>.json(): T = body().json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user