Просмотр исходного кода

去除刷新前重新获取目录url
添加刷新前js,功能更强大

kunfei 4 лет назад
Родитель
Сommit
fc8640248b

+ 2 - 1
app/src/main/assets/updateLog.md

@@ -16,8 +16,9 @@
 * 更新cronet: 102.0.5005.78
 * 缓存导出添加导出图片文件选项
 * 其他设置添加图片绘制缓存选项
-* 移除刷新时重新获取目录页链接Url的配置
+* 移除书源详情页规则添加刷新时重新获取目录页链接Url
 * 添加刷新前Js,功能更强大
+* 添加java.reGetBook(), 重新获取书籍
 
 **2022/05/27**
 

+ 22 - 3
app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@@ -704,14 +704,33 @@ class AnalyzeRule(
         }
     }
 
+    /**
+     * 重新获取book
+     */
+    fun reGetBook() {
+        val bookSource = source as? BookSource
+        val book = book as? Book
+        if (bookSource == null || book == null) return
+        runBlocking {
+            WebBook.preciseSearchAwait(this, bookSource, book.name, book.author)
+                .getOrThrow().let {
+                    book.bookUrl = it.bookUrl
+                    it.variableMap.forEach { entry ->
+                        book.putVariable(entry.key, entry.value)
+                    }
+                }
+            WebBook.getBookInfoAwait(this, bookSource, book, false)
+        }
+    }
+
     /**
      * 更新tocUrl,有些书源目录url定期更新,可以在js调用更新
      */
     fun refreshTocUrl() {
+        val bookSource = source as? BookSource
+        val book = book as? Book
+        if (bookSource == null || book == null) return
         runBlocking {
-            val bookSource = source as? BookSource
-            val book = book as? Book
-            if (bookSource == null || book == null) return@runBlocking
             WebBook.getBookInfoAwait(this, bookSource, book)
         }
     }

+ 4 - 4
app/src/main/java/io/legado/app/model/webBook/WebBook.kt

@@ -339,20 +339,20 @@ object WebBook {
         bookSource: BookSource,
         name: String,
         author: String,
-    ): Result<Book?> {
+    ): Result<Book> {
         return kotlin.runCatching {
-            if (!scope.isActive) return@runCatching null
+            scope.isActive
             searchBookAwait(scope, bookSource, name).firstOrNull {
                 it.name == name && it.author == author
             }?.let { searchBook ->
-                if (!scope.isActive) return@runCatching null
+                scope.isActive
                 var book = searchBook.toBook()
                 if (book.tocUrl.isBlank()) {
                     book = getBookInfoAwait(scope, bookSource, book)
                 }
                 return@runCatching book
             }
-            return@runCatching null
+            throw NoStackTraceException("未搜索到 $name($author) 书籍")
         }
     }