Merge pull request #1061 from bushixuanqi/patch-40

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

Loading…
Cancel
Save