mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
improvements and fixes in web apps api
This commit is contained in:
parent
821bb5b45c
commit
efe286c181
@ -9,7 +9,7 @@ sealed interface Color {
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
value class Hex(override val value: String) : Color {
|
value class Hex(override val value: String) : Color {
|
||||||
constructor(r: UByte, g: UByte, b: UByte) : this("#${r.toString(16)}${g.toString(16)}${b.toString(16)}")
|
constructor(r: UByte, g: UByte, b: UByte) : this("#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}")
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -1,34 +1,36 @@
|
|||||||
package dev.inmo.tgbotapi.webapps.cloud
|
package dev.inmo.tgbotapi.webapps.cloud
|
||||||
|
|
||||||
|
import kotlin.js.Json
|
||||||
|
|
||||||
external interface CloudStorage {
|
external interface CloudStorage {
|
||||||
fun setItem(
|
fun setItem(
|
||||||
key: CloudStorageKey,
|
key: CloudStorageKey,
|
||||||
value: CloudStorageValue,
|
value: CloudStorageValue,
|
||||||
callback: (e: Error?, success: Boolean?) -> Unit = definedExternally
|
callback: (e: Any?, success: Boolean?) -> Unit = definedExternally
|
||||||
): CloudStorage
|
): CloudStorage
|
||||||
fun getItem(
|
fun getItem(
|
||||||
key: CloudStorageKey,
|
key: CloudStorageKey,
|
||||||
callback: (e: Error?, value: CloudStorageValue?) -> Unit
|
callback: (e: Any?, value: CloudStorageValue?) -> Unit
|
||||||
): CloudStorage
|
): CloudStorage
|
||||||
fun getItems(
|
fun getItems(
|
||||||
key: Array<CloudStorageKey>,
|
key: Array<CloudStorageKey>,
|
||||||
callback: (e: Error?, values: Array<CloudStorageValue>?) -> Unit
|
callback: (e: Any?, values: Array<CloudStorageValue>?) -> Unit
|
||||||
): CloudStorage
|
): CloudStorage
|
||||||
fun removeItem(
|
fun removeItem(
|
||||||
key: CloudStorageKey,
|
key: CloudStorageKey,
|
||||||
callback: (e: Error?, success: Boolean?) -> Unit
|
callback: (e: Any?, success: Boolean?) -> Unit
|
||||||
): CloudStorage
|
): CloudStorage
|
||||||
fun removeItems(
|
fun removeItems(
|
||||||
key: Array<CloudStorageKey>,
|
key: Array<CloudStorageKey>,
|
||||||
callback: (e: Error?, success: Boolean?) -> Unit
|
callback: (e: Any?, success: Boolean?) -> Unit
|
||||||
): CloudStorage
|
): CloudStorage
|
||||||
fun getKeys(
|
fun getKeys(
|
||||||
callback: (e: Error?, success: Array<CloudStorageKey>?) -> Unit
|
callback: (e: Any?, success: Array<CloudStorageKey>?) -> Unit
|
||||||
): CloudStorage
|
): CloudStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> resultsToResult(e: Error?, v: T?): Result<T> = when {
|
private fun <T> resultsToResult(e: Any?, v: T?): Result<T> = when {
|
||||||
e != null -> Result.failure(e)
|
e != null -> Result.failure(IllegalStateException(JSON.stringify(e)))
|
||||||
v != null -> Result.success(v)
|
v != null -> Result.success(v)
|
||||||
else -> Result.failure(IllegalStateException("Both value and e"))
|
else -> Result.failure(IllegalStateException("Both value and e"))
|
||||||
}
|
}
|
||||||
@ -119,8 +121,10 @@ fun CloudStorage.keys(
|
|||||||
|
|
||||||
fun CloudStorage.getAll(callback: (result: Result<Map<CloudStorageKey, CloudStorageValue>>) -> Unit) = keys {
|
fun CloudStorage.getAll(callback: (result: Result<Map<CloudStorageKey, CloudStorageValue>>) -> Unit) = keys {
|
||||||
it.onSuccess { keys ->
|
it.onSuccess { keys ->
|
||||||
|
console.log(keys)
|
||||||
get(keys) {
|
get(keys) {
|
||||||
it.onSuccess { values ->
|
it.onSuccess { values ->
|
||||||
|
console.log(values)
|
||||||
val resultMap = keys.withIndex().mapNotNull { (i, it) ->
|
val resultMap = keys.withIndex().mapNotNull { (i, it) ->
|
||||||
it to (values.getOrNull(i) ?: return@mapNotNull null)
|
it to (values.getOrNull(i) ?: return@mapNotNull null)
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
Loading…
Reference in New Issue
Block a user