fix(书源导入):no path $.sourceUrls find

json.read找不到会抛出异常
pull/1869/head
Xwite 3 years ago
parent a2f69a08ff
commit eee9097273
  1. 11
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt

@ -90,13 +90,14 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
val mText = text.trim() val mText = text.trim()
when { when {
mText.isJsonObject() -> { mText.isJsonObject() -> {
val json = JsonPath.parse(mText) kotlin.runCatching {
val urls = json.read<List<String>>("$.sourceUrls") val json = JsonPath.parse(mText)
if (!urls.isNullOrEmpty()) { json.read<List<String>>("$.sourceUrls")
urls.forEach { }.onSuccess {
it.forEach {
importSourceUrl(it) importSourceUrl(it)
} }
} else { }.onFailure {
BookSource.fromJson(mText).getOrThrow().let { BookSource.fromJson(mText).getOrThrow().let {
allSources.add(it) allSources.add(it)
} }

Loading…
Cancel
Save