Do db migration, Resolve #1074
This commit is contained in:
1 parent
91164e4dd6
commit
95478a615e
18 files changed
+70
-44
No files matched your search
@@ -18,8 +18,8 @@ package com.hippo.ehviewer.client
|
||||
import com.hippo.ehviewer.client.data.GalleryPreview
|
||||
import com.hippo.ehviewer.client.data.NormalGalleryPreview
|
||||
|
||||
// ExHentai Large Preview: https://exhentai.org/t/***
|
||||
// ExHentai Normal Preview: https://exhentai.org/m/***
|
||||
// ExHentai Large Preview: https://s.exhentai.org/t/***
|
||||
// ExHentai Normal Preview: https://s.exhentai.org/m/***
|
||||
// EHentai Normal Preview: https://ehgt.org/m/***
|
||||
// EHentai Large Preview: https://ehgt.org/***
|
||||
|
||||
@@ -30,12 +30,12 @@ fun getImageKey(gid: Long, index: Int): String {
|
||||
return "image:$gid:$index"
|
||||
}
|
||||
|
||||
fun getPreviewThumbKey(url: String): String {
|
||||
return url.removePrefix(URL_PREFIX_THUMB_E)
|
||||
.removePrefix(URL_PREFIX_THUMB_EX)
|
||||
.removePrefix("t/")
|
||||
fun getThumbKey(url: String): String {
|
||||
return url.removePrefix(URL_PREFIX_THUMB_E).removePrefix(URL_PREFIX_THUMB_EX).removePrefix("t/")
|
||||
}
|
||||
|
||||
fun getUrlByThumbKey(key: String): String = if (EhUtils.isExHentai) URL_PREFIX_THUMB_EX + "t/" + key else URL_PREFIX_THUMB_E + key
|
||||
|
||||
val GalleryPreview.url
|
||||
get() = if (this is NormalGalleryPreview) {
|
||||
if (EhUtils.isExHentai) URL_PREFIX_THUMB_EX + imageKey else URL_PREFIX_THUMB_E + imageKey
|
||||
|
||||
@@ -5,7 +5,7 @@ interface AbstractGalleryInfo {
|
||||
var token: String?
|
||||
var title: String?
|
||||
var titleJpn: String?
|
||||
var thumb: String?
|
||||
var thumbKey: String?
|
||||
var category: Int
|
||||
var posted: String?
|
||||
var uploader: String?
|
||||
|
||||
@@ -36,7 +36,7 @@ open class BaseGalleryInfo(
|
||||
override var titleJpn: String? = null,
|
||||
|
||||
@ColumnInfo(name = "THUMB")
|
||||
override var thumb: String? = null,
|
||||
override var thumbKey: String? = null,
|
||||
|
||||
@ColumnInfo(name = "CATEGORY")
|
||||
override var category: Int = 0,
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.client.parser
|
||||
import com.hippo.ehviewer.client.EhUtils.getCategory
|
||||
import com.hippo.ehviewer.client.EhUtils.handleThumbUrlResolution
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.client.getThumbKey
|
||||
import com.hippo.ehviewer.yorozuya.NumberUtils
|
||||
import org.json.JSONObject
|
||||
|
||||
@@ -32,7 +33,7 @@ object GalleryApiParser {
|
||||
gi.title = ParserUtils.trim(g.getString("title"))
|
||||
gi.titleJpn = ParserUtils.trim(g.getString("title_jpn"))
|
||||
gi.category = getCategory(g.getString("category"))
|
||||
gi.thumb = handleThumbUrlResolution(g.getString("thumb"))
|
||||
gi.thumbKey = getThumbKey(handleThumbUrlResolution(g.getString("thumb"))!!)
|
||||
gi.uploader = g.getString("uploader")
|
||||
gi.posted =
|
||||
ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted"), 0) * 1000)
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.hippo.ehviewer.client.exception.EhException
|
||||
import com.hippo.ehviewer.client.exception.OffensiveException
|
||||
import com.hippo.ehviewer.client.exception.ParseException
|
||||
import com.hippo.ehviewer.client.exception.PiningException
|
||||
import com.hippo.ehviewer.client.getPreviewThumbKey
|
||||
import com.hippo.ehviewer.client.getThumbKey
|
||||
import com.hippo.ehviewer.util.ExceptionUtils
|
||||
import com.hippo.ehviewer.util.JsoupUtils
|
||||
import com.hippo.ehviewer.yorozuya.NumberUtils
|
||||
@@ -130,9 +130,11 @@ object GalleryDetailParser {
|
||||
val gm = d.getElementsByClass("gm")[0]
|
||||
// Thumb url
|
||||
gm.getElementById("gd1")?.child(0)?.attr("style")?.trim()?.let {
|
||||
gd.thumb = PATTERN_COVER.find(it)?.run {
|
||||
handleThumbUrlResolution(groupValues[3])
|
||||
}
|
||||
gd.thumbKey = getThumbKey(
|
||||
PATTERN_COVER.find(it)?.run {
|
||||
handleThumbUrlResolution(groupValues[3])
|
||||
}!!,
|
||||
)
|
||||
}
|
||||
|
||||
gd.title = gm.getElementById("gn")?.text()?.trim()
|
||||
@@ -481,7 +483,7 @@ object GalleryDetailParser {
|
||||
check(PATTERN_LARGE_PREVIEW.containsMatchIn(body))
|
||||
return PATTERN_LARGE_PREVIEW.findAll(body).unzip {
|
||||
val position = it.groupValues[2].toInt() - 1
|
||||
val imageKey = getPreviewThumbKey(it.groupValues[3].trim())
|
||||
val imageKey = getThumbKey(it.groupValues[3].trim())
|
||||
val pageUrl = it.groupValues[1].trim()
|
||||
LargeGalleryPreview(imageKey, position) to pageUrl
|
||||
}.run {
|
||||
@@ -493,7 +495,7 @@ object GalleryDetailParser {
|
||||
check(PATTERN_NORMAL_PREVIEW.containsMatchIn(body))
|
||||
return PATTERN_NORMAL_PREVIEW.findAll(body).unzip {
|
||||
val position = it.groupValues[6].toInt() - 1
|
||||
val imageKey = getPreviewThumbKey(it.groupValues[3].trim())
|
||||
val imageKey = getThumbKey(it.groupValues[3].trim())
|
||||
val xOffset = it.groupValues[4].toIntOrNull() ?: 0
|
||||
val width = it.groupValues[1].toInt()
|
||||
val height = it.groupValues[2].toInt()
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.BaseGalleryInfo
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.client.exception.ParseException
|
||||
import com.hippo.ehviewer.client.getThumbKey
|
||||
import com.hippo.ehviewer.util.ExceptionUtils
|
||||
import com.hippo.ehviewer.util.JsoupUtils
|
||||
import com.hippo.ehviewer.yorozuya.NumberUtils
|
||||
@@ -160,7 +161,7 @@ object GalleryListParser {
|
||||
url = img.attr("src")
|
||||
}
|
||||
if (url.isNotEmpty()) {
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(url)
|
||||
gi.thumbKey = EhUtils.handleThumbUrlResolution(url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +175,7 @@ object GalleryListParser {
|
||||
}
|
||||
}
|
||||
// Try extended and thumbnail version
|
||||
if (gi.thumb == null) {
|
||||
if (gi.thumbKey == null) {
|
||||
var gl = JsoupUtils.getElementByClass(e, "gl1e")
|
||||
if (gl == null) {
|
||||
gl = JsoupUtils.getElementByClass(e, "gl3t")
|
||||
@@ -192,11 +193,13 @@ object GalleryListParser {
|
||||
gi.thumbWidth = 0
|
||||
gi.thumbHeight = 0
|
||||
}
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(img.attr("src"))
|
||||
gi.thumbKey = EhUtils.handleThumbUrlResolution(img.attr("src"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gi.thumbKey = getThumbKey(gi.thumbKey!!)
|
||||
|
||||
// Posted
|
||||
val posted = e.getElementById("posted_" + gi.gid)
|
||||
if (posted != null) {
|
||||
|
||||
@@ -10,17 +10,14 @@ import coil.request.CachePolicy
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Size
|
||||
import com.hippo.ehviewer.client.data.GalleryPreview
|
||||
import com.hippo.ehviewer.client.getPreviewThumbKey
|
||||
import com.hippo.ehviewer.client.getUrlByThumbKey
|
||||
import com.hippo.ehviewer.client.url
|
||||
|
||||
fun ImageRequest.Builder.ehUrl(url: String?) = apply {
|
||||
url?.let {
|
||||
val key = getPreviewThumbKey(url)
|
||||
data(url)
|
||||
memoryCacheKey(key)
|
||||
diskCacheKey(key)
|
||||
size(Size.ORIGINAL)
|
||||
}
|
||||
fun ImageRequest.Builder.ehUrl(key: String) = apply {
|
||||
data(getUrlByThumbKey(key))
|
||||
memoryCacheKey(key)
|
||||
diskCacheKey(key)
|
||||
size(Size.ORIGINAL)
|
||||
}
|
||||
|
||||
fun ImageRequest.Builder.ehPreviewKey(key: GalleryPreview) = apply {
|
||||
@@ -39,5 +36,5 @@ fun ImageRequest.Builder.justDownload() = apply {
|
||||
}
|
||||
|
||||
inline fun Context.imageRequest(key: GalleryPreview, builder: ImageRequest.Builder.() -> Unit = {}) = ImageRequest.Builder(this).ehPreviewKey(key).apply(builder).build()
|
||||
inline fun Context.imageRequest(key: String?, builder: ImageRequest.Builder.() -> Unit = {}) = ImageRequest.Builder(this).ehUrl(key).apply(builder).build()
|
||||
inline fun Context.imageRequest(key: String, builder: ImageRequest.Builder.() -> Unit = {}) = ImageRequest.Builder(this).ehUrl(key).apply(builder).build()
|
||||
inline fun diskCache(builder: DiskCache.Builder.() -> Unit) = DiskCache.Builder().apply(builder).build()
|
||||
@@ -49,7 +49,7 @@ class DownloadInfo() : BaseGalleryInfo() {
|
||||
token = galleryInfo.token
|
||||
title = galleryInfo.title
|
||||
titleJpn = galleryInfo.titleJpn
|
||||
thumb = galleryInfo.thumb
|
||||
thumbKey = galleryInfo.thumbKey
|
||||
this.category = galleryInfo.category
|
||||
posted = galleryInfo.posted
|
||||
uploader = galleryInfo.uploader
|
||||
|
||||
@@ -5,10 +5,32 @@ import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
private val EHDB_MIGRATION_4_5 = object : Migration(4, 5) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
val needMigrationTables = arrayOf(
|
||||
"DOWNLOADS",
|
||||
"HISTORY",
|
||||
"LOCAL_FAVORITES",
|
||||
)
|
||||
val prefixToRemove = arrayOf(
|
||||
"https://ehgt.org/",
|
||||
"https://s.exhentai.org/t/",
|
||||
"https://exhentai.org/t/",
|
||||
)
|
||||
needMigrationTables.forEach { table ->
|
||||
prefixToRemove.forEach { prefix ->
|
||||
db.execSQL("UPDATE $table SET thumb = SUBSTR(thumb ,LENGTH('$prefix') + 1) WHERE thumb LIKE '$prefix%'")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Database(
|
||||
entities = [BookmarkInfo::class, DownloadInfo::class, DownloadLabel::class, DownloadDirname::class, Filter::class, HistoryInfo::class, LocalFavoriteInfo::class, QuickSearch::class],
|
||||
version = 4,
|
||||
version = 5,
|
||||
exportSchema = false,
|
||||
)
|
||||
abstract class EhDatabase : RoomDatabase() {
|
||||
@@ -40,6 +62,7 @@ abstract class CookiesDatabase : RoomDatabase() {
|
||||
fun buildMainDB(context: Context): EhDatabase {
|
||||
// TODO: Remove allowMainThreadQueries
|
||||
return Room.databaseBuilder(context, EhDatabase::class.java, "eh.db").allowMainThreadQueries()
|
||||
.addMigrations(EHDB_MIGRATION_4_5)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class HistoryInfo() : BaseGalleryInfo() {
|
||||
token = galleryInfo.token
|
||||
title = galleryInfo.title
|
||||
titleJpn = galleryInfo.titleJpn
|
||||
thumb = galleryInfo.thumb
|
||||
thumbKey = galleryInfo.thumbKey
|
||||
this.category = galleryInfo.category
|
||||
posted = galleryInfo.posted
|
||||
uploader = galleryInfo.uploader
|
||||
|
||||
@@ -16,7 +16,7 @@ class LocalFavoriteInfo() : BaseGalleryInfo() {
|
||||
token = galleryInfo.token
|
||||
title = galleryInfo.title
|
||||
titleJpn = galleryInfo.titleJpn
|
||||
thumb = galleryInfo.thumb
|
||||
thumbKey = galleryInfo.thumbKey
|
||||
this.category = galleryInfo.category
|
||||
posted = galleryInfo.posted
|
||||
uploader = galleryInfo.uploader
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail
|
||||
import com.hippo.ehviewer.client.getUrlByThumbKey
|
||||
import com.hippo.ehviewer.ui.login.LocalNavController
|
||||
import com.hippo.ehviewer.util.tellClipboardWithToast
|
||||
|
||||
@@ -82,7 +83,7 @@ fun GalleryInfoBottomSheet(
|
||||
EhUrl.getGalleryDetailUrl(gid, token),
|
||||
title,
|
||||
titleJpn,
|
||||
thumb,
|
||||
getUrlByThumbKey(thumbKey!!),
|
||||
EhUtils.getCategory(category),
|
||||
uploader,
|
||||
posted,
|
||||
|
||||
@@ -16,13 +16,13 @@ import com.hippo.ehviewer.coil.imageRequest
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun requestOf(model: String?): ImageRequest {
|
||||
fun requestOf(model: String): ImageRequest {
|
||||
return LocalContext.current.imageRequest(model)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EhAsyncThumb(
|
||||
model: String?,
|
||||
model: String,
|
||||
modifier: Modifier = Modifier,
|
||||
contentScale: ContentScale = ContentScale.Fit,
|
||||
) = AsyncImage(
|
||||
@@ -34,12 +34,12 @@ fun EhAsyncThumb(
|
||||
|
||||
@Composable
|
||||
fun EhAsyncCropThumb(
|
||||
model: String?,
|
||||
key: String,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var contentScale by remember { mutableStateOf(ContentScale.Fit) }
|
||||
AsyncImage(
|
||||
model = requestOf(model),
|
||||
model = requestOf(key),
|
||||
contentDescription = null,
|
||||
modifier = modifier,
|
||||
onState = {
|
||||
|
||||
@@ -103,7 +103,7 @@ fun GalleryDetailHeaderCard(
|
||||
Row {
|
||||
Card {
|
||||
EhAsyncCropThumb(
|
||||
model = remember(info.thumb) { info.thumb },
|
||||
key = remember(info.thumbKey!!) { info.thumbKey!! },
|
||||
modifier = Modifier.height(dimensionResource(id = R.dimen.gallery_detail_thumb_height)).width(dimensionResource(id = R.dimen.gallery_detail_thumb_width)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ fun GalleryInfoListItem(
|
||||
Row {
|
||||
Card {
|
||||
EhAsyncCropThumb(
|
||||
model = info.thumb,
|
||||
key = info.thumbKey!!,
|
||||
modifier = Modifier.aspectRatio(0.6666667F).fillMaxSize(),
|
||||
)
|
||||
}
|
||||
@@ -141,7 +141,7 @@ fun GalleryInfoGridItem(
|
||||
) {
|
||||
Box {
|
||||
EhAsyncThumb(
|
||||
model = info.thumb,
|
||||
model = info.thumbKey!!,
|
||||
modifier = Modifier.aspectRatio(aspect).fillMaxWidth(),
|
||||
contentScale = ContentScale.Crop,
|
||||
)
|
||||
|
||||
@@ -867,7 +867,7 @@ class DownloadsScene :
|
||||
onClick = ::onClick.partially1(binding.thumb),
|
||||
) {
|
||||
EhAsyncCropThumb(
|
||||
model = info.thumb,
|
||||
key = info.thumbKey!!,
|
||||
modifier = Modifier
|
||||
.height(height)
|
||||
.aspectRatio(0.6666667F),
|
||||
|
||||
@@ -133,7 +133,6 @@ import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.client.data.GalleryTagGroup
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder
|
||||
import com.hippo.ehviewer.client.exception.NoHAtHClientException
|
||||
import com.hippo.ehviewer.client.getPreviewThumbKey
|
||||
import com.hippo.ehviewer.client.parser.ArchiveParser
|
||||
import com.hippo.ehviewer.client.parser.HomeParser
|
||||
import com.hippo.ehviewer.client.parser.ParserUtils
|
||||
@@ -1217,7 +1216,7 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
return
|
||||
}
|
||||
try {
|
||||
val key = getPreviewThumbKey(composeBindingGI!!.thumb!!)
|
||||
val key = composeBindingGI!!.thumbKey!!
|
||||
val path = imageLoader(context).diskCache!![key]!!.use { it.data }
|
||||
val lub = ListUrlBuilder()
|
||||
lub.mode = ListUrlBuilder.MODE_IMAGE_SEARCH
|
||||
|
||||
@@ -1053,7 +1053,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
private fun onGetGalleryListSuccess(result: GalleryListParser.Result, taskId: Int) {
|
||||
if (Settings.preloadThumbAggressively) {
|
||||
lifecycleScope.launchIO {
|
||||
result.galleryInfoList.forEach { context?.run { imageLoader.enqueue(imageRequest(it.thumb) { justDownload() }) } }
|
||||
result.galleryInfoList.forEach { context?.run { imageLoader.enqueue(imageRequest(it.thumbKey!!) { justDownload() }) } }
|
||||
}
|
||||
}
|
||||
if (mHelper != null && mHelper!!.isCurrentTask(taskId)) {
|
||||
|
||||
Reference in new issue
Block a user