diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/Colors.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/Colors.kt index 270fef6920..ca3a2480fc 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/Colors.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/Colors.kt @@ -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 { diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/cloud/CloudStorage.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/cloud/CloudStorage.kt index 27172a8ce6..251858f616 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/cloud/CloudStorage.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/cloud/CloudStorage.kt @@ -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, - callback: (e: Error?, values: Array?) -> Unit + callback: (e: Any?, values: Array?) -> Unit ): CloudStorage fun removeItem( key: CloudStorageKey, - callback: (e: Error?, success: Boolean?) -> Unit + callback: (e: Any?, success: Boolean?) -> Unit ): CloudStorage fun removeItems( key: Array, - callback: (e: Error?, success: Boolean?) -> Unit + callback: (e: Any?, success: Boolean?) -> Unit ): CloudStorage fun getKeys( - callback: (e: Error?, success: Array?) -> Unit + callback: (e: Any?, success: Array?) -> Unit ): CloudStorage } -private fun resultsToResult(e: Error?, v: T?): Result = when { - e != null -> Result.failure(e) +private fun resultsToResult(e: Any?, v: T?): Result = 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>) -> 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()