mirror of
https://github.com/mihonapp/mihon.git
synced 2025-07-01 21:47:50 +02:00
Add universal captcha solver
This commit is contained in:
@ -14,7 +14,8 @@ import java.nio.charset.Charset
|
||||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
class AutoSolvingWebViewClient(activity: SolveCaptchaActivity,
|
||||
source: CaptchaCompletionVerifier,
|
||||
injectScript: String?)
|
||||
injectScript: String?,
|
||||
private val headers: Map<String, String>)
|
||||
: BasicWebViewClient(activity, source, injectScript) {
|
||||
|
||||
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
||||
@ -31,6 +32,24 @@ class AutoSolvingWebViewClient(activity: SolveCaptchaActivity,
|
||||
doc.toString().byteInputStream(Charset.forName("UTF-8")).buffered()
|
||||
)
|
||||
}
|
||||
if(headers.isNotEmpty()) {
|
||||
val response = activity.httpClient.newCall(request.toOkHttpRequest()
|
||||
.newBuilder()
|
||||
.apply {
|
||||
headers.forEach { (n, v) -> addHeader(n, v) }
|
||||
}
|
||||
.build())
|
||||
.execute()
|
||||
|
||||
return WebResourceResponse(
|
||||
response.body()?.contentType()?.let { "${it.type()}/${it.subtype()}" },
|
||||
response.body()?.contentType()?.charset()?.toString(),
|
||||
response.code(),
|
||||
response.message(),
|
||||
response.headers().toMultimap().mapValues { it.value.joinToString(",") },
|
||||
response.body()?.byteStream()
|
||||
)
|
||||
}
|
||||
return super.shouldInterceptRequest(view, request)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user