mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -57,7 +57,6 @@ import splitties.init.appCtx
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.Charset
|
||||
import java.security.MessageDigest
|
||||
@@ -310,16 +309,24 @@ interface JsExtensions : JsEncodeUtils {
|
||||
* @return 下载的文件相对路径
|
||||
*/
|
||||
fun downloadFile(url: String): String {
|
||||
rhinoContext.ensureActive()
|
||||
val analyzeUrl = AnalyzeUrl(url, source = getSource(), coroutineContext = context)
|
||||
val type = UrlUtil.getSuffix(url, analyzeUrl.type)
|
||||
val path = FileUtils.getPath(
|
||||
File(FileUtils.getCachePath()),
|
||||
"${MD5Utils.md5Encode16(url)}.${type}"
|
||||
)
|
||||
val file = File(path).createFileReplace()
|
||||
val file = File(path)
|
||||
file.delete()
|
||||
analyzeUrl.getInputStream().use { iStream ->
|
||||
FileOutputStream(file).use { oStream ->
|
||||
iStream.copyTo(oStream)
|
||||
file.createFileReplace()
|
||||
try {
|
||||
file.outputStream().buffered().use { oStream ->
|
||||
iStream.copyTo(oStream)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
file.delete()
|
||||
throw e
|
||||
}
|
||||
}
|
||||
return path.substring(FileUtils.getCachePath().length)
|
||||
@@ -337,6 +344,7 @@ interface JsExtensions : JsEncodeUtils {
|
||||
ReplaceWith("downloadFile(url)")
|
||||
)
|
||||
fun downloadFile(content: String, url: String): String {
|
||||
rhinoContext.ensureActive()
|
||||
val type = AnalyzeUrl(url, source = getSource(), coroutineContext = context).type
|
||||
?: return ""
|
||||
val path = FileUtils.getPath(
|
||||
|
||||
@@ -31,7 +31,7 @@ class JsURL(url: String, baseUrl: String? = null) {
|
||||
searchParams = query?.let { _ ->
|
||||
val map = hashMapOf<String, String>()
|
||||
query.split("&").forEach {
|
||||
val x = it.split("=")
|
||||
val x = it.split("=", limit = 2)
|
||||
map[x[0]] = URLDecoder.decode(x[1], "utf-8")
|
||||
}
|
||||
map
|
||||
|
||||
Reference in New Issue
Block a user