EH keep CF cookies

(cherry picked from commit 68dc8b51765537bdb7bd4edcca5c95e0f3cf025a)
This commit is contained in:
az4521 2026-01-16 03:54:36 +00:00 committed by Cuong-Tran
parent a86ec40c79
commit 5e3915eae8
2 changed files with 29 additions and 21 deletions

View file

@ -67,7 +67,6 @@ import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.put
import okhttp3.CacheControl
import okhttp3.CookieJar
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
@ -906,7 +905,7 @@ class EHentai(
page = parsed.first.lastOrNull()?.manga?.url?.let { EHentaiSearchMetadata.galleryId(it) }?.toInt() ?: 0
} while (parsed.second != null)
return Pair(result.toList(), favNames.orEmpty())
return Pair(result.toList(), favNames)
}
fun spPref() = if (exh) {
@ -948,7 +947,7 @@ class EHentai(
return cookies
}
fun cookiesHeader(sp: Int = spPref().get()) = buildCookies(rawCookies(sp))
fun cookiesHeader(cfCookies: Map<String, String> = emptyMap(), sp: Int = spPref().get()) = buildCookies(rawCookies(sp) + cfCookies)
// Headers
override fun headersBuilder() = super.headersBuilder().add("Cookie", cookiesHeader())
@ -958,20 +957,28 @@ class EHentai(
.appendQueryParameter(param, value)
.toString()
override val client = network.client.newBuilder()
.cookieJar(CookieJar.NO_COOKIES)
.addInterceptor { chain ->
val newReq = chain
.request()
.newBuilder()
.removeHeader("Cookie")
.addHeader("Cookie", cookiesHeader())
.build()
override val client =
network.client.newBuilder()
// .cookieJar(CookieJar.NO_COOKIES)
.addInterceptor { chain ->
val cfCookies = chain.request().header("Cookie")?.split("; ")
?.filter {
val name = it.split("=")[0].trim().lowercase()
name in arrayOf("cf_clearance", "__cf_bm", "cf_chl_prog", "_cfuvid", "__cfruid", "__cflb", "cf_ob_info", "cf_use_ob", "__cfwaitingroom", "__cfseq", "cf_chl_rc_i", "cf_chl_rc_ni", "cf_chl_rc_m") || name.startsWith("cf_chl_seq_")
}?.associate { it.split("=")[0].trim() to it.split("=")[1].trim() }
chain.proceed(newReq)
}
.addInterceptor(ThumbnailPreviewInterceptor())
.build()
val newReq =
chain
.request()
.newBuilder()
.removeHeader("Cookie")
.addHeader("Cookie", cookiesHeader(cfCookies ?: emptyMap()))
.build()
chain.proceed(newReq)
}
.addInterceptor(ThumbnailPreviewInterceptor())
.build()
// Filters
override fun getFilterList(): FilterList {
@ -1392,9 +1399,9 @@ class EHentai(
private const val BLANK_THUMB = "blank.gif"
private const val BLANK_PREVIEW_THUMB = "https://$THUMB_DOMAIN/g/$BLANK_THUMB"
private val MATCH_YEAR_REGEX = "^\\d{4}\$".toRegex()
private val MATCH_SEEK_REGEX = "^\\d{2,4}-\\d{1,2}(-\\d{1,2})?\$".toRegex()
private val MATCH_JUMP_REGEX = "^\\d+(\$|d\$|w\$|m\$|y\$|-\$)".toRegex()
private val MATCH_YEAR_REGEX = "^\\d{4}$".toRegex()
private val MATCH_SEEK_REGEX = "^\\d{2,4}-\\d{1,2}(-\\d{1,2})?$".toRegex()
private val MATCH_JUMP_REGEX = "^\\d+($|d$|w$|m$|y$|-$)".toRegex()
private const val EH_API_BASE = "https://api.e-hentai.org/api.php"
private val JSON = "application/json; charset=utf-8".toMediaTypeOrNull()!!

View file

@ -26,8 +26,9 @@ class EHConfigurator(val context: Context) {
.maybeInjectEHLogger()
.build()
private fun EHentai.requestWithCreds(sp: Int = 1) = Request.Builder()
.addHeader("Cookie", cookiesHeader(sp))
private fun EHentai.requestWithCreds(sp: Int = 1) =
Request.Builder()
.addHeader("Cookie", cookiesHeader(sp = sp))
private suspend fun EHentai.execProfileActions(
action: String,