diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt index 9dc9d8e05..690ed858a 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt @@ -34,6 +34,7 @@ class WebViewActivity : VMBaseActivity() { private val imagePathKey = "imagePath" private var customWebViewCallback: WebChromeClient.CustomViewCallback? = null private var webPic: String? = null + private var isCloudflareChallenge = false private val saveImage = registerForActivityResult(HandleFileContract()) { it.uri?.let { uri -> ACache.get().put(imagePathKey, uri.toString()) @@ -68,7 +69,7 @@ class WebViewActivity : VMBaseActivity() { R.id.menu_copy_url -> sendToClip(viewModel.baseUrl) R.id.menu_ok -> { if (viewModel.sourceVerificationEnable) { - viewModel.saveVerificationResult { + viewModel.saveVerificationResult(intent) { finish() } } else { @@ -226,6 +227,16 @@ class WebViewActivity : VMBaseActivity() { } else { binding.titleBar.title = intent.getStringExtra("title") } + if (title == "Just a moment...") { + isCloudflareChallenge = true + } + if (isCloudflareChallenge && title != "Just a moment...") { + if (viewModel.sourceVerificationEnable) { + viewModel.saveVerificationResult(intent) { + finish() + } + } + } } } diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt index 0ad527a09..94f0b1707 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt @@ -8,6 +8,7 @@ import android.webkit.URLUtil import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppConst +import io.legado.app.data.appDb import io.legado.app.exception.NoStackTraceException import io.legado.app.help.CacheManager import io.legado.app.help.IntentData @@ -83,11 +84,17 @@ class WebViewModel(application: Application) : BaseViewModel(application) { } } - fun saveVerificationResult(success: () -> Unit) { + fun saveVerificationResult(intent: Intent, success: () -> Unit) { execute { if (sourceVerificationEnable) { + val url = intent.getStringExtra("url")!! + val source = appDb.bookSourceDao.getBookSource(sourceOrigin) val key = "${sourceOrigin}_verificationResult" - html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponseAwait(useWebView = false).body + html = AnalyzeUrl( + url, + headerMapF = headerMap, + source = source + ).getStrResponseAwait(useWebView = false).body CacheManager.putMemory(key, html ?: "") } }.onSuccess {