mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
improve cloud storage
This commit is contained in:
parent
c92ed92f7c
commit
821bb5b45c
@ -39,47 +39,97 @@ fun CloudStorage.set(
|
|||||||
callback: (result: Result<Boolean>) -> Unit = {}
|
callback: (result: Result<Boolean>) -> Unit = {}
|
||||||
) = setItem(CloudStorageKey(key), CloudStorageValue(value)) { e, v -> callback(resultsToResult(e, v)) }
|
) = setItem(CloudStorageKey(key), CloudStorageValue(value)) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
key: CloudStorageKey,
|
||||||
|
callback: (result: Result<CloudStorageValue>) -> Unit
|
||||||
|
) = getItem(key) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
fun CloudStorage.get(
|
fun CloudStorage.get(
|
||||||
key: String,
|
key: String,
|
||||||
callback: (result: Result<CloudStorageValue>) -> Unit
|
callback: (result: Result<CloudStorageValue>) -> Unit
|
||||||
) = getItem(CloudStorageKey(key)) { e, v -> callback(resultsToResult(e, v)) }
|
) = get(CloudStorageKey(key), callback)
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
keys: Array<CloudStorageKey>,
|
||||||
|
callback: (result: Result<Array<CloudStorageValue>>) -> Unit
|
||||||
|
) = getItems(
|
||||||
|
keys
|
||||||
|
) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
keys: Array<String>,
|
||||||
|
callback: (result: Result<Array<CloudStorageValue>>) -> Unit
|
||||||
|
) = get(
|
||||||
|
Array(keys.size) {
|
||||||
|
CloudStorageKey(keys[it])
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
fun CloudStorage.get(
|
fun CloudStorage.get(
|
||||||
key: String,
|
key: String,
|
||||||
key2: String,
|
key2: String,
|
||||||
vararg otherKeys: String,
|
vararg otherKeys: String,
|
||||||
callback: (result: Result<Array<CloudStorageValue>>) -> Unit
|
callback: (result: Result<Array<CloudStorageValue>>) -> Unit
|
||||||
) = getItems(
|
) = get(
|
||||||
Array(2 + otherKeys.size) {
|
arrayOf(key, key2) + otherKeys,
|
||||||
when (it) {
|
callback
|
||||||
0 -> CloudStorageKey(key)
|
)
|
||||||
1 -> CloudStorageKey(key2)
|
|
||||||
else -> CloudStorageKey(otherKeys[it - 2])
|
fun CloudStorage.remove(
|
||||||
}
|
key: CloudStorageKey,
|
||||||
}
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
) { e, v -> callback(resultsToResult(e, v)) }
|
) = removeItem(key) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
fun CloudStorage.remove(
|
fun CloudStorage.remove(
|
||||||
key: String,
|
key: String,
|
||||||
callback: (result: Result<Boolean>) -> Unit
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
) = removeItem(CloudStorageKey(key)) { e, v -> callback(resultsToResult(e, v)) }
|
) = remove(CloudStorageKey(key), callback)
|
||||||
|
|
||||||
|
fun CloudStorage.remove(
|
||||||
|
keys: Array<CloudStorageKey>,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
|
) = removeItems(
|
||||||
|
keys
|
||||||
|
) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.remove(
|
||||||
|
keys: Array<String>,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
|
) = remove(
|
||||||
|
Array(keys.size) {
|
||||||
|
CloudStorageKey(keys[it])
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
fun CloudStorage.remove(
|
fun CloudStorage.remove(
|
||||||
key: String,
|
key: String,
|
||||||
key2: String,
|
key2: String,
|
||||||
vararg otherKeys: String,
|
vararg otherKeys: String,
|
||||||
callback: (result: Result<Boolean>) -> Unit
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
) = removeItems(
|
) = remove(
|
||||||
Array(2 + otherKeys.size) {
|
arrayOf(key, key2) + otherKeys,
|
||||||
when (it) {
|
callback
|
||||||
0 -> CloudStorageKey(key)
|
)
|
||||||
1 -> CloudStorageKey(key2)
|
|
||||||
else -> CloudStorageKey(otherKeys[it - 2])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) { e, v -> callback(resultsToResult(e, v)) }
|
|
||||||
|
|
||||||
fun CloudStorage.keys(
|
fun CloudStorage.keys(
|
||||||
callback: (result: Result<Array<CloudStorageKey>>) -> Unit
|
callback: (result: Result<Array<CloudStorageKey>>) -> Unit
|
||||||
) = getKeys { e, v -> callback(resultsToResult(e, v)) }
|
) = getKeys { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.getAll(callback: (result: Result<Map<CloudStorageKey, CloudStorageValue>>) -> Unit) = keys {
|
||||||
|
it.onSuccess { keys ->
|
||||||
|
get(keys) {
|
||||||
|
it.onSuccess { values ->
|
||||||
|
val resultMap = keys.withIndex().mapNotNull { (i, it) ->
|
||||||
|
it to (values.getOrNull(i) ?: return@mapNotNull null)
|
||||||
|
}.toMap()
|
||||||
|
callback(Result.success(resultMap))
|
||||||
|
}.onFailure {
|
||||||
|
callback(Result.failure(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.onFailure {
|
||||||
|
callback(Result.failure(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user