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( fun runPreUpdateJs(bookSource: BookSource, book: Book): Result<Boolean> {
bookSource: BookSource,
book: Book,
runPerJs: Boolean = false
): Result<List<BookChapter>> {
book.type = bookSource.getBookType()
return kotlin.runCatching { return kotlin.runCatching {
val preUpdateJs = bookSource.ruleToc?.preUpdateJs val preUpdateJs = bookSource.ruleToc?.preUpdateJs
if (runPerJs && !preUpdateJs.isNullOrBlank()) { if (!preUpdateJs.isNullOrBlank()) {
kotlin.runCatching { kotlin.runCatching {
AnalyzeRule(book, bookSource).evalJS(preUpdateJs) AnalyzeRule(book, bookSource).evalJS(preUpdateJs)
}.onFailure { }.onFailure {
AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it) AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it)
throw 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()) { if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) {
BookChapterList.analyzeChapterList( BookChapterList.analyzeChapterList(

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

Loading…
Cancel
Save