From 6793aadbe1205dbc71e79ce293bb8249d69137fc Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 18 Mar 2023 09:07:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8C=85=E5=90=AB=E5=9C=A8=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=86=85=E7=9A=84=E5=8D=95=E4=B8=AA=E4=B9=A6=E6=BA=90=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/source/SourceAnalyzer.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index 7a55a41f4..98e76434e 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -2,6 +2,7 @@ package io.legado.app.help.source import androidx.annotation.Keep import com.jayway.jsonpath.JsonPath +import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.AppLog import io.legado.app.constant.BookSourceType @@ -11,6 +12,8 @@ import io.legado.app.exception.NoStackTraceException import io.legado.app.utils.* import java.io.InputStream import java.util.regex.Pattern +import splitties.init.appCtx + @Suppress("RegExpRedundantEscape") object SourceAnalyzer { @@ -36,7 +39,7 @@ object SourceAnalyzer { } } else -> { - throw NoStackTraceException("格式不对") + throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } } bookSources @@ -46,21 +49,24 @@ object SourceAnalyzer { fun jsonToBookSources(inputStream: InputStream): Result> { return kotlin.runCatching { val bookSources = mutableListOf() -// kotlin.runCatching { - val items: List> = jsonPath.parse(inputStream).read("$") + val documentContext = jsonPath.parse(inputStream) + kotlin.runCatching { + val items: List = documentContext.read("$") for (item in items) { val jsonItem = jsonPath.parse(item) jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { bookSources.add(it) } } -// }.onFailure { -// val item: Map = jsonPath.parse(inputStream).read("$") -// val jsonItem = jsonPath.parse(item) -// jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { -// bookSources.add(it) -// } -// } + }.onFailure { + val item: Map = documentContext.read("$") + val jsonItem = jsonPath.parse(item) + jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { + bookSources.add(it) + } + }.onFailure { + throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) + } bookSources } } @@ -69,14 +75,14 @@ object SourceAnalyzer { val source = BookSource() val sourceAny = GSON.fromJsonObject(json.trim()) .onFailure { - AppLog.put("转化书源出错", it) + AppLog.put(appCtx.getString(R.string.wrong_format), it) }.getOrNull() return kotlin.runCatching { if (sourceAny?.ruleToc == null) { source.apply { val jsonItem = jsonPath.parse(json.trim()) bookSourceUrl = jsonItem.readString("bookSourceUrl") - ?: throw NoStackTraceException("格式不对") + ?: throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) bookSourceName = jsonItem.readString("bookSourceName") ?: "" bookSourceGroup = jsonItem.readString("bookSourceGroup") loginUrl = jsonItem.readString("loginUrl")