Mangadex fixes
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user