pull/1395/head
gedoor 3 years ago
parent 8ef7ebef40
commit 4759cd4173
  1. 28
      app/src/main/java/io/legado/app/api/controller/BookSourceController.kt
  2. 20
      app/src/main/java/io/legado/app/api/controller/RssSourceController.kt

@ -17,7 +17,7 @@ object BookSourceController {
val bookSources = appDb.bookSourceDao.all val bookSources = appDb.bookSourceDao.all
val returnData = ReturnData() val returnData = ReturnData()
return if (bookSources.isEmpty()) { return if (bookSources.isEmpty()) {
returnData.setErrorMsg("设备源列表为空") returnData.setErrorMsg("设备源列表为空")
} else returnData.setData(bookSources) } else returnData.setData(bookSources)
} }
@ -28,13 +28,13 @@ object BookSourceController {
val bookSource = BookSourceAnalyzer.jsonToBookSource(postData) val bookSource = BookSourceAnalyzer.jsonToBookSource(postData)
if (bookSource != null) { if (bookSource != null) {
if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) { if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) {
returnData.setErrorMsg("源名称和URL不能为空") returnData.setErrorMsg("源名称和URL不能为空")
} else { } else {
appDb.bookSourceDao.insert(bookSource) appDb.bookSourceDao.insert(bookSource)
returnData.setData("") returnData.setData("")
} }
} else { } else {
returnData.setErrorMsg("转换源失败") returnData.setErrorMsg("转换源失败")
} }
}.onFailure { }.onFailure {
returnData.setErrorMsg(it.msg) returnData.setErrorMsg(it.msg)
@ -44,17 +44,17 @@ object BookSourceController {
fun saveSources(postData: String?): ReturnData { fun saveSources(postData: String?): ReturnData {
val okSources = arrayListOf<BookSource>() val okSources = arrayListOf<BookSource>()
kotlin.runCatching { val bookSources = GSON.fromJsonArray<BookSource>(postData)
val bookSources = GSON.fromJsonArray<BookSource>(postData) if (bookSources != null) {
if (bookSources != null) { for (bookSource in bookSources) {
for (bookSource in bookSources) { if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) {
if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) { continue
continue
}
appDb.bookSourceDao.insert(bookSource)
okSources.add(bookSource)
} }
appDb.bookSourceDao.insert(bookSource)
okSources.add(bookSource)
} }
} else {
return ReturnData().setErrorMsg("转换源失败")
} }
return ReturnData().setData(okSources) return ReturnData().setData(okSources)
} }
@ -63,10 +63,10 @@ object BookSourceController {
val url = parameters["url"]?.firstOrNull() val url = parameters["url"]?.firstOrNull()
val returnData = ReturnData() val returnData = ReturnData()
if (url.isNullOrEmpty()) { if (url.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定源地址") return returnData.setErrorMsg("参数url不能为空,请指定源地址")
} }
val bookSource = appDb.bookSourceDao.getBookSource(url) val bookSource = appDb.bookSourceDao.getBookSource(url)
?: return returnData.setErrorMsg("未找到源,请检查书源地址") ?: return returnData.setErrorMsg("未找到源,请检查书源地址")
return returnData.setData(bookSource) return returnData.setData(bookSource)
} }

@ -17,7 +17,7 @@ object RssSourceController {
val source = appDb.rssSourceDao.all val source = appDb.rssSourceDao.all
val returnData = ReturnData() val returnData = ReturnData()
return if (source.isEmpty()) { return if (source.isEmpty()) {
returnData.setErrorMsg("订阅源列表为空") returnData.setErrorMsg("源列表为空")
} else returnData.setData(source) } else returnData.setData(source)
} }
@ -44,17 +44,17 @@ object RssSourceController {
fun saveSources(postData: String?): ReturnData { fun saveSources(postData: String?): ReturnData {
val okSources = arrayListOf<RssSource>() val okSources = arrayListOf<RssSource>()
kotlin.runCatching { val source = GSON.fromJsonArray<RssSource>(postData)
val source = GSON.fromJsonArray<RssSource>(postData) if (source != null) {
if (source != null) { for (rssSource in source) {
for (rssSource in source) { if (rssSource.sourceName.isBlank() || rssSource.sourceUrl.isBlank()) {
if (rssSource.sourceName.isBlank() || rssSource.sourceUrl.isBlank()) { continue
continue
}
appDb.rssSourceDao.insert(rssSource)
okSources.add(rssSource)
} }
appDb.rssSourceDao.insert(rssSource)
okSources.add(rssSource)
} }
} else {
return ReturnData().setErrorMsg("转换源失败")
} }
return ReturnData().setData(okSources) return ReturnData().setData(okSources)
} }

Loading…
Cancel
Save