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 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<BookSource>()
kotlin.runCatching {
val bookSources = GSON.fromJsonArray<BookSource>(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<BookSource>(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)
}

@ -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<RssSource>()
kotlin.runCatching {
val source = GSON.fromJsonArray<RssSource>(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<RssSource>(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)
}

Loading…
Cancel
Save