From 3be6838d3d233fb401a6cbc6ef128384c6d0881d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 10 Oct 2021 00:22:48 +0800 Subject: [PATCH] =?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/assets/defaultData/httpTTS.json | 13 +++++++-- .../java/io/legado/app/help/JsExtensions.kt | 7 +++++ .../app/model/analyzeRule/AnalyzeUrl.kt | 28 +++++++++++-------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/src/main/assets/defaultData/httpTTS.json b/app/src/main/assets/defaultData/httpTTS.json index d361dda1b..f0d143baf 100644 --- a/app/src/main/assets/defaultData/httpTTS.json +++ b/app/src/main/assets/defaultData/httpTTS.json @@ -13,8 +13,17 @@ "id": -29, "name": "3.阿里云语音", "url": "https://nls-gateway.cn-shanghai.aliyuncs.com/stream/v1/tts,{\"method\": \"POST\",\"body\", {\"appkey\":\"31f932fb\",\"text\":\"{{speakText}}\",\"format\":\"mp3\"}}", - "loginUrl": "", - "loginUi": "", + "loginUrl": "var query = 'AccessKeyId=' + source.loginInfoMap().get('AccessKeyId') + '&Action=CreateToken&Version=2019-02-28&Format=JSON&RegionId=cn-shanghai&SignatureMethod=HMAC-SHA1&SignatureVersion=1.0&SignatureNonce=' + java.UUID", + "loginUi": [ + { + "name": "AccessKeyId", + "type": "text" + }, + { + "name": "AccessKeySecret", + "type": "text" + } + ], "loginCheckJs": "" } ] \ No newline at end of file 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 6a7b2685b..62b859e92 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -473,6 +473,13 @@ interface JsExtensions { return msg } + /** + * 生成UUID + */ + fun randomUUID(): String { + return UUID.randomUUID().toString() + } + /** * AES 解码为 ByteArray * @param str 传入的AES加密的数据 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 1a5c85673..ffb733632 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 @@ -27,11 +27,11 @@ import kotlin.collections.HashMap * Created by GKF on 2018/1/24. * 搜索URL规则解析 */ -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") @Keep @SuppressLint("DefaultLocale") class AnalyzeUrl( - var ruleUrl: String, + val mUrl: String, val key: String? = null, val page: Int? = null, val speakText: String? = null, @@ -48,13 +48,15 @@ class AnalyzeUrl( private val accessTime = hashMapOf() } - val headerMap = HashMap() + var ruleUrl = "" + private set var url: String = "" private set var body: String? = null private set var type: String? = null private set + val headerMap = HashMap() private var urlNoQuery: String = "" private var queryStr: String? = null private val fieldMap = LinkedHashMap() @@ -75,12 +77,20 @@ class AnalyzeUrl( headerMap.remove("proxy") } } + initUrl() + } + + /** + * 处理url + */ + fun initUrl() { + ruleUrl = mUrl //执行@js, analyzeJs() //替换参数 replaceKeyPageJs() //处理URL - initUrl() + analyzeUrl() } /** @@ -142,9 +152,9 @@ class AnalyzeUrl( } /** - * 处理URL + * 解析Url */ - private fun initUrl() { + private fun analyzeUrl() { //replaceKeyPageJs已经替换掉额外内容,此处url是基础形式,可以直接切首个‘,’之前字符串。 val urlMatcher = paramPattern.matcher(ruleUrl) val urlNoOption = @@ -245,12 +255,6 @@ class AnalyzeUrl( return SCRIPT_ENGINE.eval(jsStr, bindings) } - fun upHeader() { - source?.getHeaderMap(true)?.let { - headerMap.putAll(it) - } - } - fun put(key: String, value: String): String { chapter?.putVariable(key, value) ?: ruleData?.putVariable(key, value)