This commit is contained in:
Xwite
2023-03-18 11:20:04 +08:00
parent 087ad68049
commit d4af06747a
@@ -52,23 +52,20 @@ object SourceAnalyzer {
val documentContext = jsonPath.parse(inputStream) val documentContext = jsonPath.parse(inputStream)
try { try {
val items: List<Map<String, Any>> = documentContext.read("$") val items: List<Map<String, Any>> = documentContext.read("$")
for (item in items) { items.map {
val jsonItem = jsonPath.parse(item) val jsonItem = jsonPath.parse(it)
jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { jsonToBookSource(jsonItem.jsonString()).getOrThrow()
bookSources.add(it)
}
} }
} catch (_: Exception) { } catch (_: Exception) {
val item: Map<String, Any> = documentContext.read("$") val item: Map<String, Any> = documentContext.read("$")
val jsonItem = jsonPath.parse(item) val jsonItem = jsonPath.parse(item)
jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { mutableListOf(
bookSources.add(it) jsonToBookSource(jsonItem.jsonString()).getOrThrow()
)
} }
} catch (_: Exception) { }.onFailure {
throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) throw NoStackTraceException(appCtx.getString(R.string.wrong_format))
} }
bookSources
}
} }
fun jsonToBookSource(json: String): Result<BookSource> { fun jsonToBookSource(json: String): Result<BookSource> {