diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/EhUtils.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/EhUtils.kt index 157714907..eb928a049 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/EhUtils.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhUtils.kt @@ -84,12 +84,16 @@ object EhUtils { ) private val CATEGORY_STRINGS = CATEGORY_VALUES.entries.map { (k, v) -> v to k } + private val ImageHashRegex = Regex("[0-9a-f]{40}") + val isExHentai: Boolean get() = Settings.gallerySite.value == EhUrl.SITE_EX val isMpvAvailable get() = EhCookieStore.getHathPerks()?.contains('q') == true + fun getImageHash(thumbUrl: String) = ImageHashRegex.find(thumbUrl)?.groupValues[0] + fun getCategory(type: String?): Int { for (entry in CATEGORY_STRINGS) { for (str in entry.first) { diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt index 2cda55430..ba9cf3a0a 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt @@ -524,17 +524,17 @@ fun BelowHeader(galleryDetail: GalleryDetail) { } }, ) + val invalidUrl = stringResource(R.string.error_invalid_url) EhIconButton( icon = Icons.Default.ImageSearch, text = stringResource(id = R.string.search_cover), onClick = { - val key = galleryDetail.thumbKey!! - navigate( - ListUrlBuilder( - mode = ListUrlBuilder.MODE_IMAGE_SEARCH, - hash = key.substringAfterLast('/').substringBefore('-'), - ).asDst(), - ) + val hash = EhUtils.getImageHash(galleryDetail.thumbKey!!) + if (hash != null) { + navigate(ListUrlBuilder(mode = ListUrlBuilder.MODE_IMAGE_SEARCH, hash = hash).asDst()) + } else { + launch { showSnackbar(invalidUrl) } + } }, ) val torrentText = stringResource(R.string.torrent_count, galleryDetail.torrentCount)