Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -124,7 +124,7 @@ eval(String(java.cacheFile(url)))
|
|||||||
删除缓存文件
|
删除缓存文件
|
||||||
cache.delete(java.md5Encode16(url))
|
cache.delete(java.md5Encode16(url))
|
||||||
```
|
```
|
||||||
* 获取网络压缩文件里面指定路径的数据 *可替换Zip Rar 7Z Archive
|
* 获取网络压缩文件里面指定路径的数据 *可替换Zip Rar 7Z
|
||||||
```
|
```
|
||||||
java.get*StringContent(url: String, path: String): String
|
java.get*StringContent(url: String, path: String): String
|
||||||
|
|
||||||
@@ -167,8 +167,7 @@ java.androidId()
|
|||||||
* 文件
|
* 文件
|
||||||
> 所有对于文件的读写删操作都是相对路径,只能操作阅读缓存/android/data/{package}/cache/内的文件
|
> 所有对于文件的读写删操作都是相对路径,只能操作阅读缓存/android/data/{package}/cache/内的文件
|
||||||
```
|
```
|
||||||
//文件下载,content为十六进制字符串,url用于生成文件名,返回文件路径
|
//文件下载 url用于生成文件名,返回文件路径
|
||||||
downloadFile(content: String, url: String): String
|
|
||||||
downloadFile(url: String): String
|
downloadFile(url: String): String
|
||||||
//文件解压,zipPath为压缩文件路径,返回解压路径
|
//文件解压,zipPath为压缩文件路径,返回解压路径
|
||||||
unArchiveFile(zipPath: String): String
|
unArchiveFile(zipPath: String): String
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
*/
|
*/
|
||||||
fun importScript(path: String): String {
|
fun importScript(path: String): String {
|
||||||
val result = when {
|
val result = when {
|
||||||
path.startsWith("http") -> cacheFile(path) ?: ""
|
path.startsWith("http") -> cacheFile(path)
|
||||||
path.isUri() -> Uri.parse(path).readText(appCtx)
|
path.isUri() -> Uri.parse(path).readText(appCtx)
|
||||||
path.startsWith("/storage") -> FileUtils.readText(path)
|
path.startsWith("/storage") -> FileUtils.readText(path)
|
||||||
else -> readTxtFile(path)
|
else -> readTxtFile(path)
|
||||||
@@ -187,7 +187,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
* @param urlStr 网络文件的链接
|
* @param urlStr 网络文件的链接
|
||||||
* @return 返回缓存后的文件内容
|
* @return 返回缓存后的文件内容
|
||||||
*/
|
*/
|
||||||
fun cacheFile(urlStr: String): String? {
|
fun cacheFile(urlStr: String): String {
|
||||||
return cacheFile(urlStr, 0)
|
return cacheFile(urlStr, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,16 +195,17 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
* 缓存以文本方式保存的文件 如.js .txt等
|
* 缓存以文本方式保存的文件 如.js .txt等
|
||||||
* @param saveTime 缓存时间,单位:秒
|
* @param saveTime 缓存时间,单位:秒
|
||||||
*/
|
*/
|
||||||
fun cacheFile(urlStr: String, saveTime: Int): String? {
|
fun cacheFile(urlStr: String, saveTime: Int): String {
|
||||||
val key = md5Encode16(urlStr)
|
val key = md5Encode16(urlStr)
|
||||||
val cache = CacheManager.getFile(key)
|
val cahcePath = CacheManager.get(key)
|
||||||
if (cache.isNullOrBlank()) {
|
return if (cahcePath.isNullOrBlank()) {
|
||||||
log("首次下载 $urlStr")
|
val path = downloadFile(urlStr)
|
||||||
val value = ajax(urlStr) ?: return null
|
log("首次下载 $urlStr >> $path")
|
||||||
CacheManager.putFile(key, value, saveTime)
|
CacheManager.put(key, path, saveTime)
|
||||||
return value
|
readTxtFile(path)
|
||||||
|
} else {
|
||||||
|
readTxtFile(cahcePath)
|
||||||
}
|
}
|
||||||
return cache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -224,12 +225,12 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件
|
* 下载文件
|
||||||
* @param url 下载地址:可带参数type,文件后缀,不带默认zip
|
* @param url 下载地址:可带参数type
|
||||||
* @return 下载的文件相对路径
|
* @return 下载的文件相对路径
|
||||||
*/
|
*/
|
||||||
fun downloadFile(url: String): String {
|
fun downloadFile(url: String): String {
|
||||||
val analyzeUrl = AnalyzeUrl(url, source = getSource())
|
val analyzeUrl = AnalyzeUrl(url, source = getSource())
|
||||||
val type = analyzeUrl.type ?: "zip"
|
val type = UrlUtil.getSuffix(url, analyzeUrl.type)
|
||||||
val path = FileUtils.getPath(
|
val path = FileUtils.getPath(
|
||||||
File(FileUtils.getCachePath()),
|
File(FileUtils.getCachePath()),
|
||||||
"${MD5Utils.md5Encode16(url)}.${type}"
|
"${MD5Utils.md5Encode16(url)}.${type}"
|
||||||
@@ -250,6 +251,10 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
* @param url 通过url里的参数来判断文件类型
|
* @param url 通过url里的参数来判断文件类型
|
||||||
* @return 相对路径
|
* @return 相对路径
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"Depreted",
|
||||||
|
ReplaceWith("downloadFile(url: String)")
|
||||||
|
)
|
||||||
fun downloadFile(content: String, url: String): String {
|
fun downloadFile(content: String, url: String): String {
|
||||||
val type = AnalyzeUrl(url, source = getSource()).type ?: return ""
|
val type = AnalyzeUrl(url, source = getSource()).type ?: return ""
|
||||||
val path = FileUtils.getPath(
|
val path = FileUtils.getPath(
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo
|
|||||||
val fileDoc = FileDoc.fromUri(uri, false)
|
val fileDoc = FileDoc.fromUri(uri, false)
|
||||||
fileName = fileDoc.name
|
fileName = fileDoc.name
|
||||||
if (fileName.matches(AppPattern.archiveFileRegex)) {
|
if (fileName.matches(AppPattern.archiveFileRegex)) {
|
||||||
ArchiveUtils.deCompress(fileDoc).forEach {
|
ArchiveUtils.deCompress(fileDoc, ArchiveUtils.TEMP_PATH) {
|
||||||
|
it.matches(bookFileRegex)
|
||||||
|
}.forEach {
|
||||||
dispatch(FileDoc.fromFile(it))
|
dispatch(FileDoc.fromFile(it))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ object UrlUtil {
|
|||||||
) {
|
) {
|
||||||
path.substringAfterLast("/")
|
path.substringAfterLast("/")
|
||||||
} else {
|
} else {
|
||||||
|
AppLog.put("getFileNameFromPath: Unexpected file suffix: $suffix")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
val newScope: Scriptable = ExternalScriptable(ctxt, indexedProps)
|
val newScope: Scriptable = ExternalScriptable(ctxt, indexedProps)
|
||||||
newScope.prototype = topLevel
|
newScope.prototype = topLevel
|
||||||
newScope.put("context", newScope, ctxt)
|
newScope.put("context", newScope, ctxt)
|
||||||
|
/*
|
||||||
val cx = Context.enter()
|
val cx = Context.enter()
|
||||||
try {
|
try {
|
||||||
@Language("js")
|
@Language("js")
|
||||||
@@ -195,6 +196,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
} finally {
|
} finally {
|
||||||
Context.exit()
|
Context.exit()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
newScope
|
newScope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,6 +305,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
|
|
||||||
private const val DEBUG = false
|
private const val DEBUG = false
|
||||||
|
|
||||||
|
/*
|
||||||
@Language("js")
|
@Language("js")
|
||||||
private val printSource = """
|
private val printSource = """
|
||||||
function print(str, newline) {
|
function print(str, newline) {
|
||||||
@@ -322,6 +325,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
print(str, true);
|
print(str, true);
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
*/
|
||||||
|
|
||||||
init {
|
init {
|
||||||
ContextFactory.initGlobal(object : ContextFactory() {
|
ContextFactory.initGlobal(object : ContextFactory() {
|
||||||
|
|||||||
Reference in New Issue
Block a user