Merge pull request #1679 from Xwite/master

更新BookController.getImg
pull/1688/head
kunfei 3 years ago committed by GitHub
commit ca284605ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      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.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.Book 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.BookHelp
import io.legado.app.help.CacheManager import io.legado.app.help.CacheManager
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
@ -29,6 +30,10 @@ import java.io.FileOutputStream
object BookController { object BookController {
private lateinit var book: Book
private var bookSource: BookSource? = null
private var bookUrl: String = ""
/** /**
* 书架所有书籍 * 书架所有书籍
*/ */
@ -72,19 +77,25 @@ object BookController {
val returnData = ReturnData() val returnData = ReturnData()
val bookUrl = parameters["url"]?.firstOrNull() val bookUrl = parameters["url"]?.firstOrNull()
?: return returnData.setErrorMsg("bookUrl为空") ?: return returnData.setErrorMsg("bookUrl为空")
val book = appDb.bookDao.getBook(bookUrl)
?: return returnData.setErrorMsg("bookUrl不对:${bookUrl}")
val src = parameters["path"]?.firstOrNull() val src = parameters["path"]?.firstOrNull()
?: return returnData.setErrorMsg("图片链接为空") ?: return returnData.setErrorMsg("图片链接为空")
val width = parameters["width"]?.firstOrNull()?.toInt() ?: 640
if (this.bookUrl != bookUrl) {
this.book = appDb.bookDao.getBook(bookUrl)
?: return returnData.setErrorMsg("bookUrl不对")
}
val vFile = BookHelp.getImage(book, src) val vFile = BookHelp.getImage(book, src)
if (!vFile.exists()) { if (!vFile.exists()) {
val bookSource = appDb.bookSourceDao.getBookSource(book.origin) if (this.bookUrl != bookUrl) {
this.bookSource = appDb.bookSourceDao.getBookSource(book.origin)
}
runBlocking { runBlocking {
BookHelp.saveImage(bookSource, book, src) BookHelp.saveImage(bookSource, book, src)
} }
} }
this.bookUrl = bookUrl
return returnData.setData( return returnData.setData(
BitmapUtils.decodeBitmap(vFile.absolutePath, 640, 640) BitmapUtils.decodeBitmap(vFile.absolutePath, width, width)
) )
} }

Loading…
Cancel
Save