From 43d88f8c33ea3caa9f215e62e9aac2d6eab542a7 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 4 Mar 2022 12:19:54 +0800 Subject: [PATCH 1/2] refactor(BookController.getImg):cache book and bookSource --- .../legado/app/api/controller/BookController.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index f237fc447..21bd86c4a 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -8,6 +8,7 @@ import io.legado.app.api.ReturnData import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookSource import io.legado.app.help.BookHelp import io.legado.app.help.CacheManager import io.legado.app.help.ContentProcessor @@ -29,6 +30,10 @@ import java.io.FileOutputStream object BookController { + private lateinit var book: Book + private var bookSource: BookSource? = null + private var bookUrl: String = "" + /** * 书架所有书籍 */ @@ -72,17 +77,22 @@ object BookController { val returnData = ReturnData() val bookUrl = parameters["url"]?.firstOrNull() ?: return returnData.setErrorMsg("bookUrl为空") - val book = appDb.bookDao.getBook(bookUrl) - ?: return returnData.setErrorMsg("bookUrl不对:${bookUrl}") val src = parameters["path"]?.firstOrNull() ?: return returnData.setErrorMsg("图片链接为空") + if (this.bookUrl != bookUrl) { + this.book = appDb.bookDao.getBook(bookUrl) + ?: return returnData.setErrorMsg("bookUrl不对") + } val vFile = BookHelp.getImage(book, src) if (!vFile.exists()) { - val bookSource = appDb.bookSourceDao.getBookSource(book.origin) + if (this.bookUrl != bookUrl) { + this.bookSource = appDb.bookSourceDao.getBookSource(book.origin) + } runBlocking { BookHelp.saveImage(bookSource, book, src) } } + this.bookUrl = bookUrl return returnData.setData( BitmapUtils.decodeBitmap(vFile.absolutePath, 640, 640) ) From cc6e5f771f5f8d70f5e337c7eadcc0cc9f5935d7 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 4 Mar 2022 12:25:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(web=E6=AD=A3=E6=96=87=E5=9B=BE?= =?UTF-8?q?=E7=89=87):=E5=9B=BE=E7=89=87=E6=B7=BB=E5=8A=A0width=E5=8F=82?= =?UTF-8?q?=E6=95=B0(=E9=BB=98=E8=AE=A4640)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/api/controller/BookController.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index 21bd86c4a..ab55f75ba 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -79,6 +79,7 @@ object BookController { ?: return returnData.setErrorMsg("bookUrl为空") val src = parameters["path"]?.firstOrNull() ?: return returnData.setErrorMsg("图片链接为空") + val width = parameters["width"]?.firstOrNull()?.toInt() ?: 640 if (this.bookUrl != bookUrl) { this.book = appDb.bookDao.getBook(bookUrl) ?: return returnData.setErrorMsg("bookUrl不对") @@ -94,7 +95,7 @@ object BookController { } this.bookUrl = bookUrl return returnData.setData( - BitmapUtils.decodeBitmap(vFile.absolutePath, 640, 640) + BitmapUtils.decodeBitmap(vFile.absolutePath, width, width) ) }