ManhwasNet: Remove sucuri interceptor (#5521)

remove sucuri
This commit is contained in:
bapeey 2024-10-14 06:47:44 -05:00 committed by GitHub
parent 92db0ff731
commit 17ae7c93c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 44 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Manhwas.net'
extClass = '.ManhwasNet'
extVersionCode = 11
extVersionCode = 12
isNsfw = true
}

View File

@ -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/")