Merge pull request #1855 from Xwite/master

fix:校验bug
pull/1857/head
kunfei 3 years ago committed by GitHub
commit 9958376a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/src/main/java/io/legado/app/help/SourceVerificationHelp.kt
  2. 22
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  3. 5
      app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt

@ -12,6 +12,7 @@ import splitties.init.appCtx
object SourceVerificationHelp { object SourceVerificationHelp {
private var key: String = ""
/** /**
* 获取书源验证结果 * 获取书源验证结果
* 图片验证码 防爬 滑动验证码 点击字符 等等 * 图片验证码 防爬 滑动验证码 点击字符 等等
@ -19,7 +20,7 @@ object SourceVerificationHelp {
fun getVerificationResult(source: BaseSource?, url: String, title: String, useBrowser: Boolean): String { fun getVerificationResult(source: BaseSource?, url: String, title: String, useBrowser: Boolean): String {
source ?: throw NoStackTraceException("getVerificationResult parameter source cannot be null") source ?: throw NoStackTraceException("getVerificationResult parameter source cannot be null")
return runBlocking { return runBlocking {
val key = "${source.getKey()}_verificationResult" key = "${source.getKey()}_verificationResult"
CacheManager.delete(key) CacheManager.delete(key)
if (!useBrowser) { if (!useBrowser) {
@ -52,6 +53,7 @@ object SourceVerificationHelp {
*/ */
fun startBrowser(source: BaseSource?, url: String, title: String, saveResult: Boolean? = false) { fun startBrowser(source: BaseSource?, url: String, title: String, saveResult: Boolean? = false) {
source ?: throw NoStackTraceException("startBrowser parameter source cannot be null") source ?: throw NoStackTraceException("startBrowser parameter source cannot be null")
key = "${source.getKey()}_verificationResult"
appCtx.startActivity<WebViewActivity> { appCtx.startActivity<WebViewActivity> {
putExtra("title", title) putExtra("title", title)
putExtra("url", url) putExtra("url", url)
@ -61,7 +63,7 @@ object SourceVerificationHelp {
} }
} }
private fun checkActivityStatus(): Boolean { fun checkResult() {
return true CacheManager.get(key) ?: CacheManager.putMemory(key, "")
} }
} }

@ -135,18 +135,20 @@ class CheckSourceService : BaseService() {
?.filterNot { ?.filterNot {
it.startsWith("Error: ") it.startsWith("Error: ")
}?.joinToString("\n") }?.joinToString("\n")
//校验搜索书籍 用户设置校验搜索 并且 搜索链接不为空 //校验搜索书籍
if (CheckSource.checkSearch && !source.searchUrl.isNullOrBlank()) { if (CheckSource.checkSearch) {
if (!source.searchUrl.isNullOrBlank()) {
source.removeGroup("搜索链接规则为空")
val searchBooks = WebBook.searchBookAwait(this, source, searchWord) val searchBooks = WebBook.searchBookAwait(this, source, searchWord)
if (searchBooks.isEmpty()) { if (searchBooks.isEmpty()) {
source.addGroup("搜索失效") source.addGroup("搜索失效")
if (!CheckSource.checkDiscovery) {
throw NoStackTraceException("搜索书籍为空")
}
} else { } else {
source.removeGroup("搜索失效") source.removeGroup("搜索失效")
checkBook(searchBooks.first().toBook(), source) checkBook(searchBooks.first().toBook(), source)
} }
} else {
source.addGroup("搜索链接规则为空")
}
} }
//校验发现书籍 //校验发现书籍
if (CheckSource.checkDiscovery) { if (CheckSource.checkDiscovery) {
@ -159,18 +161,12 @@ class CheckSourceService : BaseService() {
} }
} }
if (url.isNullOrBlank()) { if (url.isNullOrBlank()) {
when { source.addGroup("发现规则为空")
!CheckSource.checkSearch -> throw NoStackTraceException("没有发现")
source.hasGroup("搜索失效") -> throw NoStackTraceException("搜索内容为空并且没有发现")
}
} else { } else {
source.removeGroup("发现规则为空")
val exploreBooks = WebBook.exploreBookAwait(this, source, url) val exploreBooks = WebBook.exploreBookAwait(this, source, url)
if (exploreBooks.isEmpty()) { if (exploreBooks.isEmpty()) {
source.addGroup("发现失效") source.addGroup("发现失效")
when {
!CheckSource.checkSearch -> throw NoStackTraceException("发现书籍为空")
source.hasGroup("搜索失效") -> throw NoStackTraceException("搜索内容和发现书籍为空")
}
} else { } else {
source.removeGroup("发现失效") source.removeGroup("发现失效")
checkBook(exploreBooks.first().toBook(), source, false) checkBook(exploreBooks.first().toBook(), source, false)

@ -12,6 +12,7 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogVerificationCodeViewBinding import io.legado.app.databinding.DialogVerificationCodeViewBinding
import io.legado.app.help.CacheManager import io.legado.app.help.CacheManager
import io.legado.app.help.SourceVerificationHelp
import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.ImageLoader
import io.legado.app.help.glide.OkHttpModelLoader import io.legado.app.help.glide.OkHttpModelLoader
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
@ -91,9 +92,7 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
} }
override fun onDestroy() { override fun onDestroy() {
val sourceOrigin = arguments?.getString("sourceOrigin") SourceVerificationHelp.checkResult()
val key = "${sourceOrigin}_verificationResult"
CacheManager.get(key) ?: CacheManager.putMemory(key, "")
super.onDestroy() super.onDestroy()
activity?.finish() activity?.finish()
} }

@ -17,6 +17,7 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.databinding.ActivityWebViewBinding import io.legado.app.databinding.ActivityWebViewBinding
import io.legado.app.help.SourceVerificationHelp
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.http.CookieStore import io.legado.app.help.http.CookieStore
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
@ -182,6 +183,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
} }
override fun onDestroy() { override fun onDestroy() {
SourceVerificationHelp.checkResult()
super.onDestroy() super.onDestroy()
binding.webView.destroy() binding.webView.destroy()
} }

Loading…
Cancel
Save