Merge pull request #1575 from Xwite/master

书源校验:只校验搜索时 搜索结果为空应该抛出异常
pull/1576/head^2
kunfei 3 years ago committed by GitHub
commit 40379bd42f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      app/src/main/java/io/legado/app/service/CheckSourceService.kt

@ -124,11 +124,17 @@ class CheckSourceService : BaseService() {
//校验搜索 用户设置校验搜索 并且 搜索链接不为空 //校验搜索 用户设置校验搜索 并且 搜索链接不为空
if (CheckSource.checkSearch && !source.searchUrl.isNullOrBlank()) { if (CheckSource.checkSearch && !source.searchUrl.isNullOrBlank()) {
books = WebBook.searchBookAwait(this, source, searchWord) books = WebBook.searchBookAwait(this, source, searchWord)
if (books.isEmpty()) source.addGroup("搜索失效") else source.removeGroup("搜索失效") if (books.isEmpty()) {
source.addGroup("搜索失效")
if (!CheckSource.checkDiscovery) {
throw NoStackTraceException("搜索书籍为空")
}
} else {
source.removeGroup("搜索失效")
}
} }
//校验发现 //校验发现
if (CheckSource.checkDiscovery) { if (CheckSource.checkDiscovery) {
if (books.isEmpty()) {
val exs = source.exploreKinds val exs = source.exploreKinds
var url: String? = null var url: String? = null
for (ex in exs) { for (ex in exs) {
@ -137,7 +143,7 @@ class CheckSourceService : BaseService() {
break break
} }
} }
if (url.isNullOrBlank()) { if (source.hasGroup("搜索失效") && url.isNullOrBlank()) {
throw NoStackTraceException("搜索内容为空并且没有发现") throw NoStackTraceException("搜索内容为空并且没有发现")
} }
books = WebBook.exploreBookAwait(this, source, url) books = WebBook.exploreBookAwait(this, source, url)
@ -145,7 +151,6 @@ class CheckSourceService : BaseService() {
throw NoStackTraceException("发现书籍为空") throw NoStackTraceException("发现书籍为空")
} }
} }
}
//校验详情 //校验详情
if (CheckSource.checkInfo) { if (CheckSource.checkInfo) {
var book = books.first().toBook() var book = books.first().toBook()

Loading…
Cancel
Save