fix:importScript相对路径错误

pull/1744/head
Xwite 3 years ago
parent 9abd54b6b5
commit 417836eeae
  1. 21
      app/src/main/java/io/legado/app/help/JsExtensions.kt

@ -133,26 +133,25 @@ interface JsExtensions {
* 可从网络本地文件(阅读私有缓存目录和书籍保存位置支持相对路径)导入JavaScript脚本
*/
fun importScript(path: String): String {
var result: String = ""
when {
path.startsWith("http") -> result = cacheFile(path) ?: ""
path.isContentScheme() -> result = DocumentUtils.readText(appCtx, Uri.parse(path))
path.startsWith("/storage") -> result = FileUtils.readText(path)
val result = when {
path.startsWith("http") -> cacheFile(path) ?: ""
path.isContentScheme() -> DocumentUtils.readText(appCtx, Uri.parse(path))
path.startsWith("/storage") -> FileUtils.readText(path)
else -> {
//相对路径
val jsPath = if (path.startsWith("/")) path else "/" + path
//先找书籍保存目录下有没有
val publicStoragePath = AppConfig.defaultBookTreeUri
val jsString = publicStoragePath?.let {
val jsPath = if (path.startsWith("/")) path else "/" + path
val filePathString = it + jsPath
val fileUri = Uri.parse(filePathString)
if (fileUri.isContentScheme()) {
if (it.isContentScheme()) {
val fileUri = Uri.parse(it + URLEncoder.encode(jsPath, "UTF-8"))
DocumentUtils.readText(appCtx, fileUri)
} else {
FileUtils.readText(fileUri.path!!)
FileUtils.readText(it + jsPath)
}
}
//私有目录
result = if (jsString.isNullOrBlank()) readTxtFile(path) else jsString
if (jsString.isNullOrBlank()) readTxtFile(path) else jsString
}
}
if (result.isBlank()) throw NoStackTraceException("${path} 内容获取失败或者为空")

Loading…
Cancel
Save