|
|
@ -194,15 +194,28 @@ object AppWebDav { |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
val bookProgress = BookProgress(book) |
|
|
|
val bookProgress = BookProgress(book) |
|
|
|
val json = GSON.toJson(bookProgress) |
|
|
|
val json = GSON.toJson(bookProgress) |
|
|
|
val url = getProgressUrl(book) |
|
|
|
val url = getProgressUrl(book.name, book.author) |
|
|
|
WebDav(url, authorization).upload(json.toByteArray(), "application/json") |
|
|
|
WebDav(url, authorization).upload(json.toByteArray(), "application/json") |
|
|
|
}.onError { |
|
|
|
}.onError { |
|
|
|
AppLog.put("上传进度失败\n${it.localizedMessage}") |
|
|
|
AppLog.put("上传进度失败\n${it.localizedMessage}") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getProgressUrl(book: Book): String { |
|
|
|
fun uploadBookProgress(bookProgress: BookProgress) { |
|
|
|
return bookProgressUrl + book.name + "_" + book.author + ".json" |
|
|
|
val authorization = authorization ?: return |
|
|
|
|
|
|
|
if (!syncBookProgress) return |
|
|
|
|
|
|
|
if (!NetworkUtils.isAvailable()) return |
|
|
|
|
|
|
|
Coroutine.async { |
|
|
|
|
|
|
|
val json = GSON.toJson(bookProgress) |
|
|
|
|
|
|
|
val url = getProgressUrl(bookProgress.name, bookProgress.author) |
|
|
|
|
|
|
|
WebDav(url, authorization).upload(json.toByteArray(), "application/json") |
|
|
|
|
|
|
|
}.onError { |
|
|
|
|
|
|
|
AppLog.put("上传进度失败\n${it.localizedMessage}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getProgressUrl(name: String, author: String): String { |
|
|
|
|
|
|
|
return bookProgressUrl + name + "_" + author + ".json" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -210,7 +223,7 @@ object AppWebDav { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
suspend fun getBookProgress(book: Book): BookProgress? { |
|
|
|
suspend fun getBookProgress(book: Book): BookProgress? { |
|
|
|
authorization?.let { |
|
|
|
authorization?.let { |
|
|
|
val url = getProgressUrl(book) |
|
|
|
val url = getProgressUrl(book.name, book.author) |
|
|
|
kotlin.runCatching { |
|
|
|
kotlin.runCatching { |
|
|
|
WebDav(url, it).download().let { byteArray -> |
|
|
|
WebDav(url, it).download().let { byteArray -> |
|
|
|
val json = String(byteArray) |
|
|
|
val json = String(byteArray) |
|
|
|