Drop obsolete code as HTTP/2 is fully supported (#2185)
This commit is contained in:
1 parent
9c52e789b3
commit
b724286886
11 files changed
+6
-117
No files matched your search
@@ -29,8 +29,7 @@ import coil3.asImage
|
||||
import coil3.gif.AnimatedImageDecoder
|
||||
import coil3.gif.GifDecoder
|
||||
import coil3.network.ConnectivityChecker
|
||||
import coil3.network.NetworkFetcher
|
||||
import coil3.network.ktor3.asNetworkClient
|
||||
import coil3.network.ktor3.KtorNetworkFetcherFactory
|
||||
import coil3.request.ErrorResult
|
||||
import coil3.request.ImageRequest
|
||||
import coil3.request.allowRgb565
|
||||
@@ -45,8 +44,6 @@ import com.hippo.ehviewer.coil.HardwareBitmapInterceptor
|
||||
import com.hippo.ehviewer.coil.MapExtraInfoInterceptor
|
||||
import com.hippo.ehviewer.coil.MergeInterceptor
|
||||
import com.hippo.ehviewer.coil.QrCodeInterceptor
|
||||
import com.hippo.ehviewer.coil.exchangeSite
|
||||
import com.hippo.ehviewer.coil.limitConcurrency
|
||||
import com.hippo.ehviewer.dailycheck.checkDawn
|
||||
import com.hippo.ehviewer.dao.SearchDatabase
|
||||
import com.hippo.ehviewer.download.DownloadManager
|
||||
@@ -168,8 +165,8 @@ class EhApplication :
|
||||
components {
|
||||
serviceLoaderEnabled(false)
|
||||
add(
|
||||
NetworkFetcher.Factory(
|
||||
networkClient = { ktorClient.asNetworkClient().limitConcurrency().exchangeSite() },
|
||||
KtorNetworkFetcherFactory(
|
||||
httpClient = { ktorClient },
|
||||
connectivityChecker = { ConnectivityChecker.ONLINE },
|
||||
),
|
||||
)
|
||||
|
||||
@@ -114,9 +114,6 @@ object Settings : DataStorePreferences(null) {
|
||||
val languageFilter = intPref("language_filter", -1)
|
||||
val downloadSortMode = intPref("download_sort_mode", SortMode.Default.flag)
|
||||
val downloadFilterMode = intPref("download_filter_mode", DownloadsFilterMode.Default.flag)
|
||||
|
||||
// Enabled by default as some ExHentai thumbnail servers do not support HTTP/2
|
||||
val forceEhThumb = boolPref("force_eh_thumb", true)
|
||||
val hasSignedIn = boolPref("has_signed_in", EhCookieStore.hasSignedIn())
|
||||
val needSignIn = boolPref("need_sign_in", true)
|
||||
val meteredNetworkWarning = boolPref("cellular_network_warning", false)
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.hippo.ehviewer.client
|
||||
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
|
||||
// Normal Preview (v2): https://*.hath.network/c(m|1|2)/[timed token]/[gid]-[index].(jpg|webp)
|
||||
@@ -26,7 +25,6 @@ import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
|
||||
const val URL_PREFIX_THUMB_E = "https://ehgt.org/"
|
||||
const val URL_PREFIX_THUMB_EX = "https://s.exhentai.org/"
|
||||
const val URL_SIGNATURE_THUMB_NORMAL = ".hath.network/c"
|
||||
private const val URL_PREFIX_V1_THUMB_EX = URL_PREFIX_THUMB_EX + "t/"
|
||||
private val V2PreviewKeyRegex = Regex("/c([m12]/)[^/]+/(\\d+-\\d+)")
|
||||
|
||||
@@ -40,23 +38,15 @@ fun getV2PreviewKey(url: String) = "$".plus(
|
||||
} ?: url,
|
||||
)
|
||||
|
||||
val String.isV2PreviewKey
|
||||
get() = startsWith('$')
|
||||
|
||||
val GalleryInfo.thumbUrl
|
||||
get() = keyToUrl(thumbKey!!)
|
||||
|
||||
fun keyToUrl(key: String, exSite: Boolean = useExThumb) = if (key.startsWith("https:")) {
|
||||
fun keyToUrl(key: String) = if (key.startsWith("https:")) {
|
||||
key
|
||||
} else {
|
||||
if (key.endsWith("webp")) {
|
||||
if (exSite) URL_PREFIX_THUMB_EX else URL_PREFIX_THUMB_E
|
||||
if (EhUtils.isExHentai) URL_PREFIX_THUMB_EX else URL_PREFIX_THUMB_E
|
||||
} else {
|
||||
if (exSite) URL_PREFIX_V1_THUMB_EX else URL_PREFIX_THUMB_E
|
||||
if (EhUtils.isExHentai) URL_PREFIX_V1_THUMB_EX else URL_PREFIX_THUMB_E
|
||||
} + key
|
||||
}
|
||||
|
||||
fun flipThumbSite(url: String) = keyToUrl(getThumbKey(url), !useExThumb)
|
||||
|
||||
private val useExThumb
|
||||
get() = EhUtils.isExHentai && !Settings.forceEhThumb.value
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.hippo.ehviewer.coil
|
||||
|
||||
import coil3.network.HttpException
|
||||
import coil3.network.NetworkClient
|
||||
import coil3.network.NetworkRequest
|
||||
import coil3.network.NetworkResponse
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.flipThumbSite
|
||||
|
||||
class ExchangeSiteNetworkClient(val impl: NetworkClient) : NetworkClient {
|
||||
override suspend fun <T> executeRequest(req: NetworkRequest, f: suspend (NetworkResponse) -> T): T {
|
||||
if (EhUtils.isExHentai) {
|
||||
try {
|
||||
return impl.executeRequest(req, f)
|
||||
} catch (e: HttpException) {
|
||||
if (e.response.code == 500) {
|
||||
return impl.executeRequest(req.copy(url = flipThumbSite(req.url)), f)
|
||||
}
|
||||
throw e
|
||||
}
|
||||
} else {
|
||||
return impl.executeRequest(req, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun NetworkClient.exchangeSite() = ExchangeSiteNetworkClient(this)
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.hippo.ehviewer.coil
|
||||
|
||||
import coil3.network.NetworkClient
|
||||
import coil3.network.NetworkRequest
|
||||
import coil3.network.NetworkResponse
|
||||
import com.hippo.ehviewer.client.URL_PREFIX_THUMB_EX
|
||||
import com.hippo.ehviewer.client.URL_SIGNATURE_THUMB_NORMAL
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.withContext
|
||||
import moe.tarsin.coroutines.NamedSemaphore
|
||||
import moe.tarsin.coroutines.withLock
|
||||
|
||||
class LimitConcurrencyNetworkClient(val impl: NetworkClient) : NetworkClient {
|
||||
val semaphores = NamedSemaphore<String>(permits = 8)
|
||||
override suspend fun <T> executeRequest(req: NetworkRequest, f: suspend (NetworkResponse) -> T): T {
|
||||
val url = req.url
|
||||
return when {
|
||||
// Ex thumb server may not have h2 multiplexing support
|
||||
URL_PREFIX_THUMB_EX in url -> semaphores.withLock(URL_PREFIX_THUMB_EX) { withContext(NonCancellable) { impl.executeRequest(req, f) } }
|
||||
// H@H server may not have h2 multiplexing support
|
||||
URL_SIGNATURE_THUMB_NORMAL in url -> semaphores.withLock(url.substringBefore(URL_SIGNATURE_THUMB_NORMAL)) { withContext(NonCancellable) { impl.executeRequest(req, f) } }
|
||||
// H2 multiplexing enabled
|
||||
else -> impl.executeRequest(req, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun NetworkClient.limitConcurrency() = LimitConcurrencyNetworkClient(this)
|
||||
@@ -38,7 +38,6 @@ import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.asMutableState
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhTagDatabase
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.collectAsState
|
||||
import com.hippo.ehviewer.ui.Screen
|
||||
@@ -132,15 +131,6 @@ fun AnimatedVisibilityScope.EhScreen(navigator: DestinationsNavigator) = Screen(
|
||||
entryValueRes = R.array.gallery_site_entry_values,
|
||||
value = gallerySite,
|
||||
)
|
||||
AnimatedVisibility(gallerySite.value == EhUrl.SITE_EX) {
|
||||
var forceEhThumb by Settings.forceEhThumb.asMutableState()
|
||||
SwitchPref(
|
||||
checked = forceEhThumb,
|
||||
onMutate = { forceEhThumb = !forceEhThumb },
|
||||
title = stringResource(id = R.string.settings_eh_force_eh_thumb),
|
||||
summary = stringResource(id = R.string.settings_eh_force_eh_thumb_summary),
|
||||
)
|
||||
}
|
||||
Preference(
|
||||
title = stringResource(id = R.string.settings_u_config),
|
||||
summary = stringResource(id = R.string.settings_u_config_summary),
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package moe.tarsin.coroutines
|
||||
|
||||
import io.ktor.utils.io.pool.DefaultPool
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
|
||||
class SemaphoreWithCounter(semaphore: Semaphore) : Semaphore by semaphore, Counter by counter()
|
||||
|
||||
class SemaphorePool(val permits: Int) : DefaultPool<SemaphoreWithCounter>(capacity = 32) {
|
||||
override fun produceInstance() = SemaphoreWithCounter(semaphore = Semaphore(permits = permits))
|
||||
override fun validateInstance(semaphore: SemaphoreWithCounter) {
|
||||
check(semaphore.availablePermits == permits)
|
||||
check(semaphore.isFree)
|
||||
}
|
||||
}
|
||||
|
||||
class NamedSemaphore<K>(val permits: Int) : LockTracker<SemaphoreWithCounter, K>() {
|
||||
val pool = SemaphorePool(permits = permits)
|
||||
override suspend fun SemaphoreWithCounter.lock() = acquire()
|
||||
override fun SemaphoreWithCounter.unlock() = release()
|
||||
override fun new() = pool.borrow()
|
||||
override fun free(e: SemaphoreWithCounter) = pool.recycle(e)
|
||||
}
|
||||
@@ -298,8 +298,6 @@
|
||||
<string name="settings_eh_detail_size_long">長い</string>
|
||||
<string name="settings_eh_detail_size_short">短い</string>
|
||||
<string name="settings_eh_thumb_columns">サムネイルのカラム数</string>
|
||||
<string name="settings_eh_force_eh_thumb">E-Hentai サムネイルサーバーを使用する</string>
|
||||
<string name="settings_eh_force_eh_thumb_summary">サムネイルの読み込みに問題がある場合は無効化してください</string>
|
||||
<string name="settings_eh_show_jpn_title">日本語のタイトルを表示</string>
|
||||
<string name="settings_eh_show_jpn_title_summary">E-Hentai ウェブサイトの設定で日本語のタイトルを有効化する必要があります</string>
|
||||
<string name="settings_eh_show_gallery_pages">ギャラリーページ数を表示</string>
|
||||
|
||||
@@ -295,8 +295,6 @@
|
||||
<string name="settings_eh_detail_size_long">长</string>
|
||||
<string name="settings_eh_detail_size_short">短</string>
|
||||
<string name="settings_eh_thumb_columns">缩略图列数</string>
|
||||
<string name="settings_eh_force_eh_thumb">使用 e-hentai 缩略图服务器</string>
|
||||
<string name="settings_eh_force_eh_thumb_summary">若缩略图加载失败可尝试关闭此项</string>
|
||||
<string name="settings_eh_show_jpn_title">显示日文标题</string>
|
||||
<string name="settings_eh_show_jpn_title_summary">需同时在 EHentai 网站设置中启用 Japanese Title</string>
|
||||
<string name="settings_eh_show_gallery_pages">显示画廊页数</string>
|
||||
|
||||
@@ -294,8 +294,6 @@
|
||||
<string name="settings_eh_detail_size_long">長</string>
|
||||
<string name="settings_eh_detail_size_short">短</string>
|
||||
<string name="settings_eh_thumb_columns">縮圖列數</string>
|
||||
<string name="settings_eh_force_eh_thumb">使用 e-hentai 縮圖伺服器</string>
|
||||
<string name="settings_eh_force_eh_thumb_summary">若縮圖載入遇到問題可嘗試停用此項</string>
|
||||
<string name="settings_eh_show_jpn_title">顯示日文標題</string>
|
||||
<string name="settings_eh_show_jpn_title_summary">需同時在 EHentai 網站設定中啟用 Japanese Title</string>
|
||||
<string name="settings_eh_show_gallery_pages">顯示圖庫頁數</string>
|
||||
|
||||
@@ -311,8 +311,6 @@
|
||||
<string name="settings_eh_detail_size_long">Long</string>
|
||||
<string name="settings_eh_detail_size_short">Short</string>
|
||||
<string name="settings_eh_thumb_columns">Thumb columns</string>
|
||||
<string name="settings_eh_force_eh_thumb">Use e-hentai thumbnail server</string>
|
||||
<string name="settings_eh_force_eh_thumb_summary">Try disabling this if you have trouble loading thumbnails</string>
|
||||
<string name="settings_eh_show_jpn_title">Show Japanese title</string>
|
||||
<string name="settings_eh_show_jpn_title_summary">Require enabling Japanese Title in Settings on EHentai website</string>
|
||||
<string name="settings_eh_show_gallery_pages">Show gallery pages</string>
|
||||
|
||||
Reference in new issue
Block a user