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
@@ -9,7 +9,6 @@ package suwayomi.tachidesk.manga.impl
import eu.kanade.tachiyomi.network.GET
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.insert
import org.jetbrains.exposed.sql.select
@@ -61,17 +60,17 @@ object Manga {
MangaStatus.valueOf(mangaEntry[MangaTable.status]).name,
mangaEntry[MangaTable.inLibrary],
getSource(mangaEntry[MangaTable.sourceReference]),
getMangaMetaMap(mangaEntry[MangaTable.id]),
getMangaMetaMap(mangaId),
mangaEntry[MangaTable.realUrl],
false
)
} else { // initialize manga
val source = getHttpSource(mangaEntry[MangaTable.sourceReference])
val fetchedManga = source.fetchMangaDetails(
SManga.create().apply {
url = mangaEntry[MangaTable.url]
title = mangaEntry[MangaTable.title]
}
).awaitSingle()
val sManga = SManga.create().apply {
url = mangaEntry[MangaTable.url]
title = mangaEntry[MangaTable.title]
}
val fetchedManga = source.fetchMangaDetails(sManga).awaitSingle()
transaction {
MangaTable.update({ MangaTable.id eq mangaId }) {
@@ -85,6 +84,8 @@ object Manga {
it[MangaTable.status] = fetchedManga.status
if (fetchedManga.thumbnail_url != null && fetchedManga.thumbnail_url.orEmpty().isNotEmpty())
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,
mangaEntry[MangaTable.inLibrary],
getSource(mangaEntry[MangaTable.sourceReference]),
getMangaMetaMap(mangaEntry[MangaTable.id]),
getMangaMetaMap(mangaId),
mangaEntry[MangaTable.realUrl],
true
)
}
}
fun getMangaMetaMap(manga: EntityID<Int>): Map<String, String> {
fun getMangaMetaMap(manga: Int): Map<String, String> {
return transaction {
MangaMetaTable.select { MangaMetaTable.ref eq manga }
.associate { it[MangaMetaTable.key] to it[MangaMetaTable.value] }
@@ -126,7 +128,8 @@ object Manga {
transaction {
val manga = MangaMetaTable.select { (MangaTable.id eq mangaId) }
.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) {
MangaMetaTable.insert {
it[MangaMetaTable.key] = key
@@ -57,6 +57,8 @@ object MangaList {
it[sourceReference] = sourceId
}.value
val mangaEntry = MangaTable.select { MangaTable.url eq manga.url }.first()
MangaDataClass(
mangaId,
sourceId.toString(),
@@ -71,7 +73,11 @@ object MangaList {
manga.author,
manga.description,
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 {
val mangaId = mangaEntry[MangaTable.id].value
@@ -91,7 +97,9 @@ object MangaList {
mangaEntry[MangaTable.genre],
MangaStatus.valueOf(mangaEntry[MangaTable.status]).name,
mangaEntry[MangaTable.inLibrary],
meta = getMangaMetaMap(mangaEntry[MangaTable.id])
meta = getMangaMetaMap(mangaId),
realUrl = mangaEntry[MangaTable.realUrl],
freshData = false
)
}
}
@@ -97,7 +97,7 @@ object Extension {
if (libVersion < LIB_VERSION_MIN || libVersion > LIB_VERSION_MAX) {
throw Exception(
"Lib version is $libVersion, while only versions " +
"$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed"
"$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed"
)
}
@@ -26,9 +26,13 @@ data class MangaDataClass(
val status: String = MangaStatus.UNKNOWN.name,
val inLibrary: Boolean = false,
val source: SourceDataClass? = null,
/** meta data for clients */
val meta: Map<String, String> = emptyMap(),
val freshData: Boolean = false
val realUrl: String? = null,
val freshData: Boolean = false,
)
data class PagedMangaListDataClass(
@@ -31,8 +31,11 @@ object MangaTable : IntIdTable() {
val inLibrary = bool("in_library").default(false)
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")
/** 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) =
@@ -52,7 +55,8 @@ fun MangaTable.toDataClass(mangaEntry: ResultRow) =
mangaEntry[genre],
Companion.valueOf(mangaEntry[status]).name,
mangaEntry[inLibrary],
meta = getMangaMetaMap(mangaEntry[id])
meta = getMangaMetaMap(mangaEntry[id].value),
realUrl = mangaEntry[realUrl],
)
enum class MangaStatus(val value: Int) {
@@ -10,9 +10,9 @@ package suwayomi.tachidesk.server.database.migration
import de.neonew.exposed.migrations.helpers.AddColumnMigration
@Suppress("ClassName", "unused")
class M0011_SourceIsNsfw : AddColumnMigration(
"Source",
"is_nsfw",
"BOOLEAN",
"FALSE"
class M0013_MangaRealUrl : AddColumnMigration(
"Manga",
"real_url",
"VARCHAR(2048)",
"NULL"
)