From 9a51472726079b30f73eef8c19716061328c715b Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Thu, 14 Nov 2024 18:08:31 -0500 Subject: [PATCH] Update Titles from the Source (#1115) * Update Titles from the source * Properly keep null fields --- .../kanade/tachiyomi/source/model/SManga.kt | 28 ------------- .../suwayomi/tachidesk/manga/impl/Manga.kt | 40 +++++++++++++------ 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/source/model/SManga.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/source/model/SManga.kt index d4652ac8..f50e430b 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/source/model/SManga.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/source/model/SManga.kt @@ -25,34 +25,6 @@ interface SManga : Serializable { var initialized: Boolean - fun copyFrom(other: SManga) { - if (other.author != null) { - author = other.author - } - - if (other.artist != null) { - artist = other.artist - } - - if (other.description != null) { - description = other.description - } - - if (other.genre != null) { - genre = other.genre - } - - if (other.thumbnail_url != null) { - thumbnail_url = other.thumbnail_url - } - - status = other.status - - if (!initialized) { - initialized = other.initialized - } - } - companion object { const val UNKNOWN = 0 const val ONGOING = 1 diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Manga.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Manga.kt index 61969276..289f5575 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Manga.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Manga.kt @@ -115,28 +115,42 @@ object Manga { getCatalogueSourceOrNull(mangaEntry[MangaTable.sourceReference]) ?: return null val sManga = - SManga.create().apply { - url = mangaEntry[MangaTable.url] - title = mangaEntry[MangaTable.title] - } - val networkManga = source.getMangaDetails(sManga) - sManga.copyFrom(networkManga) + source.getMangaDetails( + SManga.create().apply { + url = mangaEntry[MangaTable.url] + title = mangaEntry[MangaTable.title] + thumbnail_url = mangaEntry[MangaTable.thumbnail_url] + artist = mangaEntry[MangaTable.artist] + author = mangaEntry[MangaTable.author] + description = mangaEntry[MangaTable.description] + genre = mangaEntry[MangaTable.genre] + status = mangaEntry[MangaTable.status] + update_strategy = UpdateStrategy.valueOf(mangaEntry[MangaTable.updateStrategy]) + }, + ) transaction { MangaTable.update({ MangaTable.id eq mangaId }) { - if (sManga.title != mangaEntry[MangaTable.title]) { - val canUpdateTitle = updateMangaDownloadDir(mangaId, sManga.title) + val remoteTitle = + try { + sManga.title + } catch (_: UninitializedPropertyAccessException) { + "" + } + if (remoteTitle.isNotEmpty() && remoteTitle != mangaEntry[MangaTable.title]) { + val canUpdateTitle = updateMangaDownloadDir(mangaId, remoteTitle) if (canUpdateTitle) { - it[MangaTable.title] = sManga.title + it[MangaTable.title] = remoteTitle } } it[MangaTable.initialized] = true - it[MangaTable.artist] = sManga.artist - it[MangaTable.author] = sManga.author - it[MangaTable.description] = truncate(sManga.description, 4096) - it[MangaTable.genre] = sManga.genre + it[MangaTable.artist] = sManga.artist ?: mangaEntry[MangaTable.artist] + it[MangaTable.author] = sManga.author ?: mangaEntry[MangaTable.author] + it[MangaTable.description] = sManga.description?.let { truncate(it, 4096) } + ?: mangaEntry[MangaTable.description] + it[MangaTable.genre] = sManga.genre ?: mangaEntry[MangaTable.genre] it[MangaTable.status] = sManga.status if (!sManga.thumbnail_url.isNullOrEmpty() && sManga.thumbnail_url != mangaEntry[MangaTable.thumbnail_url]) { it[MangaTable.thumbnail_url] = sManga.thumbnail_url