mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-21 15:53: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
|
||||
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 {
|
||||
|
@ -1,34 +1,36 @@
|
||||
package dev.inmo.tgbotapi.webapps.cloud
|
||||
|
||||
import kotlin.js.Json
|
||||
|
||||
external interface CloudStorage {
|
||||
fun setItem(
|
||||
key: CloudStorageKey,
|
||||
value: CloudStorageValue,
|
||||
callback: (e: Error?, success: Boolean?) -> Unit = definedExternally
|
||||
callback: (e: Any?, success: Boolean?) -> Unit = definedExternally
|
||||
): CloudStorage
|
||||
fun getItem(
|
||||
key: CloudStorageKey,
|
||||
callback: (e: Error?, value: CloudStorageValue?) -> Unit
|
||||
callback: (e: Any?, value: CloudStorageValue?) -> Unit
|
||||
): CloudStorage
|
||||
fun getItems(
|
||||
key: Array<CloudStorageKey>,
|
||||
callback: (e: Error?, values: Array<CloudStorageValue>?) -> Unit
|
||||
callback: (e: Any?, values: Array<CloudStorageValue>?) -> Unit
|
||||
): CloudStorage
|
||||
fun removeItem(
|
||||
key: CloudStorageKey,
|
||||
callback: (e: Error?, success: Boolean?) -> Unit
|
||||
callback: (e: Any?, success: Boolean?) -> Unit
|
||||
): CloudStorage
|
||||
fun removeItems(
|
||||
key: Array<CloudStorageKey>,
|
||||
callback: (e: Error?, success: Boolean?) -> Unit
|
||||
callback: (e: Any?, success: Boolean?) -> Unit
|
||||
): CloudStorage
|
||||
fun getKeys(
|
||||
callback: (e: Error?, success: Array<CloudStorageKey>?) -> Unit
|
||||
callback: (e: Any?, success: Array<CloudStorageKey>?) -> Unit
|
||||
): CloudStorage
|
||||
}
|
||||
|
||||
private fun <T> resultsToResult(e: Error?, v: T?): Result<T> = when {
|
||||
e != null -> Result.failure(e)
|
||||
private fun <T> resultsToResult(e: Any?, v: T?): Result<T> = when {
|
||||
e != null -> Result.failure(IllegalStateException(JSON.stringify(e)))
|
||||
v != null -> Result.success(v)
|
||||
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 {
|
||||
it.onSuccess { keys ->
|
||||
console.log(keys)
|
||||
get(keys) {
|
||||
it.onSuccess { values ->
|
||||
console.log(values)
|
||||
val resultMap = keys.withIndex().mapNotNull { (i, it) ->
|
||||
it to (values.getOrNull(i) ?: return@mapNotNull null)
|
||||
}.toMap()
|
||||
|
Loading…
Reference in New Issue
Block a user