mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-07 21:04:34 -05:00
Update Titles from the Source (#1115)
* Update Titles from the source * Properly keep null fields
This commit is contained in:
@@ -25,34 +25,6 @@ interface SManga : Serializable {
|
|||||||
|
|
||||||
var initialized: Boolean
|
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 {
|
companion object {
|
||||||
const val UNKNOWN = 0
|
const val UNKNOWN = 0
|
||||||
const val ONGOING = 1
|
const val ONGOING = 1
|
||||||
|
|||||||
@@ -115,28 +115,42 @@ object Manga {
|
|||||||
getCatalogueSourceOrNull(mangaEntry[MangaTable.sourceReference])
|
getCatalogueSourceOrNull(mangaEntry[MangaTable.sourceReference])
|
||||||
?: return null
|
?: return null
|
||||||
val sManga =
|
val sManga =
|
||||||
SManga.create().apply {
|
source.getMangaDetails(
|
||||||
url = mangaEntry[MangaTable.url]
|
SManga.create().apply {
|
||||||
title = mangaEntry[MangaTable.title]
|
url = mangaEntry[MangaTable.url]
|
||||||
}
|
title = mangaEntry[MangaTable.title]
|
||||||
val networkManga = source.getMangaDetails(sManga)
|
thumbnail_url = mangaEntry[MangaTable.thumbnail_url]
|
||||||
sManga.copyFrom(networkManga)
|
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 {
|
transaction {
|
||||||
MangaTable.update({ MangaTable.id eq mangaId }) {
|
MangaTable.update({ MangaTable.id eq mangaId }) {
|
||||||
if (sManga.title != mangaEntry[MangaTable.title]) {
|
val remoteTitle =
|
||||||
val canUpdateTitle = updateMangaDownloadDir(mangaId, sManga.title)
|
try {
|
||||||
|
sManga.title
|
||||||
|
} catch (_: UninitializedPropertyAccessException) {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
if (remoteTitle.isNotEmpty() && remoteTitle != mangaEntry[MangaTable.title]) {
|
||||||
|
val canUpdateTitle = updateMangaDownloadDir(mangaId, remoteTitle)
|
||||||
|
|
||||||
if (canUpdateTitle) {
|
if (canUpdateTitle) {
|
||||||
it[MangaTable.title] = sManga.title
|
it[MangaTable.title] = remoteTitle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it[MangaTable.initialized] = true
|
it[MangaTable.initialized] = true
|
||||||
|
|
||||||
it[MangaTable.artist] = sManga.artist
|
it[MangaTable.artist] = sManga.artist ?: mangaEntry[MangaTable.artist]
|
||||||
it[MangaTable.author] = sManga.author
|
it[MangaTable.author] = sManga.author ?: mangaEntry[MangaTable.author]
|
||||||
it[MangaTable.description] = truncate(sManga.description, 4096)
|
it[MangaTable.description] = sManga.description?.let { truncate(it, 4096) }
|
||||||
it[MangaTable.genre] = sManga.genre
|
?: mangaEntry[MangaTable.description]
|
||||||
|
it[MangaTable.genre] = sManga.genre ?: mangaEntry[MangaTable.genre]
|
||||||
it[MangaTable.status] = sManga.status
|
it[MangaTable.status] = sManga.status
|
||||||
if (!sManga.thumbnail_url.isNullOrEmpty() && sManga.thumbnail_url != mangaEntry[MangaTable.thumbnail_url]) {
|
if (!sManga.thumbnail_url.isNullOrEmpty() && sManga.thumbnail_url != mangaEntry[MangaTable.thumbnail_url]) {
|
||||||
it[MangaTable.thumbnail_url] = sManga.thumbnail_url
|
it[MangaTable.thumbnail_url] = sManga.thumbnail_url
|
||||||
|
|||||||
Reference in New Issue
Block a user