From 46e14a83ba72115eb17df37ac662442e19a3ecba Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Thu, 12 May 2022 20:47:12 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(ui):=E4=B9=A6=E6=BA=90=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E4=BF=9D=E5=AD=98?= =?UTF-8?q?cookie=E7=9A=84=E9=80=89=E9=A1=B9(=E5=8A=9F=E8=83=BD=E6=9C=AA?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 5 +++-- .../main/java/io/legado/app/data/entities/BookSource.kt | 3 +++ .../app/ui/book/source/edit/BookSourceEditActivity.kt | 2 ++ app/src/main/res/layout/activity_book_source_edit.xml | 7 +++++++ app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 11 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 7e141d90a..1cb68c80d 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -20,7 +20,7 @@ val appDb by lazy { } @Database( - version = 48, + version = 49, exportSchema = true, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, @@ -32,7 +32,8 @@ val appDb by lazy { AutoMigration(from = 44, to = 45), AutoMigration(from = 45, to = 46), AutoMigration(from = 46, to = 47), - AutoMigration(from = 47, to = 48) + AutoMigration(from = 47, to = 48), + AutoMigration(from = 48, to = 49) ] ) abstract class AppDatabase : RoomDatabase() { diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 228ba7915..85cf985b0 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -38,6 +38,9 @@ data class BookSource( var enabled: Boolean = true, // 启用发现 var enabledExplore: Boolean = true, + // 启用okhttp CookieJAr 自动保存每次请求的cookie + @ColumnInfo(defaultValue = "0") + var enabledCookieJar: Boolean = false, // 并发率 override var concurrentRate: String? = null, // 请求头 diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 3f647fa46..a280057f9 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -190,6 +190,7 @@ class BookSourceEditActivity : source?.let { binding.cbIsEnable.isChecked = it.enabled binding.cbIsEnableFind.isChecked = it.enabledExplore + binding.cbIsEnableCookie.isChecked = it.enabledCookieJar binding.spType.setSelection( when (it.bookSourceType) { BookType.file -> 3 @@ -296,6 +297,7 @@ class BookSourceEditActivity : val source = viewModel.bookSource?.copy() ?: BookSource() source.enabled = binding.cbIsEnable.isChecked source.enabledExplore = binding.cbIsEnableFind.isChecked + source.enabledCookieJar = binding.cbIsEnableCookie.isChecked source.bookSourceType = when (binding.spType.selectedItemPosition) { 3 -> BookType.file 2 -> BookType.image diff --git a/app/src/main/res/layout/activity_book_source_edit.xml b/app/src/main/res/layout/activity_book_source_edit.xml index a6f529472..ceae414f2 100644 --- a/app/src/main/res/layout/activity_book_source_edit.xml +++ b/app/src/main/res/layout/activity_book_source_edit.xml @@ -33,6 +33,13 @@ android:checked="true" android:text="@string/discovery" /> + + 导入TTS 导入主题 导入txt目录规则 + 自动保存cookie diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 7dfa85ddd..4d529828a 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -981,5 +981,6 @@ 导入TTS 导入主题 导入txt目录规则 + 自动保存cookie diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 1267823f2..81abdb45e 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -981,5 +981,6 @@ 导入TTS 导入主题 导入txt目录规则 + 自动保存cookie diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index ef0fe4e40..4bda45ccd 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -978,5 +978,6 @@ 导入TTS 导入主题 导入txt目录规则 + 自动保存cookie diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 5af20d737..7cc8a41f3 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -980,5 +980,6 @@ 导入TTS 导入主题 导入txt目录规则 + 自动保存cookie diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index b7204f02d..62dce0ac4 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -980,5 +980,6 @@ 导入TTS 导入主题 导入txt目录规则 + 自动保存cookie diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 262d98d30..b988c636d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -981,5 +981,6 @@ 导入TTS 导入主题 导入txt目录规则 + 自动保存cookie From 3e736bad199626db781b517009fe0e57cdebc2c5 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Thu, 12 May 2022 23:33:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=E4=B9=A6=E6=BA=90cookie=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/BaseSource.kt | 1 + .../java/io/legado/app/data/entities/BookSource.kt | 2 +- .../java/io/legado/app/data/entities/HttpTTS.kt | 2 ++ .../java/io/legado/app/data/entities/RssSource.kt | 3 +++ .../main/java/io/legado/app/help/http/HttpHelper.kt | 7 ++++++- app/src/main/java/io/legado/app/model/BookCover.kt | 1 + .../io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 13 +++++++++++-- .../ui/book/source/edit/BookSourceEditActivity.kt | 2 +- 8 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt index 45466f2a2..50acc0492 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt @@ -21,6 +21,7 @@ interface BaseSource : JsExtensions { var loginUrl: String? // 登录地址 var loginUi: String? // 登录UI var header: String? // 请求头 + var enabledCookieJar: Boolean? //启用cookieJar fun getTag(): String diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 85cf985b0..dc2997f87 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -40,7 +40,7 @@ data class BookSource( var enabledExplore: Boolean = true, // 启用okhttp CookieJAr 自动保存每次请求的cookie @ColumnInfo(defaultValue = "0") - var enabledCookieJar: Boolean = false, + override var enabledCookieJar: Boolean? = false, // 并发率 override var concurrentRate: String? = null, // 请求头 diff --git a/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt b/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt index afcbae9bc..4ad644d73 100644 --- a/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt +++ b/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt @@ -24,6 +24,8 @@ data class HttpTTS( override var loginUrl: String? = null, override var loginUi: String? = null, override var header: String? = null, + @ColumnInfo(defaultValue = "0") + override var enabledCookieJar: Boolean? = false, var loginCheckJs: String? = null, @ColumnInfo(defaultValue = "0") var lastUpdateTime: Long = System.currentTimeMillis() diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 8c3e98d46..dca1fa0ac 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -1,6 +1,7 @@ package io.legado.app.data.entities import android.os.Parcelable +import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.Index import androidx.room.PrimaryKey @@ -19,6 +20,8 @@ data class RssSource( var sourceGroup: String? = null, var sourceComment: String? = null, var enabled: Boolean = true, + @ColumnInfo(defaultValue = "0") + override var enabledCookieJar: Boolean? = false, override var concurrentRate: String? = null, //并发率 override var header: String? = null, // 请求头 override var loginUrl: String? = null, // 登录地址 diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index c5cb6ea79..e6e1a672f 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -1,9 +1,11 @@ package io.legado.app.help.http import io.legado.app.constant.AppConst +import io.legado.app.help.CacheManager import io.legado.app.help.config.AppConfig import io.legado.app.help.http.cronet.CronetInterceptor import io.legado.app.help.http.cronet.CronetLoader +import io.legado.app.utils.NetworkUtils import okhttp3.* import java.net.InetSocketAddress import java.net.Proxy @@ -23,7 +25,10 @@ val cookieJar by lazy { override fun saveFromResponse(url: HttpUrl, cookies: List) { 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}") } } diff --git a/app/src/main/java/io/legado/app/model/BookCover.kt b/app/src/main/java/io/legado/app/model/BookCover.kt index 75fba23de..c91d6cc0b 100644 --- a/app/src/main/java/io/legado/app/model/BookCover.kt +++ b/app/src/main/java/io/legado/app/model/BookCover.kt @@ -150,6 +150,7 @@ object BookCover { override var loginUrl: String? = null, override var loginUi: String? = null, override var header: String? = null, + override var enabledCookieJar: Boolean? = false, ) : BaseSource { override fun getTag(): String { diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 2802921d5..65c57af4d 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -69,6 +69,7 @@ class AnalyzeUrl( private var retry: Int = 0 private var useWebView: Boolean = false private var webJs: String? = null + private val enabledCookieJar = source?.enabledCookieJar ?: false init { if (!mUrl.isDataUrl()) { @@ -519,11 +520,19 @@ class AnalyzeUrl( } /** - *设置cookie urlOption的优先级大于书源保存的cookie + *设置cookie 优先级 + * urlOption临时cookie > 数据库cookie = okhttp CookieJar保存在内存中的cookie *@param tag 书源url 缺省为传入的url */ 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()) { val cookieMap = CookieStore.cookieToMap(cookie) val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "") diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index a280057f9..9fe743bad 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -190,7 +190,7 @@ class BookSourceEditActivity : source?.let { binding.cbIsEnable.isChecked = it.enabled binding.cbIsEnableFind.isChecked = it.enabledExplore - binding.cbIsEnableCookie.isChecked = it.enabledCookieJar + binding.cbIsEnableCookie.isChecked = it.enabledCookieJar ?: false binding.spType.setSelection( when (it.bookSourceType) { BookType.file -> 3 From 88a63c2ab353f2a5924eb0b811b065310eddc81d Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 13 May 2022 07:00:39 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(ui):=E7=BC=96=E8=BE=91=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=A0=8F=E6=94=BE=E4=B8=8D=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/values-es-rES/strings.xml | 2 +- app/src/main/res/values-ja-rJP/strings.xml | 2 +- app/src/main/res/values-pt-rBR/strings.xml | 2 +- app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 85648772a..a3a5e4521 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -978,6 +978,6 @@ 导入TTS 导入主题 导入txt目录规则 - 自动保存cookie + CookieJar diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 4d529828a..e98d5fa0b 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -981,6 +981,6 @@ 导入TTS 导入主题 导入txt目录规则 - 自动保存cookie + CookieJar diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 81abdb45e..7646b005e 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -981,6 +981,6 @@ 导入TTS 导入主题 导入txt目录规则 - 自动保存cookie + CookieJar diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 4bda45ccd..90eb8bc6d 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -978,6 +978,6 @@ 导入TTS 导入主题 导入txt目录规则 - 自动保存cookie + CookieJar diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 7cc8a41f3..0de83ac2f 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -980,6 +980,6 @@ 导入TTS 导入主题 导入txt目录规则 - 自动保存cookie + CookieJar diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 62dce0ac4..19069a3f2 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -980,6 +980,6 @@ 导入TTS 导入主题 导入txt目录规则 - 自动保存cookie + CookieJar diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b988c636d..582890f12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -981,6 +981,6 @@ 导入TTS 导入主题 导入txt目录规则 - 自动保存cookie + CookieJar From a6fa18b5d675a75045edfeef020b083fc3d9fd75 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 13 May 2022 07:08:29 +0800 Subject: [PATCH 4/4] docs:update doc --- app/src/main/assets/help/ruleHelp.md | 3 ++- app/src/main/assets/updateLog.md | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/help/ruleHelp.md b/app/src/main/assets/help/ruleHelp.md index 938b46bff..e3def4f4e 100644 --- a/app/src/main/assets/help/ruleHelp.md +++ b/app/src/main/assets/help/ruleHelp.md @@ -10,7 +10,8 @@ @Json: json规则,直接写时以$.开头可省略@Json : regex规则,不可省略,只可以用在书籍列表和目录列表 ``` - +* CookieJar +> 启用后会自动保存每次返回头中的Set-Cookie中的值,适用于验证码图片一类需要session的网站 * 登录UI > 不使用内置webView登录网站,需要使用`登录URL`规则实现登录逻辑,可使用`登录检查JS`检查登录结果 ``` diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 5f73271b3..d15b2c493 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,6 +11,10 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2022/05/13** + +* 书源编辑添加cookieJar选项 + **2022/05/10** * 更新cronet: 101.0.4951.61