Mangadex fixes

This commit is contained in:
Jobobby04
2021-07-10 17:27:21 -04:00
parent 7377892942
commit e6cb339ff5
5 changed files with 24 additions and 12 deletions
@@ -2,6 +2,10 @@ package exh.md.utils
import exh.md.dto.ListCallDto
import exh.util.under
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
suspend fun <T> mdListCall(request: suspend (offset: Int) -> ListCallDto<T>): List<T> {
val results = mutableListOf<T>()
@@ -15,3 +19,9 @@ suspend fun <T> mdListCall(request: suspend (offset: Int) -> ListCallDto<T>): Li
return results
}
fun JsonElement.asMdMap(): Map<String, String> {
return runCatching {
jsonObject.map { it.key to it.value.jsonPrimitive.contentOrNull.orEmpty() }.toMap()
}.getOrElse { emptyMap() }
}