diff --git a/app/src/main/java/io/legado/app/api/controller/BookSourceController.kt b/app/src/main/java/io/legado/app/api/controller/BookSourceController.kt index 341b315c8..1a73d70e4 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookSourceController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookSourceController.kt @@ -17,7 +17,7 @@ object BookSourceController { val bookSources = appDb.bookSourceDao.all val returnData = ReturnData() return if (bookSources.isEmpty()) { - returnData.setErrorMsg("设备书源列表为空") + returnData.setErrorMsg("设备源列表为空") } else returnData.setData(bookSources) } @@ -28,13 +28,13 @@ object BookSourceController { val bookSource = BookSourceAnalyzer.jsonToBookSource(postData) if (bookSource != null) { if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) { - returnData.setErrorMsg("书源名称和URL不能为空") + returnData.setErrorMsg("源名称和URL不能为空") } else { appDb.bookSourceDao.insert(bookSource) returnData.setData("") } } else { - returnData.setErrorMsg("转换书源失败") + returnData.setErrorMsg("转换源失败") } }.onFailure { returnData.setErrorMsg(it.msg) @@ -44,17 +44,17 @@ object BookSourceController { fun saveSources(postData: String?): ReturnData { val okSources = arrayListOf() - kotlin.runCatching { - val bookSources = GSON.fromJsonArray(postData) - if (bookSources != null) { - for (bookSource in bookSources) { - if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) { - continue - } - appDb.bookSourceDao.insert(bookSource) - okSources.add(bookSource) + val bookSources = GSON.fromJsonArray(postData) + if (bookSources != null) { + for (bookSource in bookSources) { + if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) { + continue } + appDb.bookSourceDao.insert(bookSource) + okSources.add(bookSource) } + } else { + return ReturnData().setErrorMsg("转换源失败") } return ReturnData().setData(okSources) } @@ -63,10 +63,10 @@ object BookSourceController { val url = parameters["url"]?.firstOrNull() val returnData = ReturnData() if (url.isNullOrEmpty()) { - return returnData.setErrorMsg("参数url不能为空,请指定书源地址") + return returnData.setErrorMsg("参数url不能为空,请指定源地址") } val bookSource = appDb.bookSourceDao.getBookSource(url) - ?: return returnData.setErrorMsg("未找到书源,请检查书源地址") + ?: return returnData.setErrorMsg("未找到源,请检查书源地址") return returnData.setData(bookSource) } diff --git a/app/src/main/java/io/legado/app/api/controller/RssSourceController.kt b/app/src/main/java/io/legado/app/api/controller/RssSourceController.kt index afa29d800..d0366acb8 100644 --- a/app/src/main/java/io/legado/app/api/controller/RssSourceController.kt +++ b/app/src/main/java/io/legado/app/api/controller/RssSourceController.kt @@ -17,7 +17,7 @@ object RssSourceController { val source = appDb.rssSourceDao.all val returnData = ReturnData() return if (source.isEmpty()) { - returnData.setErrorMsg("订阅源列表为空") + returnData.setErrorMsg("源列表为空") } else returnData.setData(source) } @@ -44,17 +44,17 @@ object RssSourceController { fun saveSources(postData: String?): ReturnData { val okSources = arrayListOf() - kotlin.runCatching { - val source = GSON.fromJsonArray(postData) - if (source != null) { - for (rssSource in source) { - if (rssSource.sourceName.isBlank() || rssSource.sourceUrl.isBlank()) { - continue - } - appDb.rssSourceDao.insert(rssSource) - okSources.add(rssSource) + val source = GSON.fromJsonArray(postData) + if (source != null) { + for (rssSource in source) { + if (rssSource.sourceName.isBlank() || rssSource.sourceUrl.isBlank()) { + continue } + appDb.rssSourceDao.insert(rssSource) + okSources.add(rssSource) } + } else { + return ReturnData().setErrorMsg("转换源失败") } return ReturnData().setData(okSources) }