Merge branch 'gedoor:master' into master

pull/1121/head
bushixuanqi 4 years ago committed by GitHub
commit b4ea0ee8ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 2
      app/src/main/java/io/legado/app/api/controller/SourceController.kt
  3. 13
      app/src/main/java/io/legado/app/help/ImageLoader.kt
  4. 36
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  5. 1
      app/src/main/java/io/legado/app/web/HttpServer.kt

@ -6,9 +6,11 @@ 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.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.ImageLoader
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
@ -40,13 +42,23 @@ object BookController {
} }
} }
fun getCover(parameters: Map<String, List<String>>): ReturnData {
val returnData = ReturnData()
val coverPath = parameters["path"]?.firstOrNull()
val ftBitmap = ImageLoader.loadBitmap(appCtx, coverPath)
.placeholder(CoverImageView.defaultDrawable)
.error(CoverImageView.defaultDrawable)
.submit()
return returnData.setData(ftBitmap.get())
}
/** /**
* 更新目录 * 更新目录
*/ */
fun refreshToc(parameters: Map<String, List<String>>): ReturnData { fun refreshToc(parameters: Map<String, List<String>>): ReturnData {
val returnData = ReturnData() val returnData = ReturnData()
try { try {
val bookUrl = parameters["url"]?.getOrNull(0) val bookUrl = parameters["url"]?.firstOrNull()
if (bookUrl.isNullOrEmpty()) { if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址") return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")
} }
@ -90,7 +102,7 @@ object BookController {
* 获取目录 * 获取目录
*/ */
fun getChapterList(parameters: Map<String, List<String>>): ReturnData { fun getChapterList(parameters: Map<String, List<String>>): ReturnData {
val bookUrl = parameters["url"]?.getOrNull(0) val bookUrl = parameters["url"]?.firstOrNull()
val returnData = ReturnData() val returnData = ReturnData()
if (bookUrl.isNullOrEmpty()) { if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址") return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")
@ -103,8 +115,8 @@ object BookController {
* 获取正文 * 获取正文
*/ */
fun getBookContent(parameters: Map<String, List<String>>): ReturnData { fun getBookContent(parameters: Map<String, List<String>>): ReturnData {
val bookUrl = parameters["url"]?.getOrNull(0) val bookUrl = parameters["url"]?.firstOrNull()
val index = parameters["index"]?.getOrNull(0)?.toInt() val index = parameters["index"]?.firstOrNull()?.toInt()
val returnData = ReturnData() val returnData = ReturnData()
if (bookUrl.isNullOrEmpty()) { if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址") return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")

@ -59,7 +59,7 @@ object SourceController {
} }
fun getSource(parameters: Map<String, List<String>>): ReturnData { fun getSource(parameters: Map<String, List<String>>): ReturnData {
val url = parameters["url"]?.getOrNull(0) val url = parameters["url"]?.firstOrNull()
val returnData = ReturnData() val returnData = ReturnData()
if (url.isNullOrEmpty()) { if (url.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书源地址") return returnData.setErrorMsg("参数url不能为空,请指定书源地址")

@ -30,6 +30,19 @@ object ImageLoader {
} }
} }
fun loadBitmap(context: Context, path: String?): RequestBuilder<Bitmap> {
return when {
path.isNullOrEmpty() -> Glide.with(context).asBitmap().load(path)
path.isAbsUrl() -> Glide.with(context).asBitmap().load(AnalyzeUrl(path).getGlideUrl())
path.isContentScheme() -> Glide.with(context).asBitmap().load(Uri.parse(path))
else -> kotlin.runCatching {
Glide.with(context).asBitmap().load(File(path))
}.getOrElse {
Glide.with(context).asBitmap().load(path)
}
}
}
fun load(context: Context, @DrawableRes resId: Int?): RequestBuilder<Drawable> { fun load(context: Context, @DrawableRes resId: Int?): RequestBuilder<Drawable> {
return Glide.with(context).load(resId) return Glide.with(context).load(resId)
} }

@ -285,7 +285,7 @@ interface JsExtensions {
val zipFile = getFile(zipPath) val zipFile = getFile(zipPath)
val unzipFolder = FileUtils.createFolderIfNotExist(unzipPath) val unzipFolder = FileUtils.createFolderIfNotExist(unzipPath)
ZipUtils.unzipFile(zipFile, unzipFolder) ZipUtils.unzipFile(zipFile, unzipFolder)
FileUtils.deleteFile(zipPath) FileUtils.deleteFile(zipFile.absolutePath)
return unzipPath.substring(FileUtils.getCachePath().length) return unzipPath.substring(FileUtils.getCachePath().length)
} }
@ -306,7 +306,7 @@ interface JsExtensions {
contents.deleteCharAt(contents.length - 1) contents.deleteCharAt(contents.length - 1)
} }
} }
FileUtils.deleteFile(unzipPath) FileUtils.deleteFile(unzipFolder.absolutePath)
return contents.toString() return contents.toString()
} }
@ -443,10 +443,7 @@ interface JsExtensions {
* @param iv ECB模式的偏移向量 * @param iv ECB模式的偏移向量
*/ */
fun aesDecodeToByteArray( fun aesDecodeToByteArray(
str: String, str: String, key: String, transformation: String, iv: String
key: String,
transformation: String,
iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.decryptAES( return EncoderUtils.decryptAES(
data = str.encodeToByteArray(), data = str.encodeToByteArray(),
@ -465,10 +462,7 @@ interface JsExtensions {
*/ */
fun aesDecodeToString( fun aesDecodeToString(
str: String, str: String, key: String, transformation: String, iv: String
key: String,
transformation: String,
iv: String
): String? { ): String? {
return aesDecodeToByteArray(str, key, transformation, iv)?.let { String(it) } return aesDecodeToByteArray(str, key, transformation, iv)?.let { String(it) }
} }
@ -482,10 +476,7 @@ interface JsExtensions {
*/ */
fun aesBase64DecodeToByteArray( fun aesBase64DecodeToByteArray(
str: String, str: String, key: String, transformation: String, iv: String
key: String,
transformation: String,
iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.decryptBase64AES( return EncoderUtils.decryptBase64AES(
data = str.encodeToByteArray(), data = str.encodeToByteArray(),
@ -504,10 +495,7 @@ interface JsExtensions {
*/ */
fun aesBase64DecodeToString( fun aesBase64DecodeToString(
str: String, str: String, key: String, transformation: String, iv: String
key: String,
transformation: String,
iv: String
): String? { ): String? {
return aesBase64DecodeToByteArray(str, key, transformation, iv)?.let { String(it) } return aesBase64DecodeToByteArray(str, key, transformation, iv)?.let { String(it) }
} }
@ -520,8 +508,7 @@ interface JsExtensions {
* @param iv ECB模式的偏移向量 * @param iv ECB模式的偏移向量
*/ */
fun aesEncodeToByteArray( fun aesEncodeToByteArray(
data: String, key: String, transformation: String, data: String, key: String, transformation: String, iv: String
iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.encryptAES( return EncoderUtils.encryptAES(
data.encodeToByteArray(), data.encodeToByteArray(),
@ -539,8 +526,7 @@ interface JsExtensions {
* @param iv ECB模式的偏移向量 * @param iv ECB模式的偏移向量
*/ */
fun aesEncodeToString( fun aesEncodeToString(
data: String, key: String, transformation: String, data: String, key: String, transformation: String, iv: String
iv: String
): String? { ): String? {
return aesEncodeToByteArray(data, key, transformation, iv)?.let { String(it) } return aesEncodeToByteArray(data, key, transformation, iv)?.let { String(it) }
} }
@ -553,8 +539,7 @@ interface JsExtensions {
* @param iv ECB模式的偏移向量 * @param iv ECB模式的偏移向量
*/ */
fun aesEncodeToBase64ByteArray( fun aesEncodeToBase64ByteArray(
data: String, key: String, transformation: String, data: String, key: String, transformation: String, iv: String
iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.encryptAES2Base64( return EncoderUtils.encryptAES2Base64(
data.encodeToByteArray(), data.encodeToByteArray(),
@ -572,8 +557,7 @@ interface JsExtensions {
* @param iv ECB模式的偏移向量 * @param iv ECB模式的偏移向量
*/ */
fun aesEncodeToBase64String( fun aesEncodeToBase64String(
data: String, key: String, transformation: String, data: String, key: String, transformation: String, iv: String
iv: String
): String? { ): String? {
return aesEncodeToBase64ByteArray(data, key, transformation, iv)?.let { String(it) } return aesEncodeToBase64ByteArray(data, key, transformation, iv)?.let { String(it) }
} }

@ -51,6 +51,7 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
"/getChapterList" -> BookController.getChapterList(parameters) "/getChapterList" -> BookController.getChapterList(parameters)
"/refreshToc" -> BookController.refreshToc(parameters) "/refreshToc" -> BookController.refreshToc(parameters)
"/getBookContent" -> BookController.getBookContent(parameters) "/getBookContent" -> BookController.getBookContent(parameters)
"/cover" -> BookController.getCover(parameters)
else -> null else -> null
} }
} }

Loading…
Cancel
Save