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 af828e395..56d4f5d69 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -46,9 +46,10 @@ interface JsExtensions { * js实现文件下载 */ fun downloadFile(content: String, url: String): String { + val type = AnalyzeUrl(url).type ?: return "type为空,未下载" val zipPath = FileUtils.getPath( FileUtils.createFolderIfNotExist(FileUtils.getCachePath()), - "${MD5Utils.md5Encode16(url)}.zip" + "${MD5Utils.md5Encode16(url)}.${type}" ) FileUtils.deleteFile(zipPath) val zipFile = FileUtils.createFileIfNotExist(zipPath) @@ -137,14 +138,18 @@ interface JsExtensions { * js实现解码,不能删 */ fun base64Decode(str: String): String { - return EncoderUtils.base64Decode(str) + return EncoderUtils.base64Decode(str, Base64.NO_WRAP) + } + + fun base64Decode(str: String, flags: Int): String { + return EncoderUtils.base64Decode(str, flags) } fun base64Encode(str: String): String? { - return EncoderUtils.base64Encode(str) + return EncoderUtils.base64Encode(str, Base64.NO_WRAP) } - fun base64Encode(str: String, flags: Int = Base64.NO_WRAP): String? { + fun base64Encode(str: String, flags: Int): String? { return EncoderUtils.base64Encode(str, flags) } 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 30246e0cf..b4650d9f5 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 @@ -52,6 +52,7 @@ class AnalyzeUrl( var url: String = "" val headerMap = HashMap() var body: String? = null + var type: String? = null private lateinit var urlHasQuery: String private var queryStr: String? = null private val fieldMap = LinkedHashMap() @@ -60,7 +61,6 @@ class AnalyzeUrl( private var method = RequestMethod.GET private val splitUrlRegex = Regex(",\\s*(?=\\{)") private var proxy: String? = null - private var type: String? = null init { baseUrl = baseUrl.split(splitUrlRegex, 1)[0] diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index 8ee17662d..a2e2c4388 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -305,7 +305,7 @@ object StringUtils { } return sb.toString() } - + fun hexStringToByte(hexString: String): ByteArray? { val hexStr = hexString.replace(" ", "") val len = hexStr.length