Merge pull request #1586 from Xwite/master

书源校验:优化同时校验搜索发现的逻辑
pull/1592/head
kunfei 3 years ago committed by GitHub
commit ca01a0e8b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app/src/main/java/io/legado/app/service/CheckSourceService.kt

@ -123,14 +123,15 @@ class CheckSourceService : BaseService() {
} }
//校验搜索 用户设置校验搜索 并且 搜索链接不为空 //校验搜索 用户设置校验搜索 并且 搜索链接不为空
if (CheckSource.checkSearch && !source.searchUrl.isNullOrBlank()) { if (CheckSource.checkSearch && !source.searchUrl.isNullOrBlank()) {
books = WebBook.searchBookAwait(this, source, searchWord) val searchBooks = WebBook.searchBookAwait(this, source, searchWord)
if (books.isEmpty()) { if (searchBooks.isEmpty()) {
source.addGroup("搜索失效") source.addGroup("搜索失效")
if (!CheckSource.checkDiscovery) { if (!CheckSource.checkDiscovery) {
throw NoStackTraceException("搜索书籍为空") throw NoStackTraceException("搜索书籍为空")
} }
} else { } else {
source.removeGroup("搜索失效") source.removeGroup("搜索失效")
books = searchBooks
} }
} }
//校验发现 //校验发现
@ -149,12 +150,16 @@ class CheckSourceService : BaseService() {
source.hasGroup("搜索失效") -> throw NoStackTraceException("搜索内容为空并且没有发现") source.hasGroup("搜索失效") -> throw NoStackTraceException("搜索内容为空并且没有发现")
} }
} else { } else {
books = WebBook.exploreBookAwait(this, source, url) val exploreBooks = WebBook.exploreBookAwait(this, source, url)
if (books.isEmpty()) { if (exploreBooks.isEmpty()) {
source.addGroup("发现失效")
when { when {
!CheckSource.checkSearch -> throw NoStackTraceException("发现书籍为空") !CheckSource.checkSearch -> throw NoStackTraceException("发现书籍为空")
source.hasGroup("搜索失效") -> throw NoStackTraceException("搜索内容和发现书籍为空") source.hasGroup("搜索失效") -> throw NoStackTraceException("搜索内容和发现书籍为空")
} }
} else {
source.removeGroup("发现失效")
books = exploreBooks
} }
} }
} }
@ -199,7 +204,7 @@ class CheckSourceService : BaseService() {
?.filterNot { ?.filterNot {
it.startsWith("Error: ") it.startsWith("Error: ")
}?.joinToString("\n") }?.joinToString("\n")
if (source.hasGroup("搜索失效")) { if (source.hasGroup("搜索失效") || source.hasGroup("发现失效")) {
Debug.updateFinalMessage(source.bookSourceUrl, "失败") Debug.updateFinalMessage(source.bookSourceUrl, "失败")
} else { } else {
Debug.updateFinalMessage(source.bookSourceUrl, "成功") Debug.updateFinalMessage(source.bookSourceUrl, "成功")

Loading…
Cancel
Save