This commit is contained in:
Horis
2023-05-13 23:43:58 +08:00
parent b38c1539c6
commit bb70568b3e
3 changed files with 1221 additions and 13 deletions
+4
View File
@@ -26,12 +26,15 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ThemeConfig.applyDayNight
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.Cronet
import io.legado.app.help.http.ObsoleteUrlFactory
import io.legado.app.help.http.okHttpClient
import io.legado.app.model.BookCover
import io.legado.app.utils.defaultSharedPreferences
import io.legado.app.utils.getPrefBoolean
import kotlinx.coroutines.launch
import splitties.init.appCtx
import splitties.systemservices.notificationManager
import java.net.URL
import java.util.concurrent.TimeUnit
class App : Application() {
@@ -53,6 +56,7 @@ class App : Application() {
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
DefaultData.upVersion()
Coroutine.async {
URL.setURLStreamHandlerFactory(ObsoleteUrlFactory(okHttpClient))
launch { installGmsTlsProvider(appCtx) }
//初始化封面
BookCover.toString()
@@ -14,6 +14,7 @@ import io.legado.app.data.entities.BaseSource
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.http.BackstageWebView
import io.legado.app.help.http.CookieManager
import io.legado.app.help.http.CookieManager.cookieJarHeader
import io.legado.app.help.http.CookieStore
import io.legado.app.help.http.SSLHelper
import io.legado.app.help.http.StrResponse
@@ -202,7 +203,7 @@ interface JsExtensions : JsEncodeUtils {
val cachePath = CacheManager.get(key)
return if (
cachePath.isNullOrBlank() ||
!getFile(cachePath).exists()
!getFile(cachePath).exists()
) {
val path = downloadFile(urlStr)
log("首次下载 $urlStr >> $path")
@@ -279,52 +280,55 @@ interface JsExtensions : JsEncodeUtils {
/**
* js实现重定向拦截,网络访问get
*/
@Suppress("UnnecessaryVariable")
fun get(urlStr: String, headers: Map<String, String>): Connection.Response {
val requestHeaders = if (getSource()?.enabledCookieJar == true) {
headers.toMutableMap().apply { put(cookieJarHeader, "1") }
} else headers
val response = Jsoup.connect(urlStr)
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
.ignoreContentType(true)
.followRedirects(false)
.headers(headers)
.headers(requestHeaders)
.method(Connection.Method.GET)
.execute()
if (getSource()?.enabledCookieJar == true) {
CookieManager.saveResponse(response)
}
return response
}
/**
* js实现重定向拦截,网络访问head,不返回Response Body更省流量
*/
@Suppress("UnnecessaryVariable")
fun head(urlStr: String, headers: Map<String, String>): Connection.Response {
val requestHeaders = if (getSource()?.enabledCookieJar == true) {
headers.toMutableMap().apply { put(cookieJarHeader, "1") }
} else headers
val response = Jsoup.connect(urlStr)
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
.ignoreContentType(true)
.followRedirects(false)
.headers(headers)
.headers(requestHeaders)
.method(Connection.Method.HEAD)
.execute()
if (getSource()?.enabledCookieJar == true) {
CookieManager.saveResponse(response)
}
return response
}
/**
* 网络访问post
*/
@Suppress("UnnecessaryVariable")
fun post(urlStr: String, body: String, headers: Map<String, String>): Connection.Response {
val requestHeaders = if (getSource()?.enabledCookieJar == true) {
headers.toMutableMap().apply { put(cookieJarHeader, "1") }
} else headers
val response = Jsoup.connect(urlStr)
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
.ignoreContentType(true)
.followRedirects(false)
.requestBody(body)
.headers(headers)
.headers(requestHeaders)
.method(Connection.Method.POST)
.execute()
if (getSource()?.enabledCookieJar == true) {
CookieManager.saveResponse(response)
}
return response
}
@@ -511,6 +515,7 @@ interface JsExtensions : JsEncodeUtils {
fun unzipFile(zipPath: String): String {
return unArchiveFile(zipPath)
}
/**
* js实现7Zip压缩文件解压
* @param zipPath 相对路径
@@ -519,6 +524,7 @@ interface JsExtensions : JsEncodeUtils {
fun un7zFile(zipPath: String): String {
return unArchiveFile(zipPath)
}
/**
* js实现Rar压缩文件解压
* @param zipPath 相对路径
@@ -527,6 +533,7 @@ interface JsExtensions : JsEncodeUtils {
fun unrarFile(zipPath: String): String {
return unArchiveFile(zipPath)
}
/**
* js实现压缩文件解压
* @param zipPath 相对路径
@@ -730,6 +737,7 @@ interface JsExtensions : JsEncodeUtils {
}
return@runBlocking x
}
str.isContentScheme() -> Uri.parse(str).readBytes(appCtx)
str.startsWith("/storage") -> File(str).readBytes()
else -> base64DecodeToByteArray(str)
File diff suppressed because it is too large Load Diff