|
|
|
@ -3,18 +3,16 @@ package org.koitharu.kotatsu.browser.cloudflare
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
import android.webkit.WebView
|
|
|
|
import android.webkit.WebView
|
|
|
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
|
|
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
|
|
|
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
|
|
|
import org.koitharu.kotatsu.core.network.CookieJar
|
|
|
|
import org.koitharu.kotatsu.core.network.WebViewClientCompat
|
|
|
|
import org.koitharu.kotatsu.core.network.WebViewClientCompat
|
|
|
|
|
|
|
|
|
|
|
|
class CloudFlareClient(
|
|
|
|
class CloudFlareClient(
|
|
|
|
private val cookieJar: AndroidCookieJar,
|
|
|
|
private val cookieJar: CookieJar,
|
|
|
|
private val callback: CloudFlareCallback,
|
|
|
|
private val callback: CloudFlareCallback,
|
|
|
|
private val targetUrl: String
|
|
|
|
private val targetUrl: String
|
|
|
|
) : WebViewClientCompat() {
|
|
|
|
) : WebViewClientCompat() {
|
|
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
private val oldClearance = getCookieValue(CF_CLEARANCE)
|
|
|
|
cookieJar.remove(targetUrl, CF_UID, CF_CLEARANCE)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
|
|
|
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
|
|
|
super.onPageStarted(view, url, favicon)
|
|
|
|
super.onPageStarted(view, url, favicon)
|
|
|
|
@ -32,16 +30,19 @@ class CloudFlareClient(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun checkClearance() {
|
|
|
|
private fun checkClearance() {
|
|
|
|
val cookies = cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
|
|
|
val clearance = getCookieValue(CF_CLEARANCE)
|
|
|
|
if (cookies.any { it.name == CF_CLEARANCE }) {
|
|
|
|
if (clearance != null && clearance != oldClearance) {
|
|
|
|
callback.onCheckPassed()
|
|
|
|
callback.onCheckPassed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getCookieValue(name: String): String? {
|
|
|
|
|
|
|
|
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
|
|
|
|
|
|
|
.find { it.name == name }?.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private companion object {
|
|
|
|
private companion object {
|
|
|
|
|
|
|
|
|
|
|
|
const val CF_UID = "__cfduid"
|
|
|
|
|
|
|
|
const val CF_CLEARANCE = "cf_clearance"
|
|
|
|
const val CF_CLEARANCE = "cf_clearance"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|