Drop HAtHBlacklist

immature implementation
This commit is contained in:
Dude so hot authored and renovate[bot] committed 2025-01-03 12:10:42 +08:00
1 parent 517d6f6d0b
commit e8701b65c6
9 files changed
-75

No files matched your search

@@ -56,7 +56,6 @@ import com.hippo.ehviewer.ktbuilder.imageLoader
import com.hippo.ehviewer.ktor.Cronet
import com.hippo.ehviewer.ktor.configureClient
import com.hippo.ehviewer.ktor.configureCommon
import com.hippo.ehviewer.spider.trimHAtHBlacklist
import com.hippo.ehviewer.ui.keepNoMediaFileStatus
import com.hippo.ehviewer.ui.lockObserver
import com.hippo.ehviewer.ui.screen.detailCache
@@ -78,10 +77,8 @@ import eu.kanade.tachiyomi.util.lang.withUIContext
import eu.kanade.tachiyomi.util.system.logcat
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import kotlin.time.Duration.Companion.days
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import logcat.AndroidLogcatLogger
import logcat.LogPriority
import logcat.LogcatLogger
@@ -115,7 +112,6 @@ class EhApplication :
super.onCreate()
System.loadLibrary("ehviewer")
lifecycleScope.launchIO {
launch { trimHAtHBlacklist(Clock.System.now() - 7.days) }
launchUI { FavouriteStatusRouter.collect { (gid, slot) -> detailCache[gid]?.favoriteSlot = slot } }
EhTagDatabase.launchUpdate()
launch { EhDB }
@@ -148,7 +148,6 @@ object Settings : DataStorePreferences(null) {
var launchPage by intPref("launch_page_2", 0)
var commentThreshold by intPref("comment_threshold", -101)
var hardwareBitmapThreshold by intPref("hardware_bitmap_threshold", 16384)
var hAtHBlacklist by boolPref("H@H_blacklist", false).observed { updateWhenHAtHBlacklistChanges() }
var showComments by boolPref("show_gallery_comments", true)
var requestNews by boolPref("request_news", false).observed { updateWhenRequestNewsChanges() }
var hideHvEvents by boolPref("hide_hv_events", false)
@@ -5,7 +5,6 @@ import androidx.appcompat.app.AppCompatDelegate
import com.hippo.ehviewer.client.EhEngine
import com.hippo.ehviewer.client.EhTagDatabase
import com.hippo.ehviewer.dailycheck.updateDailyCheckWork
import com.hippo.ehviewer.spider.trimHAtHBlacklist
import com.hippo.ehviewer.ui.keepNoMediaFileStatus
import com.hippo.ehviewer.util.isAtLeastS
import eu.kanade.tachiyomi.util.lang.launchIO
@@ -68,9 +67,3 @@ fun updateWhenGallerySiteChanges() {
fun updateWhenTagTranslationChanges() {
EhTagDatabase.launchUpdate()
}
fun updateWhenHAtHBlacklistChanges() {
collectScope.launchIO {
trimHAtHBlacklist()
}
}
@@ -1,37 +0,0 @@
package com.hippo.ehviewer.spider
import com.hippo.files.read
import com.hippo.files.write
import io.ktor.utils.io.core.writeFully
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.io.readByteArray
import kotlinx.serialization.Serializable
import kotlinx.serialization.cbor.Cbor
import kotlinx.serialization.decodeFromByteArray
import kotlinx.serialization.encodeToByteArray
import okio.Path.Companion.toOkioPath
import splitties.init.appCtx
@Serializable
class HAtHBlacklist(val blacklist: MutableMap<String, Instant> = mutableMapOf())
private val cache = appCtx.cacheDir.toOkioPath() / "H@H_blacklist"
val blacklist by lazy {
runCatching {
cache.read { Cbor.decodeFromByteArray<HAtHBlacklist>(readByteArray()) }
}.getOrElse {
cache.write { HAtHBlacklist().also { writeFully(Cbor.encodeToByteArray(it)) } }
}
}
fun appendHAtHBlacklist(host: String) = synchronized(blacklist) {
blacklist.blacklist[host] = Clock.System.now()
cache.write { writeFully(Cbor.encodeToByteArray(blacklist)) }
}
fun trimHAtHBlacklist(time: Instant = Clock.System.now()) = synchronized(blacklist) {
blacklist.blacklist.values.removeIf { i -> i < time }
cache.write { writeFully(Cbor.encodeToByteArray(blacklist)) }
}
@@ -38,10 +38,8 @@ import com.hippo.ehviewer.client.parser.GalleryDetailParser.parsePreviewPages
import com.hippo.ehviewer.client.parser.GalleryMultiPageViewerPTokenParser
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser
import com.hippo.ehviewer.util.displayString
import com.hippo.ehviewer.util.isHAtHTimeoutException
import com.hippo.files.find
import eu.kanade.tachiyomi.util.system.logcat
import io.ktor.http.Url
import java.util.concurrent.atomic.AtomicInteger
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.TimeSource
@@ -638,20 +636,6 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
}
checkNotNull(targetImageUrl)
val host = Url(targetImageUrl).host
synchronized(blacklist) {
if (lasthost == host) {
blacklist.blacklist.remove(host)
logcat(WORKER_DEBUG_TAG) { "Drop $host from H@H blacklist as its resource is unique for now!" }
}
if (Settings.hAtHBlacklist && blacklist.blacklist.containsKey(host)) {
logcat(WORKER_DEBUG_TAG) { "$host hits H@H blacklist!" }
lasthost = host
return@repeat
}
}
runCatching {
logcat(WORKER_DEBUG_TAG) { "Start download image $index" }
spiderDen.makeHttpCallAndSaveImage(
@@ -666,9 +650,6 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
}.onFailure {
spiderDen.removeIntermediateFiles(index)
logcat(WORKER_DEBUG_TAG) { "Download image $index failed" }
if (Settings.hAtHBlacklist && it.isHAtHTimeoutException()) {
appendHAtHBlacklist(host)
}
when (it) {
is CancellationException, is FileNotFoundException -> throw it
}
@@ -310,7 +310,6 @@ object EnStrings : Strings {
override val settingsDownloadDownloadDelaySummary = { a: Int -> "Delay $a ms per download" }
override val settingsDownloadConnectionTimeout = "Connection timeout (in seconds)"
override val settingsDownloadTimeoutSpeed = "Minimum response speed (in KB/s)"
override val settingsDownloadHAtHBlacklist = "Enable H@H blacklist"
override val settingsDownloadPreloadImage = "Preload image"
override val settingsDownloadPreloadImageSummary = { a: Int -> "Preload next $a image" }
override val settingsDownloadDownloadOriginImage = "Download original image"
@@ -315,7 +315,6 @@ interface Strings {
val settingsDownloadDownloadDelaySummary: (Int) -> String
val settingsDownloadConnectionTimeout: String
val settingsDownloadTimeoutSpeed: String
val settingsDownloadHAtHBlacklist: String
val settingsDownloadPreloadImage: String
val settingsDownloadPreloadImageSummary: (Int) -> String
val settingsDownloadDownloadOriginImage: String
@@ -408,7 +408,6 @@ object ZhCnStrings : Strings by EnStrings {
override val settingsDownloadDownloadDelaySummary = { a: Int -> "每次下载延时 $a 毫秒" }
override val settingsDownloadConnectionTimeout = "连接超时(秒)"
override val settingsDownloadTimeoutSpeed = "最低响应速度(KB/s)"
override val settingsDownloadHAtHBlacklist = "启用H@H黑名单"
override val noBrowserInstalled = "请安装一个浏览器。"
override val toplistAlltime = "从始至终"
override val toplistPastyear = "过去一年"
@@ -195,10 +195,6 @@ fun AnimatedVisibilityScope.DownloadScreen(navigator: DestinationsNavigator) = c
value = Settings::timeoutSpeed,
display = ::speedLevelToSpeed,
)
SwitchPreference(
title = settingsDownloadHAtHBlacklist,
value = Settings::hAtHBlacklist,
)
val preloadImage = Settings::preloadImage.observed
SimpleMenuPreferenceInt(
title = settingsDownloadPreloadImage,