diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/EhCacheKeyFactory.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/EhCacheKeyFactory.kt index 8e8919c3f..21c5010f2 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/EhCacheKeyFactory.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhCacheKeyFactory.kt @@ -25,6 +25,7 @@ import com.hippo.ehviewer.client.data.NormalGalleryPreview const val URL_PREFIX_THUMB_E = "https://ehgt.org/" const val URL_PREFIX_THUMB_EX = "https://s.exhentai.org/t/" +const val URL_SIGNATURE_THUMB_NORMAL = ".hath.network" private const val NORMAL_PREVIEW_PREFIX = "$" private val NormalPreviewKeyRegex = Regex("/(\\d+-\\d+)\\.jpg$") diff --git a/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt b/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt index 337bf8814..50508525f 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt @@ -6,18 +6,23 @@ import coil3.network.NetworkResponse import coil3.network.ktor3.asNetworkClient import com.hippo.ehviewer.Settings import com.hippo.ehviewer.client.URL_PREFIX_THUMB_EX +import com.hippo.ehviewer.client.URL_SIGNATURE_THUMB_NORMAL import io.ktor.client.HttpClient import kotlinx.coroutines.NonCancellable -import kotlinx.coroutines.sync.Semaphore -import kotlinx.coroutines.sync.withPermit import kotlinx.coroutines.withContext +import moe.tarsin.coroutines.NamedSemaphore +import moe.tarsin.coroutines.withPermit class LimitConcurrencyNetworkClient(val impl: NetworkClient) : NetworkClient { - val semaphore = Semaphore(Settings.thumbConcurrency) + val semaphores = NamedSemaphore(permits = Settings.thumbConcurrency) override suspend fun executeRequest(req: NetworkRequest, f: suspend (NetworkResponse) -> T): T { val url = req.url return when { - URL_PREFIX_THUMB_EX in url -> semaphore.withPermit { withContext(NonCancellable) { impl.executeRequest(req, f) } } + // Ex thumb server has no h2 multiplexing support + URL_PREFIX_THUMB_EX in url -> semaphores.withPermit(URL_PREFIX_THUMB_EX) { withContext(NonCancellable) { impl.executeRequest(req, f) } } + // H@H server has no h2 multiplexing support + URL_SIGNATURE_THUMB_NORMAL in url -> semaphores.withPermit(url.substringBefore(URL_SIGNATURE_THUMB_NORMAL)) { withContext(NonCancellable) { impl.executeRequest(req, f) } } + // H2 multiplexing enabled else -> impl.executeRequest(req, f) } }