fix(myanimelist): Fix nullability and fallback to medium cover if large

cover is null

(cherry picked from commit a3672be7282c553017d35b310fb5a148d677ff14)
This commit is contained in:
Ahmad Ansori Palembani 2025-01-03 10:44:38 +07:00 committed by Cuong-Tran
parent eddabbc04e
commit 136bfe2833
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
2 changed files with 5 additions and 5 deletions

View file

@ -113,7 +113,7 @@ class MyAnimeListApi(
summary = it.synopsis
total_chapters = it.numChapters
score = it.mean
cover_url = it.covers.large
cover_url = (it.covers?.large ?: it.covers?.medium).orEmpty()
tracking_url = "https://myanimelist.net/manga/$remote_id"
publishing_status = it.status.replace("_", " ")
publishing_type = it.mediaType.replace("_", " ")
@ -195,7 +195,7 @@ class MyAnimeListApi(
}
}
suspend fun getMangaMetadata(track: DomainTrack): TrackMangaMetadata? {
suspend fun getMangaMetadata(track: DomainTrack): TrackMangaMetadata {
return withIOContext {
val url = "$BASE_API_URL/manga".toUri().buildUpon()
.appendPath(track.remoteId.toString())
@ -212,7 +212,7 @@ class MyAnimeListApi(
TrackMangaMetadata(
remoteId = it.id,
title = it.title,
thumbnailUrl = it.covers.large.ifEmpty { null } ?: it.covers.medium,
thumbnailUrl = it.covers.large?.ifEmpty { null } ?: it.covers.medium,
description = it.synopsis,
authors = it.authors
.filter { it.role == "Story" || it.role == "Story & Art" }

View file

@ -12,7 +12,7 @@ data class MALManga(
val numChapters: Long,
val mean: Double = -1.0,
@SerialName("main_picture")
val covers: MALMangaCovers,
val covers: MALMangaCovers?,
val status: String,
@SerialName("media_type")
val mediaType: String,
@ -22,7 +22,7 @@ data class MALManga(
@Serializable
data class MALMangaCovers(
val large: String = "",
val large: String?,
val medium: String,
)