mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
Fix:添加js函数来修复开启js沙箱后某些书源失效。
getZipStringContent(url: String, path: String): String getZipByteArrayContent(url: String, path: String): ByteArray
This commit is contained in:
parent
2f16520593
commit
87e279ecf4
@ -15,9 +15,13 @@ import kotlinx.coroutines.runBlocking
|
||||
import org.jsoup.Connection
|
||||
import org.jsoup.Jsoup
|
||||
import splitties.init.appCtx
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.net.URLEncoder
|
||||
import java.util.*
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
@Keep
|
||||
@Suppress("unused")
|
||||
@ -275,6 +279,59 @@ interface JsExtensions {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网络zip文件里面的数据
|
||||
* @param url zip文件的链接
|
||||
* @param path 所需获取文件在zip内的路径
|
||||
* @return zip指定文件的数据
|
||||
*/
|
||||
fun getZipStringContent(url: String, path: String): String {
|
||||
val bytes = runBlocking {
|
||||
return@runBlocking okHttpClient.newCall { url(url) }.bytes()
|
||||
}
|
||||
val bos = ByteArrayOutputStream()
|
||||
val zis = ZipInputStream(ByteArrayInputStream(bytes))
|
||||
|
||||
var entry: ZipEntry = zis.nextEntry
|
||||
|
||||
while (entry != null) {
|
||||
if (entry.name.equals(path)) {
|
||||
zis.use { it.copyTo(bos) }
|
||||
return bos.toString()
|
||||
}
|
||||
entry = zis.nextEntry
|
||||
}
|
||||
Debug.log("getZipContent 未发现内容")
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网络zip文件里面的数据
|
||||
* @param url zip文件的链接
|
||||
* @param path 所需获取文件在zip内的路径
|
||||
* @return zip指定文件的数据
|
||||
*/
|
||||
fun getZipByteArrayContent(url: String, path: String): ByteArray? {
|
||||
val bytes = runBlocking {
|
||||
return@runBlocking okHttpClient.newCall { url(url) }.bytes()
|
||||
}
|
||||
val bos = ByteArrayOutputStream()
|
||||
val zis = ZipInputStream(ByteArrayInputStream(bytes))
|
||||
|
||||
var entry: ZipEntry = zis.nextEntry
|
||||
while (entry != null) {
|
||||
if (entry.name.equals(path)) {
|
||||
zis.use { it.copyTo(bos) }
|
||||
return bos.toByteArray()
|
||||
}
|
||||
entry = zis.nextEntry;
|
||||
}
|
||||
Debug.log("getZipContent 未发现内容")
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回字体解析类
|
||||
* @param str 支持url,本地文件,base64,自动判断,自动缓存
|
||||
|
Loading…
Reference in New Issue
Block a user