pull/1732/head
kunfei 3 years ago
parent dec5d386bc
commit cf0a00a712
  1. 7
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt

@ -122,9 +122,12 @@ object AppWebDav {
} }
suspend fun hasBackUp(): Boolean { suspend fun hasBackUp(): Boolean {
if (isOk) {
val url = "${rootWebDavUrl}${backupFileName}" val url = "${rootWebDavUrl}${backupFileName}"
return WebDav(url).exists() return WebDav(url).exists()
} }
return false
}
suspend fun backUpWebDav(path: String) { suspend fun backUpWebDav(path: String) {
try { try {
@ -163,17 +166,16 @@ object AppWebDav {
} }
fun uploadBookProgress(book: Book) { fun uploadBookProgress(book: Book) {
if (!isOk) return
if (!AppConfig.syncBookProgress) return if (!AppConfig.syncBookProgress) return
if (!NetworkUtils.isAvailable()) return if (!NetworkUtils.isAvailable()) return
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)
if (isOk) {
WebDav(url).upload(json.toByteArray(), "application/json") WebDav(url).upload(json.toByteArray(), "application/json")
} }
} }
}
private fun getProgressUrl(book: Book): String { private fun getProgressUrl(book: Book): String {
return bookProgressUrl + book.name + "_" + book.author + ".json" return bookProgressUrl + book.name + "_" + book.author + ".json"
@ -196,6 +198,7 @@ object AppWebDav {
} }
suspend fun downloadAllBookProgress() { suspend fun downloadAllBookProgress() {
if (!isOk) return
appDb.bookDao.all.forEach { book -> appDb.bookDao.all.forEach { book ->
getBookProgress(book)?.let { bookProgress -> getBookProgress(book)?.let { bookProgress ->
if (bookProgress.durChapterIndex > book.durChapterIndex || if (bookProgress.durChapterIndex > book.durChapterIndex ||

Loading…
Cancel
Save