mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
代理正文图片
This commit is contained in:
parent
09457dd0cf
commit
f5a05a2973
@ -25,6 +25,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URLDecoder
|
||||
|
||||
object BookController {
|
||||
|
||||
@ -55,7 +56,7 @@ object BookController {
|
||||
*/
|
||||
fun getCover(parameters: Map<String, List<String>>): ReturnData {
|
||||
val returnData = ReturnData()
|
||||
val coverPath = parameters["path"]?.firstOrNull()
|
||||
val coverPath = URLDecoder.decode(parameters["path"]?.firstOrNull(), "UTF-8")
|
||||
val ftBitmap = ImageLoader.loadBitmap(appCtx, coverPath).submit()
|
||||
return try {
|
||||
returnData.setData(ftBitmap.get())
|
||||
@ -64,6 +65,26 @@ object BookController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取正文图片
|
||||
*/
|
||||
fun getImg(parameters: Map<String, List<String>>): ReturnData {
|
||||
val returnData = ReturnData()
|
||||
val bookUrl = parameters["url"]?.firstOrNull()
|
||||
?: return returnData.setErrorMsg("bookUrl为空")
|
||||
val book = appDb.bookDao.getBook(bookUrl)
|
||||
?: return returnData.setErrorMsg("bookUrl不对")
|
||||
val src = URLDecoder.decode(parameters["path"]?.firstOrNull(), "UTF-8")
|
||||
val vFile = BookHelp.getImage(book, src)
|
||||
if (!vFile.exists()) {
|
||||
val bookSource = appDb.bookSourceDao.getBookSource(book.origin)
|
||||
runBlocking {
|
||||
BookHelp.saveImage(bookSource, book, src)
|
||||
}
|
||||
}
|
||||
return returnData.setData(vFile.readBytes())
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新目录
|
||||
*/
|
||||
|
@ -61,6 +61,7 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
|
||||
"/refreshToc" -> BookController.refreshToc(parameters)
|
||||
"/getBookContent" -> BookController.getBookContent(parameters)
|
||||
"/cover" -> BookController.getCover(parameters)
|
||||
"/image" -> BookController.getImg(parameters)
|
||||
"/getReadConfig" -> BookController.getWebReadConfig()
|
||||
"/getRssSource" -> RssSourceController.getSource(parameters)
|
||||
"/getRssSources" -> RssSourceController.sources
|
||||
|
Loading…
Reference in New Issue
Block a user