From 4eee1ec27ffd2a38454c576758451e1c5838c976 Mon Sep 17 00:00:00 2001 From: Celeter Date: Wed, 23 Sep 2020 11:37:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0type=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E4=B8=8B=E8=BD=BD=E5=8E=8B=E7=BC=A9=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeUrl.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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 94d67ec92..943abbd9b 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 @@ -60,6 +60,7 @@ class AnalyzeUrl( private var method = RequestMethod.GET private val splitUrlRegex = Regex(",\\s*(?=\\{)") private var proxy: String? = null + private var type: String? = null init { baseUrl?.let { @@ -191,6 +192,7 @@ class AnalyzeUrl( val option = GSON.fromJsonObject(urlArray[1]) option?.let { _ -> option.method?.let { if (it.equals("POST", true)) method = RequestMethod.POST } + option.type?.let { type = it } option.headers?.let { headers -> if (headers is Map<*, *>) { headers.forEach { entry -> @@ -326,6 +328,22 @@ class AnalyzeUrl( jsStr: String? = null, sourceRegex: String? = null, ): Res { + if (type.equals("zip", true)) { + val zipPath = FileUtils.getPath( + FileUtils.createFolderIfNotExist(FileUtils.getCachePath()), + "${MD5Utils.md5Encode16(tag)}.zip" + ) + FileUtils.deleteFile(zipPath) + getResponseBytes(tag).let { + return if (it != null) { + FileUtils.createFileIfNotExist(zipPath).writeBytes(it) + // 返回压缩文件的下载路径 + Res(url, zipPath) + } else { + Res(url, "文件下载失败\n${zipPath}") + } + } + } if (useWebView) { val params = AjaxWebView.AjaxParams(url) params.headerMap = headerMap @@ -420,7 +438,8 @@ class AnalyzeUrl( val charset: String?, val webView: Any?, val headers: Any?, - val body: Any? + val body: Any?, + val type: String? ) }