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() }
}
+1 -1
View File
@@ -265,7 +265,7 @@ class MdUtil {
fun createMangaEntry(json: MangaDto, lang: String): MangaInfo {
return MangaInfo(
key = buildMangaUrl(json.data.id),
title = cleanString(json.data.attributes.title[lang] ?: json.data.attributes.title["en"]!!),
title = cleanString(json.data.attributes.title.asMdMap().let { it[lang] ?: it["en"]!! }),
cover = json.relationships
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
?.attributes