From deeeaa3b53b98384dd11ff0fb7b5ce26f3f84f3f Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Fri, 23 Oct 2020 19:40:01 +0800 Subject: [PATCH 1/5] update java.getCookie java.getCookie("http://baidu.com") return user=test;pwd=123 java.getCookie("http://baidu.com", "user") reurn test --- app/src/main/assets/updateLog.md | 2 +- app/src/main/java/io/legado/app/help/JsExtensions.kt | 10 ++++++++-- .../main/java/io/legado/app/help/http/CookieStore.kt | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 011689a1b..10b2e6acb 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,7 +6,7 @@ **2020/10/23** * 修复选择错误的bug * 修复长图最后一张不能滚动的bug -* js添加java.getCookie(sourceUrl)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie) +* js添加java.getCookie(sourceUrl:String, key:String ?=null)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie) * 修复简繁转换没有处理标题 **2020/10/21** diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index ff7357ad4..f42828476 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -123,8 +123,14 @@ interface JsExtensions { /** *js实现读取cookie */ - fun getCookie(tag: String): String { - return CookieStore.getCookie(tag) + fun getCookie(tag: String, key: String? = null): String { + val cookie = CookieStore.getCookie(tag) + val cookieMap = CookieStore.cookieToMap(cookie) + return if (key != null) { + cookieMap.get(key) ?: "" + } else { + cookie + } } /** diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index 2f2bfaaec..f97588a87 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -43,7 +43,7 @@ object CookieStore : CookiePersistor { App.db.cookieDao().delete(NetworkUtils.getSubDomain(url)) } - private fun cookieToMap(cookie: String): MutableMap { + fun cookieToMap(cookie: String): MutableMap { val cookieMap = mutableMapOf() if (cookie.isBlank()) { return cookieMap From 0a4b2018c71a3444dfaac7dc71f4f8c1c4eaea1e Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Fri, 23 Oct 2020 20:50:31 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89cookie=E8=AE=BE=E7=BD=AE=20https://github.com/gedoor/l?= =?UTF-8?q?egado/commit/e2ba01806107fbe8523e34b760ad0dfad78ddcfa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/http/CookieStore.kt | 2 +- .../app/model/analyzeRule/AnalyzeUrl.kt | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index f97588a87..a565560b7 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -63,7 +63,7 @@ object CookieStore : CookiePersistor { return cookieMap } - private fun mapToCookie(cookieMap: Map?): String? { + fun mapToCookie(cookieMap: Map?): String? { if (cookieMap == null || cookieMap.isEmpty()) { return null } 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 160c0debf..a7eb08968 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 @@ -281,7 +281,13 @@ class AnalyzeUrl( fun getResponse(tag: String): Call { val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { - headerMap["Cookie"] += ";${cookie}" + val cookieMap = CookieStore.cookieToMap(cookie) + val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + cookieMap.putAll(customCookieMap) + val newCookie = CookieStore.mapToCookie(cookieMap) + newCookie?.let { + headerMap.put("Cookie", it) + } } return when { method == RequestMethod.POST -> { @@ -312,6 +318,16 @@ class AnalyzeUrl( if (type != null) { return Res(url, StringUtils.byteToHexString(getResponseBytes(tag))) } + val cookie = CookieStore.getCookie(tag) + if (cookie.isNotEmpty()) { + val cookieMap = CookieStore.cookieToMap(cookie) + val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + cookieMap.putAll(customCookieMap) + val newCookie = CookieStore.mapToCookie(cookieMap) + newCookie?.let { + headerMap.put("Cookie", it) + } + } if (useWebView) { val params = AjaxWebView.AjaxParams(url) params.headerMap = headerMap @@ -322,10 +338,6 @@ class AnalyzeUrl( params.tag = tag return HttpHelper.ajax(params) } - val cookie = CookieStore.getCookie(tag) - if (cookie.isNotEmpty()) { - headerMap["Cookie"] += ";${cookie}" - } val res = when { method == RequestMethod.POST -> { if (fieldMap.isNotEmpty()) { @@ -356,7 +368,13 @@ class AnalyzeUrl( if (tag != null) { val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { - headerMap["Cookie"] += ";${cookie}" + val cookieMap = CookieStore.cookieToMap(cookie) + val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + cookieMap.putAll(customCookieMap) + val newCookie = CookieStore.mapToCookie(cookieMap) + newCookie?.let { + headerMap.put("Cookie", it) + } } } val response = when { From c9ba317fa9aff2dadfa6e4c8d778b71611d53f14 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Fri, 23 Oct 2020 21:20:57 +0800 Subject: [PATCH 3/5] update log --- app/src/main/assets/updateLog.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 10b2e6acb..430408e94 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,7 +6,11 @@ **2020/10/23** * 修复选择错误的bug * 修复长图最后一张不能滚动的bug -* js添加java.getCookie(sourceUrl:String, key:String ?=null)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie) +* js添加java.getCookie(sourceUrl:String, key:String? = null)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie) +``` +java.getCookie("http://baidu.com", null) => userid=1234;pwd=adbcd +java.getCookie("http://baidu.com", "userid") => 1234 +``` * 修复简繁转换没有处理标题 **2020/10/21** From e4dde5cced58992a6f962b6dde7cf7e87b3551d7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 24 Oct 2020 09:16:29 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/JsExtensions.kt | 4 ++-- .../main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index f42828476..0984a01d9 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -3,8 +3,8 @@ package io.legado.app.help import android.util.Base64 import androidx.annotation.Keep import io.legado.app.constant.AppConst.dateFormat -import io.legado.app.help.http.SSLHelper import io.legado.app.help.http.CookieStore +import io.legado.app.help.http.SSLHelper import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* import org.jsoup.Connection @@ -127,7 +127,7 @@ interface JsExtensions { val cookie = CookieStore.getCookie(tag) val cookieMap = CookieStore.cookieToMap(cookie) return if (key != null) { - cookieMap.get(key) ?: "" + cookieMap[key] ?: "" } else { cookie } 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 a7eb08968..3cbc2b44f 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 @@ -282,7 +282,7 @@ class AnalyzeUrl( val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { val cookieMap = CookieStore.cookieToMap(cookie) - val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "") cookieMap.putAll(customCookieMap) val newCookie = CookieStore.mapToCookie(cookieMap) newCookie?.let { @@ -321,7 +321,7 @@ class AnalyzeUrl( val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { val cookieMap = CookieStore.cookieToMap(cookie) - val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "") cookieMap.putAll(customCookieMap) val newCookie = CookieStore.mapToCookie(cookieMap) newCookie?.let { @@ -369,7 +369,7 @@ class AnalyzeUrl( val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { val cookieMap = CookieStore.cookieToMap(cookie) - val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "") cookieMap.putAll(customCookieMap) val newCookie = CookieStore.mapToCookie(cookieMap) newCookie?.let { From cdbfe6d1b00a601fdcbe4524ddc86cea3fe06b5b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 24 Oct 2020 09:49:01 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E9=99=A4=E8=BF=87=E6=9C=9F=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=95=B0=E6=8D=AE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../io/legado/app/ui/welcome/WelcomeActivity.kt | 7 +++++-- 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 ++ app/src/main/res/xml/pref_config_other.xml | 16 +++++++++++----- 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index b55f35d57..0aa00ac2a 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -51,6 +51,7 @@ object PreferKey { const val defaultCover = "defaultCover" const val replaceEnableDefault = "replaceEnableDefault" const val showBrightnessView = "showBrightnessView" + const val autoClearExpired = "autoClearExpired" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index c22b8ec13..f3f4e0be7 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -6,6 +6,7 @@ import com.hankcs.hanlp.HanLP import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.SyncBookProgress @@ -33,8 +34,10 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { private fun init() { Coroutine.async { //清除过期数据 - App.db.searchBookDao() - .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) + if (getPrefBoolean(PreferKey.autoClearExpired, true)) { + App.db.searchBookDao() + .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) + } //初始化简繁转换引擎 when (AppConfig.chineseConverterType) { 1 -> HanLP.convertToSimplifiedChinese("初始化") diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 598a5577d..a0c4f79a5 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -771,5 +771,7 @@ 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! 将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开. 主题名称 + 自动清除过期搜索数据 + 超过一天的搜索数据 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 17b939c02..43de70b8f 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -771,5 +771,7 @@ 目前沒有發現源,關注公眾號[开源阅读]添加包含發現的書源! 将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开. 主题名称 + 自动清除过期搜索数据 + 超过一天的搜索数据 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 18c518d9c..62f3865dd 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -774,5 +774,7 @@ 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! 将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开. 主题名称 + 自动清除过期搜索数据 + 超过一天的搜索数据 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cdb9bc509..870f42f73 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -777,5 +777,7 @@ 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! 将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开. 主题名称 + 自动清除过期搜索数据 + 超过一天的搜索数据 diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 0e3930546..1a1541988 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -58,11 +58,6 @@ android:summary="@string/replace_enable_default_s" app:iconSpaceReserved="false" /> - - + + + +