mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
577ca2ad40
commit
8c88ded53d
@ -201,7 +201,7 @@ object BookController {
|
||||
/**
|
||||
* 保存书籍
|
||||
*/
|
||||
fun saveBook(postData: String?): ReturnData {
|
||||
suspend fun saveBook(postData: String?): ReturnData {
|
||||
val returnData = ReturnData()
|
||||
GSON.fromJsonObject<Book>(postData).getOrNull()?.let { book ->
|
||||
AppWebDav.uploadBookProgress(book)
|
||||
|
@ -9,7 +9,6 @@ import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookProgress
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.help.storage.Backup
|
||||
import io.legado.app.help.storage.Restore
|
||||
import io.legado.app.lib.webdav.Authorization
|
||||
@ -202,18 +201,18 @@ object AppWebDav {
|
||||
}
|
||||
}
|
||||
|
||||
fun uploadBookProgress(book: Book) {
|
||||
suspend fun uploadBookProgress(book: Book) {
|
||||
val authorization = authorization ?: return
|
||||
if (!AppConfig.syncBookProgress) return
|
||||
if (!NetworkUtils.isAvailable()) return
|
||||
Coroutine.async {
|
||||
try {
|
||||
val bookProgress = BookProgress(book)
|
||||
val json = GSON.toJson(bookProgress)
|
||||
val url = getProgressUrl(book.name, book.author)
|
||||
WebDav(url, authorization).upload(json.toByteArray(), "application/json")
|
||||
book.syncTime = System.currentTimeMillis()
|
||||
}.onError {
|
||||
AppLog.put("上传进度失败\n${it.localizedMessage}", it)
|
||||
} catch (e: Exception) {
|
||||
AppLog.put("上传进度失败\n${e.localizedMessage}", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user