优化
This commit is contained in:
@@ -189,6 +189,22 @@ object WebBook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun runPreUpdateJs(bookSource: BookSource, book: Book): Result<Boolean> {
|
||||||
|
return kotlin.runCatching {
|
||||||
|
val preUpdateJs = bookSource.ruleToc?.preUpdateJs
|
||||||
|
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(
|
suspend fun getChapterListAwait(
|
||||||
bookSource: BookSource,
|
bookSource: BookSource,
|
||||||
book: Book,
|
book: Book,
|
||||||
@@ -196,14 +212,8 @@ object WebBook {
|
|||||||
): Result<List<BookChapter>> {
|
): Result<List<BookChapter>> {
|
||||||
book.type = bookSource.getBookType()
|
book.type = bookSource.getBookType()
|
||||||
return kotlin.runCatching {
|
return kotlin.runCatching {
|
||||||
val preUpdateJs = bookSource.ruleToc?.preUpdateJs
|
if (runPerJs) {
|
||||||
if (runPerJs && !preUpdateJs.isNullOrBlank()) {
|
runPreUpdateJs(bookSource, book).getOrThrow()
|
||||||
kotlin.runCatching {
|
|
||||||
AnalyzeRule(book, bookSource).evalJS(preUpdateJs)
|
|
||||||
}.onFailure {
|
|
||||||
AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it)
|
|
||||||
throw it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user