fix: java.importScript 相对路径只支持私有缓存目录

pull/1753/head
Xwite 3 years ago committed by GitHub
parent 417836eeae
commit a4ad5f30ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      app/src/main/java/io/legado/app/help/JsExtensions.kt

@ -137,22 +137,7 @@ interface JsExtensions {
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 {
if (it.isContentScheme()) {
val fileUri = Uri.parse(it + URLEncoder.encode(jsPath, "UTF-8"))
DocumentUtils.readText(appCtx, fileUri)
} else {
FileUtils.readText(it + jsPath)
}
}
//私有目录
if (jsString.isNullOrBlank()) readTxtFile(path) else jsString
}
else -> readTxtFile(path)
}
if (result.isBlank()) throw NoStackTraceException("${path} 内容获取失败或者为空")
return result

Loading…
Cancel
Save