Horis 4 лет назад
Родитель
Сommit
cb65ca3f1b

+ 12 - 1
app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt

@@ -34,6 +34,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
     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<ActivityWebViewBinding, WebViewModel>() {
             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<ActivityWebViewBinding, WebViewModel>() {
                 } 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()
+                        }
+                    }
+                }
             }
         }
 

+ 9 - 2
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 {