From 1e8fec699cc9a1ee286dfa3ef46145b278612178 Mon Sep 17 00:00:00 2001 From: zhongfly <11155705+zhongfly@users.noreply.github.com> Date: Thu, 14 Aug 2025 22:37:55 +0800 Subject: [PATCH] zaimanhua: update MangaDto and PageItemDto to handle nullable fields (#10111) Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> --- .../extension/zh/zaimanhua/ZaimanhuaDto.kt | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/zh/zaimanhua/src/eu/kanade/tachiyomi/extension/zh/zaimanhua/ZaimanhuaDto.kt b/src/zh/zaimanhua/src/eu/kanade/tachiyomi/extension/zh/zaimanhua/ZaimanhuaDto.kt index 74b5a0de5..c57faf038 100644 --- a/src/zh/zaimanhua/src/eu/kanade/tachiyomi/extension/zh/zaimanhua/ZaimanhuaDto.kt +++ b/src/zh/zaimanhua/src/eu/kanade/tachiyomi/extension/zh/zaimanhua/ZaimanhuaDto.kt @@ -11,25 +11,25 @@ import kotlinx.serialization.json.JsonNames class MangaDto( private val id: Int, private val title: String, - private val cover: String, - private val description: String? = null, - private val types: List, - private val status: List, - private val authors: List? = null, + private val cover: String?, + private val description: String?, + private val types: List?, + private val status: List?, + private val authors: List?, @SerialName("chapters") private val chapterGroups: List, @SerialName("last_update_chapter_id") - private val lastUpdateChapterId: Int = 0, + private val lastUpdateChapterId: Int, @SerialName("last_updatetime") - private val lastUpdateTime: Long = 0, + private val lastUpdateTime: Long, ) { fun toSManga() = SManga.create().apply { url = id.toString() title = this@MangaDto.title author = authors?.joinToString { it.name } description = this@MangaDto.description - genre = types.joinToString { it.name } - status = parseStatus(this@MangaDto.status[0].name) + genre = types?.joinToString { it.name } + status = parseStatus(this@MangaDto.status?.firstOrNull()?.name.orEmpty()) thumbnail_url = cover initialized = true } @@ -80,12 +80,12 @@ class ChapterDto( @SerialName("chapter_title") private val name: String, @SerialName("updatetime") - private val updateTime: Long = 0, + private val updateTime: Long?, ) { fun toSChapterInternal() = SChapter.create().apply { url = id.toString() name = this@ChapterDto.name.formatChapterName() - date_upload = updateTime * 1000 + date_upload = updateTime?.times(1000) ?: 0L } } @@ -112,25 +112,21 @@ class PageDto( @Serializable class PageItemDto( - private val id: Int = 0, + private val id: Int?, @SerialName("comic_id") - private val comicId: Int = 0, + private val comicId: Int, private val title: String, - private val authors: String = "", - private val status: String, - private val cover: String, - private val types: String, + private val authors: String?, + private val status: String?, + private val cover: String?, + private val types: String?, ) { fun toSManga() = SManga.create().apply { - url = if (this@PageItemDto.id != 0) { - this@PageItemDto.id.toString() - } else { - this@PageItemDto.comicId.toString() - } + url = (this@PageItemDto.id?.takeIf { it != 0 } ?: this@PageItemDto.comicId).toString() title = this@PageItemDto.title - author = authors.formatList() - genre = types.formatList() - status = parseStatus(this@PageItemDto.status) + author = authors?.formatList() + genre = types?.formatList() + status = parseStatus(this@PageItemDto.status ?: "") thumbnail_url = cover } } @@ -159,12 +155,12 @@ class DataWrapperDto( @Serializable class SimpleResponseDto( - val errno: Int = 0, + val errno: Int? = 0, ) @Serializable class ResponseDto( - val errno: Int = 0, + val errno: Int? = 0, val errmsg: String = "", val data: T, )