diff --git a/src/es/manhwasnet/build.gradle b/src/es/manhwasnet/build.gradle index b013dc4e5..d1d04b7a8 100644 --- a/src/es/manhwasnet/build.gradle +++ b/src/es/manhwasnet/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Manhwas.net' extClass = '.ManhwasNet' - extVersionCode = 11 + extVersionCode = 12 isNsfw = true } diff --git a/src/es/manhwasnet/src/eu/kanade/tachiyomi/extension/es/manhwasnet/ManhwasNet.kt b/src/es/manhwasnet/src/eu/kanade/tachiyomi/extension/es/manhwasnet/ManhwasNet.kt index 2e8e74f25..529a48bbb 100644 --- a/src/es/manhwasnet/src/eu/kanade/tachiyomi/extension/es/manhwasnet/ManhwasNet.kt +++ b/src/es/manhwasnet/src/eu/kanade/tachiyomi/extension/es/manhwasnet/ManhwasNet.kt @@ -1,22 +1,17 @@ package eu.kanade.tachiyomi.extension.es.manhwasnet -import app.cash.quickjs.QuickJs import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.interceptor.rateLimitHost import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource -import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.Cookie import okhttp3.HttpUrl.Companion.toHttpUrl -import okhttp3.Interceptor import okhttp3.Request -import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import java.io.IOException import java.util.Calendar import java.util.concurrent.TimeUnit @@ -27,45 +22,10 @@ class ManhwasNet : ParsedHttpSource() { override val name: String = "Manhwas.net" override val supportsLatest: Boolean = true - override val client = network.client.newBuilder() - .connectTimeout(60, TimeUnit.SECONDS) - .writeTimeout(60, TimeUnit.SECONDS) - .readTimeout(60, TimeUnit.SECONDS) - .addInterceptor { sucuriInterceptor(it) } + override val client = network.cloudflareClient.newBuilder() + .rateLimitHost(baseUrl.toHttpUrl(), 3, 1, TimeUnit.SECONDS) .build() - private fun sucuriInterceptor(chain: Interceptor.Chain): Response { - val request = chain.request() - val url = request.url - val response = try { - chain.proceed(request) - } catch (e: Exception) { - // Try to clear cookies and retry - client.cookieJar.saveFromResponse(url, emptyList()) - val clearHeaders = request.headers.newBuilder().removeAll("Cookie").build() - chain.proceed(request.newBuilder().headers(clearHeaders).build()) - } - if (response.headers["x-sucuri-cache"].isNullOrEmpty() && response.headers["x-sucuri-id"] != null && url.toString().startsWith(baseUrl)) { - val script = response.use { it.asJsoup() }.selectFirst("script")?.data() - if (script != null) { - val patchedScript = script.split("(r)")[0].dropLast(1) + "r=r.replace('document.cookie','cookie');" - QuickJs.create().use { - val result = (it.evaluate(patchedScript) as String) - .replace("location.", "") - .replace("reload();", "") - val sucuriCookie = (it.evaluate(result) as String).split("=", limit = 2) - val cookieName = sucuriCookie.first() - val cookieValue = sucuriCookie.last().replace(";path", "") - client.cookieJar.saveFromResponse(url, listOf(Cookie.parse(url, "$cookieName=$cookieValue")!!)) - } - val newResponse = chain.proceed(request) - if (!newResponse.headers["x-sucuri-cache"].isNullOrEmpty()) return newResponse - } - throw IOException("Sitio protegido - Abra en WebView para intentar desbloquear.") - } - return response - } - override fun headersBuilder() = super.headersBuilder() .set("Referer", "$baseUrl/")