Update LocalBook.kt

简化
pull/1061/head
bushixuanqi 3 years ago committed by GitHub
parent 47106522bc
commit dd08dd2e14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt

@ -85,13 +85,13 @@ object LocalBook {
} else if (!AppConfig.bookImportFileName.isNullOrBlank()) {
//在脚本中定义如何分解文件名成书名、作者名
val bindings = SimpleBindings()
bindings["src"] = fileName
val jsonStr = AppConst.SCRIPT_ENGINE.eval(
//在用户脚本后添加捕获author、name的代码,只要脚本中author、name有值就会被捕获,未定义则赋值为空字符串
//在用户脚本后添加捕获author、name的代码,只要脚本中author、name有值就会被捕获
AppConfig.bookImportFileName + "\nJSON.stringify({author:author,name:name})",
bindings
//将文件名注入到脚步的src变量中
SimpleBindings().also{ it["src"] = fileName }
).toString()
val bookMess = GSON.fromJsonObject<HashMap<String, String>>(jsonStr) ?: HashMap()
name = bookMess["name"] ?: fileName

Loading…
Cancel
Save