From 5087fdbf615c60afe07dabdb99aac74e4b7a943b Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 13 Jun 2020 19:40:34 -0400 Subject: [PATCH] NHentai: add rate limiting --- src/all/nhentai/build.gradle | 6 +++++- .../eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/all/nhentai/build.gradle b/src/all/nhentai/build.gradle index de685ccc0..f80ecc4fe 100644 --- a/src/all/nhentai/build.gradle +++ b/src/all/nhentai/build.gradle @@ -5,8 +5,12 @@ ext { appName = 'Tachiyomi: NHentai' pkgNameSuffix = 'all.nhentai' extClass = '.NHFactory' - extVersionCode = 22 + extVersionCode = 23 libVersion = '1.2' } +dependencies { + implementation project(':lib-ratelimit') +} + apply from: "$rootDir/common.gradle" diff --git a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt index 8a6ec01b4..0a96c2587 100644 --- a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt +++ b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getNumPages import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTagDescription import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTags import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTime +import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.ConfigurableSource @@ -42,7 +43,10 @@ open class NHentai( override val supportsLatest = true - override val client: OkHttpClient = network.cloudflareClient + private val rateLimitInterceptor = RateLimitInterceptor(4) + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .addNetworkInterceptor(rateLimitInterceptor) + .build() private val preferences: SharedPreferences by lazy { Injekt.get().getSharedPreferences("source_$id", 0x0000)