MangaHere: Fix http 500 (#4830)

idk
This commit is contained in:
bapeey 2024-08-30 06:13:12 -05:00 committed by GitHub
parent d46401ff0e
commit 8b86e9190c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 25 deletions

View File

@ -1,7 +1,11 @@
ext {
extName = 'Mangahere'
extClass = '.Mangahere'
extVersionCode = 19
extVersionCode = 20
}
apply from: "$rootDir/common.gradle"
dependencies {
implementation(project(":lib:cookieinterceptor"))
}

View File

@ -1,7 +1,9 @@
package eu.kanade.tachiyomi.extension.en.mangahere
import app.cash.quickjs.QuickJs
import eu.kanade.tachiyomi.lib.cookieinterceptor.CookieInterceptor
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
@ -9,10 +11,7 @@ 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.CookieJar
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
@ -35,27 +34,30 @@ class Mangahere : ParsedHttpSource() {
override val supportsLatest = true
override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("Referer", baseUrl)
override fun headersBuilder(): Headers.Builder = super.headersBuilder()
.set("Referer", "$baseUrl/")
.set("Cache-Control", "no-cache")
override val client: OkHttpClient = super.client.newBuilder()
.cookieJar(
object : CookieJar {
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {}
override fun loadForRequest(url: HttpUrl): MutableList<Cookie> {
return ArrayList<Cookie>().apply {
add(
Cookie.Builder()
.domain("www.mangahere.cc")
.path("/")
.name("isAdult")
.value("1")
.build(),
)
}
}
},
)
private val cookieInterceptor = CookieInterceptor(
baseUrl.substringAfter("://"),
listOf(
"isAdult" to "1",
),
)
private val notRateLimitClient: OkHttpClient = network.cloudflareClient.newBuilder()
.addNetworkInterceptor(cookieInterceptor)
.addNetworkInterceptor { chain ->
val newRequest = chain.request().newBuilder()
.header("Cache-Control", "no-cache")
.removeHeader("If-Modified-Since")
.build()
chain.proceed(newRequest)
}
.build()
override val client: OkHttpClient = notRateLimitClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 1, 2)
.build()
override fun popularMangaSelector() = ".manga-list-1-list li"
@ -277,7 +279,7 @@ class Mangahere : ParsedHttpSource() {
.addHeader("X-Requested-With", "XMLHttpRequest")
.build()
val response = client.newCall(request).execute()
val response = notRateLimitClient.newCall(request).execute()
responseText = response.body.string()
if (responseText.isNotEmpty()) {