Merge pull request #1766 from Xwite/master

headers缺省优先级:书源>全局
This commit is contained in:
kunfei 2022-04-11 17:13:28 +08:00 committed by GitHub
commit 0050be8f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 49 additions and 26 deletions

View File

@ -51,8 +51,17 @@ java.put(key, value)
```
* 网络请求
```
java.ajax(urlStr)
java.ajax(urlStr): String
java.ajaxAll(urlList: Array<String>): Array<StrResponse?>
//返回Response 方法body() code() message() header() raw() toString()
java.connect(urlStr): Response<String>
* 使用webView访问网络
* @param html 直接用webView载入的html, 如果html为空直接访问url
* @param url html内如果有相对路径的资源不传入url访问不了
* @param js 用来取返回值的js语句, 没有就返回整个源代码
* @return 返回js获取的内容
java.webView(html: String?, url: String?, js: String?): String
```
* 调试
```
@ -142,7 +151,8 @@ java.md5Encode(str)
java.md5Encode16(str)
```
## book对象的可用属性
## book对象的可用属性和方法
### 属性
> 使用方法: 在js中或{{}}中使用book.属性的方式即可获取.如在正文内容后加上 ##{{book.name+"正文卷"+title}} 可以净化 书名+正文卷+章节名称(如 我是大明星正文卷第二章我爸是豪门总裁) 这一类的字符.
```
bookUrl // 详情页Url(本地书源存储完整文件路径)
@ -174,6 +184,11 @@ order // 手动排序
originOrder //书源排序
variable // 自定义书籍变量信息(用于书源规则检索书籍信息)
```
### 方法
```
//可在正文js中关闭净化 对于漫画源有用
book.setUseReplaceRule(boolean)
```
## chapter对象的部分可用属性
> 使用方法: 在js中或{{}}中使用chapter.属性的方式即可获取.如在正文内容后加上 ##{{chapter.title+chapter.index}} 可以净化 章节标题+序号(如 第二章 天仙下凡2) 这一类的字符.

View File

@ -123,7 +123,9 @@ interface JsExtensions {
BackstageWebView(
url = url,
html = html,
javaScript = js
javaScript = js,
headerMap = getSource()?.getHeaderMap(true),
tag = getSource()?.getKey()
).getStrResponse().body
}
}

View File

@ -7,6 +7,7 @@ import android.net.Uri
import androidx.annotation.DrawableRes
import com.bumptech.glide.RequestBuilder
import io.legado.app.constant.AppPattern.dataUriRegex
import io.legado.app.data.appDb
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isContentScheme
@ -18,7 +19,7 @@ object ImageLoader {
/**
* 自动判断path类型
*/
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
fun load(context: Context, path: String?, sourceOrigin: String? = null): RequestBuilder<Drawable> {
return when {
path.isNullOrEmpty() -> GlideApp.with(context).load(path)
dataUriRegex.find(path) != null -> {
@ -27,7 +28,10 @@ object ImageLoader {
}
path.isAbsUrl() -> {
kotlin.runCatching {
val url = AnalyzeUrl(path).getGlideUrl()
val source = sourceOrigin?.let {
appDb.bookSourceDao.getBookSource(it) ?: appDb.rssSourceDao.getByKey(it)
}
val url = AnalyzeUrl(path, source = source).getGlideUrl()
GlideApp.with(context).load(url)
}.getOrDefault(
GlideApp.with(context).load(path)

View File

@ -73,7 +73,7 @@ class AnalyzeUrl(
init {
val urlMatcher = paramPattern.matcher(baseUrl)
if (urlMatcher.find()) baseUrl = baseUrl.substring(0, urlMatcher.start())
headerMapF?.let {
(headerMapF ?: source?.getHeaderMap(true))?.let {
headerMap.putAll(it)
if (it.containsKey("proxy")) {
proxy = it["proxy"]

View File

@ -35,7 +35,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) :
item: SearchBook,
payloads: MutableList<Any>
) = binding.run {
ivCover.load(item.coverUrl, item.name, item.author)
ivCover.load(item.coverUrl, item.name, item.author, false, item.origin)
tvSource.text = item.originName
}

View File

@ -43,7 +43,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
llKind.visible()
llKind.setLabels(kinds)
}
ivCover.load(item.coverUrl, item.name, item.author, AppConfig.loadOnlyWifi)
ivCover.load(item.coverUrl, item.name, item.author, AppConfig.loadOnlyWifi, item.origin)
}
}

View File

@ -219,7 +219,7 @@ class BookInfoActivity :
}
private fun showCover(book: Book) {
binding.ivCover.load(book.getDisplayCover(), book.name, book.author)
binding.ivCover.load(book.getDisplayCover(), book.name, book.author, false, book.origin)
BookCover.loadBlur(this, book.getDisplayCover())
.into(binding.bgBook)
}

View File

@ -86,7 +86,8 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
searchBook.coverUrl,
searchBook.name,
searchBook.author,
AppConfig.loadOnlyWifi
AppConfig.loadOnlyWifi,
searchBook.origin
)
}
}
@ -99,7 +100,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
"last" -> upLasted(binding, searchBook.latestChapterTitle)
"intro" -> tvIntroduce.text = searchBook.trimIntro(context)
"kind" -> upKind(binding, searchBook.getKindList())
"cover" -> ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author)
"cover" -> ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author, false, searchBook.origin)
}
}
}

View File

@ -27,13 +27,13 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
val bundle = payloads.getOrNull(0) as? Bundle
if (bundle == null) {
tvName.text = item.name
ivCover.load(item.getDisplayCover(), item.name, item.author)
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
upRefresh(binding, item)
} else {
bundle.keySet().forEach {
when (it) {
"name" -> tvName.text = item.name
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author)
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
"refresh" -> upRefresh(binding, item)
}
}

View File

@ -30,7 +30,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
tvAuthor.text = item.author
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle
ivCover.load(item.getDisplayCover(), item.name, item.author)
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
upRefresh(binding, item)
} else {
tvRead.text = item.durChapterTitle
@ -39,7 +39,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
when (it) {
"name" -> tvName.text = item.name
"author" -> tvAuthor.text = item.author
"cover" -> ivCover.load(item.getDisplayCover())
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
"refresh" -> upRefresh(binding, item)
}
}

View File

@ -63,7 +63,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
bundle.keySet().forEach {
when (it) {
"name" -> tvName.text = item.name
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author)
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
"refresh" -> upRefresh(this, item)
}
}
@ -98,7 +98,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
val item = callBack.getItem(position)
if (item is Book) {
tvName.text = item.name
ivCover.load(item.getDisplayCover(), item.name, item.author)
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
upRefresh(this, item)
}
root.setOnClickListener {

View File

@ -64,7 +64,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
when (it) {
"name" -> tvName.text = item.name
"author" -> tvAuthor.text = item.author
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author)
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
"refresh" -> upRefresh(this, item)
}
}
@ -109,7 +109,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
tvAuthor.text = item.author
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle
ivCover.load(item.getDisplayCover(), item.name, item.author)
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
flHasNew.visible()
ivAuthor.visible()
ivLast.visible()

View File

@ -27,7 +27,7 @@ class RssAdapter(context: Context, val callBack: CallBack) :
) {
binding.apply {
tvName.text = item.sourceName
ImageLoader.load(context, item.sourceIcon)
ImageLoader.load(context, item.sourceIcon, item.sourceUrl)
.centerCrop()
.placeholder(R.drawable.image_rss)
.error(R.drawable.image_rss)

View File

@ -38,7 +38,7 @@ class RssArticlesAdapter(context: Context, callBack: CallBack) :
if (item.image.isNullOrBlank() && !callBack.isGridLayout) {
imageView.gone()
} else {
ImageLoader.load(context, item.image).apply {
ImageLoader.load(context, item.image, item.origin).apply {
if (callBack.isGridLayout) {
placeholder(R.drawable.image_rss_article)
} else {

View File

@ -36,7 +36,7 @@ class RssArticlesAdapter1(context: Context, callBack: CallBack) :
if (item.image.isNullOrBlank() && !callBack.isGridLayout) {
imageView.gone()
} else {
ImageLoader.load(context, item.image).apply {
ImageLoader.load(context, item.image, item.origin).apply {
if (callBack.isGridLayout) {
placeholder(R.drawable.image_rss_article)
} else {

View File

@ -36,7 +36,7 @@ class RssArticlesAdapter2(context: Context, callBack: CallBack) :
if (item.image.isNullOrBlank() && !callBack.isGridLayout) {
imageView.gone()
} else {
ImageLoader.load(context, item.image).apply {
ImageLoader.load(context, item.image, item.origin).apply {
if (callBack.isGridLayout) {
placeholder(R.drawable.image_rss_article)
} else {

View File

@ -35,7 +35,7 @@ class RssFavoritesAdapter(context: Context, val callBack: CallBack) :
if (item.image.isNullOrBlank()) {
imageView.gone()
} else {
ImageLoader.load(context, item.image)
ImageLoader.load(context, item.image, item.origin)
.addListener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,

View File

@ -175,7 +175,8 @@ class CoverImageView @JvmOverloads constructor(
path: String? = null,
name: String? = null,
author: String? = null,
loadOnlyWifi: Boolean = false
loadOnlyWifi: Boolean = false,
sourceOrigin: String? = null
) {
this.bitmapPath = path
this.name = name?.replace(AppPattern.bdRegex, "")?.trim()
@ -186,7 +187,7 @@ class CoverImageView @JvmOverloads constructor(
.centerCrop()
.into(this)
} else {
ImageLoader.load(context, path)//Glide自动识别http://,content://和file://
ImageLoader.load(context, path, sourceOrigin)//Glide自动识别http://,content://和file://
.apply(RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi))
.placeholder(BookCover.defaultDrawable)
.error(BookCover.defaultDrawable)