Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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,19 +77,25 @@ 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("图片链接为空")
|
||||
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)
|
||||
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)
|
||||
BitmapUtils.decodeBitmap(vFile.absolutePath, width, width)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,15 +34,29 @@ object RuleComplete {
|
||||
if (rules.isNullOrEmpty()||rules.contains(notComplete) || preRule?.contains(notComplete) ?: false){
|
||||
return rules
|
||||
}
|
||||
// 分离正则
|
||||
val regexSplit=rules.split("##".toRegex(),2)
|
||||
val cleanedRule=regexSplit[0]
|
||||
val regexRule=if (regexSplit.size>1) "##"+regexSplit[1] else ""
|
||||
|
||||
/** 尾部##分割的正则或由,分割的参数 */
|
||||
val tailStr: String
|
||||
/** 分割字符 */
|
||||
val splitStr:String
|
||||
/** 用于获取文字时添加的规则 */
|
||||
val textRule: String
|
||||
/** 用于获取链接时添加的规则 */
|
||||
val linkRule: String
|
||||
/** 用于获取图片时添加的规则 */
|
||||
val imgRule: String
|
||||
/** 用于获取图片alt属性时添加的规则 */
|
||||
val imgText: String
|
||||
|
||||
// 分离尾部规则
|
||||
val regexSplit=rules.split("##|,".toRegex(),2)
|
||||
val cleanedRule=regexSplit[0]
|
||||
if (regexSplit.size>1){
|
||||
splitStr="##|,".toRegex().find(rules)?.value ?: ""
|
||||
tailStr = splitStr + regexSplit[1]
|
||||
}else{
|
||||
tailStr = ""
|
||||
}
|
||||
if (cleanedRule.contains(isXpath)){
|
||||
textRule = "//text()\${seq}"
|
||||
linkRule = "//@href\${seq}"
|
||||
@@ -55,9 +69,9 @@ object RuleComplete {
|
||||
imgText = "img\${at}@alt\${seq}"
|
||||
}
|
||||
return when (type) {
|
||||
1 -> needComplete.replace(cleanedRule, textRule).replace(fixImgInfo, imgText) + regexRule
|
||||
2 -> needComplete.replace(cleanedRule, linkRule) + regexRule
|
||||
3 -> needComplete.replace(cleanedRule, imgRule) + regexRule
|
||||
1 -> needComplete.replace(cleanedRule, textRule).replace(fixImgInfo, imgText) + tailStr
|
||||
2 -> needComplete.replace(cleanedRule, linkRule) + tailStr
|
||||
3 -> needComplete.replace(cleanedRule, imgRule) + tailStr
|
||||
else -> rules
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user