fix(anilist): Fix null recommendation node

(cherry picked from commit 305f8db0adcf821962a539867b5704fbf229461e)
This commit is contained in:
Cuong-Tran 2025-06-16 16:49:12 +07:00
parent 5ec780eddb
commit d0823ef3f6
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2

View file

@ -88,18 +88,24 @@ class AniListPagingSource(manga: Manga) : TrackerRecommendationPagingSource(
.ifEmpty { throw NoResultsException() } .ifEmpty { throw NoResultsException() }
.filter() .filter()
return media.flatMap { it.jsonObject["recommendations"]!!.jsonObject["edges"]!!.jsonArray }.map { return media.flatMap { it.jsonObject["recommendations"]!!.jsonObject["edges"]!!.jsonArray }.mapNotNull { edge ->
val rec = it.jsonObject["node"]!!.jsonObject["mediaRecommendation"]!!.jsonObject edge.jsonObject["node"]?.let { node ->
node.jsonObject["mediaRecommendation"]?.takeIf { it is JsonObject }?.let { media ->
val rec = media.jsonObject
val recTitle = getTitle(rec) val recTitle = getTitle(rec)
logcat { "ANILIST > RECOMMENDATION: $recTitle" } logcat { "ANILIST > RECOMMENDATION: $recTitle" }
rec["siteUrl"]?.jsonPrimitive?.contentOrNull?.let { url ->
SManga( SManga(
title = recTitle, title = recTitle,
thumbnail_url = rec["coverImage"]!!.jsonObject["large"]!!.jsonPrimitive.content, thumbnail_url = rec["coverImage"]?.jsonObject?.get("large")?.jsonPrimitive?.contentOrNull,
initialized = true, initialized = true,
url = rec["siteUrl"]!!.jsonPrimitive.content, url = url,
) )
} }
} }
}
}
}
override suspend fun getRecsById(id: String): List<SManga> { override suspend fun getRecsById(id: String): List<SManga> {
val query = val query =