pull/1835/head
kunfei 3 years ago
parent fabb74990a
commit dfbeb3797b
  1. 2
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt
  2. 5
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  3. 5
      app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt
  4. 2
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -142,7 +142,7 @@ object AppWebDav {
return kotlin.runCatching { return kotlin.runCatching {
authorization?.let { authorization?.let {
var lastBackupFile: WebDavFile? = null var lastBackupFile: WebDavFile? = null
WebDav(rootWebDavUrl, it).listFiles().forEach { webDavFile -> WebDav(rootWebDavUrl, it).listFiles().reversed().forEach { webDavFile ->
if (webDavFile.displayName.startsWith("backup")) { if (webDavFile.displayName.startsWith("backup")) {
if (lastBackupFile == null if (lastBackupFile == null
|| webDavFile.lastModify > lastBackupFile!!.lastModify || webDavFile.lastModify > lastBackupFile!!.lastModify

@ -20,7 +20,6 @@ import java.net.MalformedURLException
import java.net.URL import java.net.URL
import java.net.URLEncoder import java.net.URLEncoder
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.*
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
open class WebDav(urlStr: String, val authorization: Authorization) { open class WebDav(urlStr: String, val authorization: Authorization) {
@ -133,12 +132,12 @@ open class WebDav(urlStr: String, val authorization: Authorization) {
element.getElementsByTag("d:getcontentlength") element.getElementsByTag("d:getcontentlength")
.firstOrNull()?.text()?.toLong() ?: 0 .firstOrNull()?.text()?.toLong() ?: 0
}.getOrDefault(0) }.getOrDefault(0)
val lastModify: Date? = kotlin.runCatching { val lastModify: Long = kotlin.runCatching {
element.getElementsByTag("d:getcontentlength") element.getElementsByTag("d:getcontentlength")
.firstOrNull()?.text()?.let { .firstOrNull()?.text()?.let {
dateFormat.parse(it) dateFormat.parse(it)
} }
}.getOrNull() }.getOrNull()?.time ?: 0
webDavFile = WebDavFile( webDavFile = WebDavFile(
baseUrl + fileName, baseUrl + fileName,
authorization, authorization,

@ -1,10 +1,9 @@
package io.legado.app.lib.webdav package io.legado.app.lib.webdav
import java.util.*
/** /**
* webDavFile * webDavFile
*/ */
@Suppress("unused")
class WebDavFile( class WebDavFile(
urlStr: String, urlStr: String,
authorization: Authorization, authorization: Authorization,
@ -12,5 +11,5 @@ class WebDavFile(
val urlName: String, val urlName: String,
val size: Long, val size: Long,
val contentType: String, val contentType: String,
val lastModify: Date? val lastModify: Long
) : WebDav(urlStr, authorization) ) : WebDav(urlStr, authorization)

@ -97,7 +97,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
launch { launch {
val lastBackupFile = withContext(IO) { AppWebDav.lastBackUp().getOrNull() } val lastBackupFile = withContext(IO) { AppWebDav.lastBackUp().getOrNull() }
?: return@launch ?: return@launch
if (lastBackupFile.lastModify?.time ?: 0 - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS) { if (lastBackupFile.lastModify - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS) {
alert("恢复", "webDav书源比本地新,是否恢复") { alert("恢复", "webDav书源比本地新,是否恢复") {
cancelButton() cancelButton()
okButton { okButton {

Loading…
Cancel
Save