|
|
@ -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) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|