pull/2446/head
kunfei 2 years ago
parent 52d0ba8b60
commit db68c165b3
  1. 24
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -189,21 +189,31 @@ object WebBook {
}
}
suspend fun getChapterListAwait(
bookSource: BookSource,
book: Book,
runPerJs: Boolean = false
): Result<List<BookChapter>> {
book.type = bookSource.getBookType()
fun runPreUpdateJs(bookSource: BookSource, book: Book): Result<Boolean> {
return kotlin.runCatching {
val preUpdateJs = bookSource.ruleToc?.preUpdateJs
if (runPerJs && !preUpdateJs.isNullOrBlank()) {
if (!preUpdateJs.isNullOrBlank()) {
kotlin.runCatching {
AnalyzeRule(book, bookSource).evalJS(preUpdateJs)
}.onFailure {
AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it)
throw it
}
return@runCatching true
}
return@runCatching false
}
}
suspend fun getChapterListAwait(
bookSource: BookSource,
book: Book,
runPerJs: Boolean = false
): Result<List<BookChapter>> {
book.type = bookSource.getBookType()
return kotlin.runCatching {
if (runPerJs) {
runPreUpdateJs(bookSource, book).getOrThrow()
}
if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) {
BookChapterList.analyzeChapterList(

@ -122,10 +122,11 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
upTocAdd(bookUrl)
execute(context = upTocPool) {
val oldBook = book.copy()
WebBook.runPreUpdateJs(source, book)
if (book.tocUrl.isBlank()) {
WebBook.getBookInfoAwait(source, book)
}
val toc = WebBook.getChapterListAwait(source, book, true).getOrThrow()
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
book.removeType(BookType.updateError)
if (book.bookUrl == bookUrl) {
appDb.bookDao.update(book)

Loading…
Cancel
Save