ソースを参照

WebDav: 检查应用密码是否正确;输入为空时保留提示

Xwite 3 年 前
親
コミット
7d47970f70

+ 15 - 3
app/src/main/java/io/legado/app/help/AppWebDav.kt

@@ -1,6 +1,7 @@
 package io.legado.app.help
 
 import android.net.Uri
+import io.legado.app.R
 import io.legado.app.constant.AppLog
 import io.legado.app.constant.PreferKey
 import io.legado.app.data.appDb
@@ -62,13 +63,12 @@ object AppWebDav {
     suspend fun upConfig() {
         kotlin.runCatching {
             authorization = null
+            defaultBookWebDav = null
             val account = appCtx.getPrefString(PreferKey.webDavAccount)
             val password = appCtx.getPrefString(PreferKey.webDavPassword)
             if (!account.isNullOrBlank() && !password.isNullOrBlank()) {
                 val mAuthorization = Authorization(account, password)
-                WebDav(rootWebDavUrl, mAuthorization).makeAsDir()
-                WebDav(bookProgressUrl, mAuthorization).makeAsDir()
-                WebDav(exportsWebDavUrl, mAuthorization).makeAsDir()
+                checkAuthorization(mAuthorization)
                 val rootBooksUrl = "${rootWebDavUrl}books"
                 defaultBookWebDav = RemoteBookWebDav(rootBooksUrl, mAuthorization)
                 authorization = mAuthorization
@@ -76,6 +76,18 @@ object AppWebDav {
         }
     }
 
+    @Throws(WebDavException::class)
+    private suspend fun checkAuthorization(authorization: Authorization) {
+        if (!WebDav(rootWebDavUrl, authorization).makeAsDir() ||
+            !WebDav(bookProgressUrl, authorization).makeAsDir() ||
+            !WebDav(exportsWebDavUrl, authorization).makeAsDir()
+        ) {
+            appCtx.removePref(PreferKey.webDavPassword)
+            appCtx.toastOnUi(R.string.webdav_application_password_error)
+            throw WebDavException(appCtx.getString(R.string.webdav_application_password_error))
+        }
+    }
+
     @Throws(Exception::class)
     suspend fun getBackupNames(): ArrayList<String> {
         val names = arrayListOf<String>()

+ 3 - 3
app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@@ -191,19 +191,19 @@ class BackupConfigFragment : PreferenceFragment(),
         val preference = findPreference<Preference>(preferenceKey) ?: return
         when (preferenceKey) {
             PreferKey.webDavUrl ->
-                if (value == null) {
+                if (value.isNullOrBlank()) {
                     preference.summary = getString(R.string.web_dav_url_s)
                 } else {
                     preference.summary = value.toString()
                 }
             PreferKey.webDavAccount ->
-                if (value == null) {
+                if (value.isNullOrBlank()) {
                     preference.summary = getString(R.string.web_dav_account_s)
                 } else {
                     preference.summary = value.toString()
                 }
             PreferKey.webDavPassword ->
-                if (value == null) {
+                if (value.isNullOrBlank()) {
                     preference.summary = getString(R.string.web_dav_pw_s)
                 } else {
                     preference.summary = "*".repeat(value.toString().length)

+ 1 - 0
app/src/main/res/values-es-rES/strings.xml

@@ -1098,4 +1098,5 @@
     <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
     <string name="only_latest_backup_t">仅保留最新备份</string>
     <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
+    <string name="webdav_application_password_error">WebDav application password error</string>
 </resources>

+ 1 - 0
app/src/main/res/values-ja-rJP/strings.xml

@@ -1101,4 +1101,5 @@
     <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
     <string name="only_latest_backup_t">仅保留最新备份</string>
     <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
+    <string name="webdav_application_password_error">WebDav application password error</string>
 </resources>

+ 1 - 0
app/src/main/res/values-pt-rBR/strings.xml

@@ -1101,4 +1101,5 @@
     <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
     <string name="only_latest_backup_t">仅保留最新备份</string>
     <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
+    <string name="webdav_application_password_error">WebDav application password error</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -1098,4 +1098,5 @@
     <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
     <string name="only_latest_backup_t">仅保留最新备份</string>
     <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
+    <string name="webdav_application_password_error">webDav应用密码错误</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -1100,4 +1100,5 @@
     <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
     <string name="only_latest_backup_t">仅保留最新备份</string>
     <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
+    <string name="webdav_application_password_error">webDav应用密码错误</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh/strings.xml

@@ -1100,4 +1100,5 @@
     <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
     <string name="only_latest_backup_t">仅保留最新备份</string>
     <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
+    <string name="webdav_application_password_error">webDav应用密码错误</string>
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1101,4 +1101,5 @@
     <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
     <string name="only_latest_backup_t">仅保留最新备份</string>
     <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
+    <string name="webdav_application_password_error">WebDav application password error</string>
 </resources>