feat:书源cookie选项功能实现
This commit is contained in:
@@ -21,6 +21,7 @@ interface BaseSource : JsExtensions {
|
|||||||
var loginUrl: String? // 登录地址
|
var loginUrl: String? // 登录地址
|
||||||
var loginUi: String? // 登录UI
|
var loginUi: String? // 登录UI
|
||||||
var header: String? // 请求头
|
var header: String? // 请求头
|
||||||
|
var enabledCookieJar: Boolean? //启用cookieJar
|
||||||
|
|
||||||
fun getTag(): String
|
fun getTag(): String
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ data class BookSource(
|
|||||||
var enabledExplore: Boolean = true,
|
var enabledExplore: Boolean = true,
|
||||||
// 启用okhttp CookieJAr 自动保存每次请求的cookie
|
// 启用okhttp CookieJAr 自动保存每次请求的cookie
|
||||||
@ColumnInfo(defaultValue = "0")
|
@ColumnInfo(defaultValue = "0")
|
||||||
var enabledCookieJar: Boolean = false,
|
override var enabledCookieJar: Boolean? = false,
|
||||||
// 并发率
|
// 并发率
|
||||||
override var concurrentRate: String? = null,
|
override var concurrentRate: String? = null,
|
||||||
// 请求头
|
// 请求头
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ data class HttpTTS(
|
|||||||
override var loginUrl: String? = null,
|
override var loginUrl: String? = null,
|
||||||
override var loginUi: String? = null,
|
override var loginUi: String? = null,
|
||||||
override var header: String? = null,
|
override var header: String? = null,
|
||||||
|
@ColumnInfo(defaultValue = "0")
|
||||||
|
override var enabledCookieJar: Boolean? = false,
|
||||||
var loginCheckJs: String? = null,
|
var loginCheckJs: String? = null,
|
||||||
@ColumnInfo(defaultValue = "0")
|
@ColumnInfo(defaultValue = "0")
|
||||||
var lastUpdateTime: Long = System.currentTimeMillis()
|
var lastUpdateTime: Long = System.currentTimeMillis()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.legado.app.data.entities
|
package io.legado.app.data.entities
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
@@ -19,6 +20,8 @@ data class RssSource(
|
|||||||
var sourceGroup: String? = null,
|
var sourceGroup: String? = null,
|
||||||
var sourceComment: String? = null,
|
var sourceComment: String? = null,
|
||||||
var enabled: Boolean = true,
|
var enabled: Boolean = true,
|
||||||
|
@ColumnInfo(defaultValue = "0")
|
||||||
|
override var enabledCookieJar: Boolean? = false,
|
||||||
override var concurrentRate: String? = null, //并发率
|
override var concurrentRate: String? = null, //并发率
|
||||||
override var header: String? = null, // 请求头
|
override var header: String? = null, // 请求头
|
||||||
override var loginUrl: String? = null, // 登录地址
|
override var loginUrl: String? = null, // 登录地址
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package io.legado.app.help.http
|
package io.legado.app.help.http
|
||||||
|
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
|
import io.legado.app.help.CacheManager
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.http.cronet.CronetInterceptor
|
import io.legado.app.help.http.cronet.CronetInterceptor
|
||||||
import io.legado.app.help.http.cronet.CronetLoader
|
import io.legado.app.help.http.cronet.CronetLoader
|
||||||
|
import io.legado.app.utils.NetworkUtils
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.Proxy
|
import java.net.Proxy
|
||||||
@@ -23,7 +25,10 @@ val cookieJar by lazy {
|
|||||||
|
|
||||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
cookies.forEach {
|
cookies.forEach {
|
||||||
CookieStore.replaceCookie(url.toString(), "${it.name}=${it.value}")
|
//CookieStore.replaceCookie(url.toString(), "${it.name}=${it.value}")
|
||||||
|
//临时保存 书源启用cookie选项再添加到数据库
|
||||||
|
val domain = NetworkUtils.getSubDomain(url.toString())
|
||||||
|
CacheManager.putMemory("${domain}_cookieJar", "${it.name}=${it.value}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ object BookCover {
|
|||||||
override var loginUrl: String? = null,
|
override var loginUrl: String? = null,
|
||||||
override var loginUi: String? = null,
|
override var loginUi: String? = null,
|
||||||
override var header: String? = null,
|
override var header: String? = null,
|
||||||
|
override var enabledCookieJar: Boolean? = false,
|
||||||
) : BaseSource {
|
) : BaseSource {
|
||||||
|
|
||||||
override fun getTag(): String {
|
override fun getTag(): String {
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class AnalyzeUrl(
|
|||||||
private var retry: Int = 0
|
private var retry: Int = 0
|
||||||
private var useWebView: Boolean = false
|
private var useWebView: Boolean = false
|
||||||
private var webJs: String? = null
|
private var webJs: String? = null
|
||||||
|
private val enabledCookieJar = source?.enabledCookieJar ?: false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (!mUrl.isDataUrl()) {
|
if (!mUrl.isDataUrl()) {
|
||||||
@@ -519,11 +520,19 @@ class AnalyzeUrl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*设置cookie urlOption的优先级大于书源保存的cookie
|
*设置cookie 优先级
|
||||||
|
* urlOption临时cookie > 数据库cookie = okhttp CookieJar保存在内存中的cookie
|
||||||
*@param tag 书源url 缺省为传入的url
|
*@param tag 书源url 缺省为传入的url
|
||||||
*/
|
*/
|
||||||
private fun setCookie(tag: String?) {
|
private fun setCookie(tag: String?) {
|
||||||
val cookie = CookieStore.getCookie(tag ?: url)
|
val domain = NetworkUtils.getSubDomain(tag ?: url)
|
||||||
|
//书源启用保存cookie时 添加内存中的cookie到数据库
|
||||||
|
if (enabledCookieJar) {
|
||||||
|
CacheManager.getFromMemory("${domain}_cookieJar")?.let {
|
||||||
|
CookieStore.replaceCookie(domain, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val cookie = CookieStore.getCookie(domain)
|
||||||
if (cookie.isNotEmpty()) {
|
if (cookie.isNotEmpty()) {
|
||||||
val cookieMap = CookieStore.cookieToMap(cookie)
|
val cookieMap = CookieStore.cookieToMap(cookie)
|
||||||
val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "")
|
val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "")
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ class BookSourceEditActivity :
|
|||||||
source?.let {
|
source?.let {
|
||||||
binding.cbIsEnable.isChecked = it.enabled
|
binding.cbIsEnable.isChecked = it.enabled
|
||||||
binding.cbIsEnableFind.isChecked = it.enabledExplore
|
binding.cbIsEnableFind.isChecked = it.enabledExplore
|
||||||
binding.cbIsEnableCookie.isChecked = it.enabledCookieJar
|
binding.cbIsEnableCookie.isChecked = it.enabledCookieJar ?: false
|
||||||
binding.spType.setSelection(
|
binding.spType.setSelection(
|
||||||
when (it.bookSourceType) {
|
when (it.bookSourceType) {
|
||||||
BookType.file -> 3
|
BookType.file -> 3
|
||||||
|
|||||||
Reference in New Issue
Block a user