add realUrl to Manga, reperesents open in WebView URL

This commit is contained in:
Aria Moradi
2021-08-26 22:11:51 +04:30
parent 87f5e9b847
commit dfaecc08c5
6 changed files with 41 additions and 22 deletions

View File

@@ -9,7 +9,6 @@ package suwayomi.tachidesk.manga.impl
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
@@ -61,17 +60,17 @@ object Manga {
MangaStatus.valueOf(mangaEntry[MangaTable.status]).name, MangaStatus.valueOf(mangaEntry[MangaTable.status]).name,
mangaEntry[MangaTable.inLibrary], mangaEntry[MangaTable.inLibrary],
getSource(mangaEntry[MangaTable.sourceReference]), getSource(mangaEntry[MangaTable.sourceReference]),
getMangaMetaMap(mangaEntry[MangaTable.id]), getMangaMetaMap(mangaId),
mangaEntry[MangaTable.realUrl],
false false
) )
} else { // initialize manga } else { // initialize manga
val source = getHttpSource(mangaEntry[MangaTable.sourceReference]) val source = getHttpSource(mangaEntry[MangaTable.sourceReference])
val fetchedManga = source.fetchMangaDetails( val sManga = SManga.create().apply {
SManga.create().apply {
url = mangaEntry[MangaTable.url] url = mangaEntry[MangaTable.url]
title = mangaEntry[MangaTable.title] title = mangaEntry[MangaTable.title]
} }
).awaitSingle() val fetchedManga = source.fetchMangaDetails(sManga).awaitSingle()
transaction { transaction {
MangaTable.update({ MangaTable.id eq mangaId }) { MangaTable.update({ MangaTable.id eq mangaId }) {
@@ -85,6 +84,8 @@ object Manga {
it[MangaTable.status] = fetchedManga.status it[MangaTable.status] = fetchedManga.status
if (fetchedManga.thumbnail_url != null && fetchedManga.thumbnail_url.orEmpty().isNotEmpty()) if (fetchedManga.thumbnail_url != null && fetchedManga.thumbnail_url.orEmpty().isNotEmpty())
it[MangaTable.thumbnail_url] = fetchedManga.thumbnail_url it[MangaTable.thumbnail_url] = fetchedManga.thumbnail_url
it[MangaTable.realUrl] = source.mangaDetailsRequest(sManga).url.toString()
} }
} }
@@ -109,13 +110,14 @@ object Manga {
MangaStatus.valueOf(fetchedManga.status).name, MangaStatus.valueOf(fetchedManga.status).name,
mangaEntry[MangaTable.inLibrary], mangaEntry[MangaTable.inLibrary],
getSource(mangaEntry[MangaTable.sourceReference]), getSource(mangaEntry[MangaTable.sourceReference]),
getMangaMetaMap(mangaEntry[MangaTable.id]), getMangaMetaMap(mangaId),
mangaEntry[MangaTable.realUrl],
true true
) )
} }
} }
fun getMangaMetaMap(manga: EntityID<Int>): Map<String, String> { fun getMangaMetaMap(manga: Int): Map<String, String> {
return transaction { return transaction {
MangaMetaTable.select { MangaMetaTable.ref eq manga } MangaMetaTable.select { MangaMetaTable.ref eq manga }
.associate { it[MangaMetaTable.key] to it[MangaMetaTable.value] } .associate { it[MangaMetaTable.key] to it[MangaMetaTable.value] }
@@ -126,7 +128,8 @@ object Manga {
transaction { transaction {
val manga = MangaMetaTable.select { (MangaTable.id eq mangaId) } val manga = MangaMetaTable.select { (MangaTable.id eq mangaId) }
.first()[MangaTable.id] .first()[MangaTable.id]
val meta = transaction { MangaMetaTable.select { (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) } }.firstOrNull() val meta =
transaction { MangaMetaTable.select { (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) } }.firstOrNull()
if (meta == null) { if (meta == null) {
MangaMetaTable.insert { MangaMetaTable.insert {
it[MangaMetaTable.key] = key it[MangaMetaTable.key] = key

View File

@@ -57,6 +57,8 @@ object MangaList {
it[sourceReference] = sourceId it[sourceReference] = sourceId
}.value }.value
val mangaEntry = MangaTable.select { MangaTable.url eq manga.url }.first()
MangaDataClass( MangaDataClass(
mangaId, mangaId,
sourceId.toString(), sourceId.toString(),
@@ -71,7 +73,11 @@ object MangaList {
manga.author, manga.author,
manga.description, manga.description,
manga.genre, manga.genre,
MangaStatus.valueOf(manga.status).name MangaStatus.valueOf(manga.status).name,
false, // It's a new manga entry
meta = getMangaMetaMap(mangaId),
realUrl = mangaEntry[MangaTable.realUrl],
freshData = true
) )
} else { } else {
val mangaId = mangaEntry[MangaTable.id].value val mangaId = mangaEntry[MangaTable.id].value
@@ -91,7 +97,9 @@ object MangaList {
mangaEntry[MangaTable.genre], mangaEntry[MangaTable.genre],
MangaStatus.valueOf(mangaEntry[MangaTable.status]).name, MangaStatus.valueOf(mangaEntry[MangaTable.status]).name,
mangaEntry[MangaTable.inLibrary], mangaEntry[MangaTable.inLibrary],
meta = getMangaMetaMap(mangaEntry[MangaTable.id]) meta = getMangaMetaMap(mangaId),
realUrl = mangaEntry[MangaTable.realUrl],
freshData = false
) )
} }
} }

View File

@@ -26,9 +26,13 @@ data class MangaDataClass(
val status: String = MangaStatus.UNKNOWN.name, val status: String = MangaStatus.UNKNOWN.name,
val inLibrary: Boolean = false, val inLibrary: Boolean = false,
val source: SourceDataClass? = null, val source: SourceDataClass? = null,
/** meta data for clients */
val meta: Map<String, String> = emptyMap(), val meta: Map<String, String> = emptyMap(),
val freshData: Boolean = false val realUrl: String? = null,
val freshData: Boolean = false,
) )
data class PagedMangaListDataClass( data class PagedMangaListDataClass(

View File

@@ -31,8 +31,11 @@ object MangaTable : IntIdTable() {
val inLibrary = bool("in_library").default(false) val inLibrary = bool("in_library").default(false)
val defaultCategory = bool("default_category").default(true) val defaultCategory = bool("default_category").default(true)
// source is used by some ancestor of IntIdTable // the [source] field name is used by some ancestor of IntIdTable
val sourceReference = long("source") val sourceReference = long("source")
/** the real url of a manga used for the "open in WebView" feature */
val realUrl = varchar("real_url", 2048).nullable()
} }
fun MangaTable.toDataClass(mangaEntry: ResultRow) = fun MangaTable.toDataClass(mangaEntry: ResultRow) =
@@ -52,7 +55,8 @@ fun MangaTable.toDataClass(mangaEntry: ResultRow) =
mangaEntry[genre], mangaEntry[genre],
Companion.valueOf(mangaEntry[status]).name, Companion.valueOf(mangaEntry[status]).name,
mangaEntry[inLibrary], mangaEntry[inLibrary],
meta = getMangaMetaMap(mangaEntry[id]) meta = getMangaMetaMap(mangaEntry[id].value),
realUrl = mangaEntry[realUrl],
) )
enum class MangaStatus(val value: Int) { enum class MangaStatus(val value: Int) {

View File

@@ -10,9 +10,9 @@ package suwayomi.tachidesk.server.database.migration
import de.neonew.exposed.migrations.helpers.AddColumnMigration import de.neonew.exposed.migrations.helpers.AddColumnMigration
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0011_SourceIsNsfw : AddColumnMigration( class M0013_MangaRealUrl : AddColumnMigration(
"Source", "Manga",
"is_nsfw", "real_url",
"BOOLEAN", "VARCHAR(2048)",
"FALSE" "NULL"
) )