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

This commit is contained in:
Xwite
2023-05-07 10:34:38 +08:00
parent 468c2030fb
commit 7d47970f70
9 changed files with 25 additions and 6 deletions
@@ -1,6 +1,7 @@
package io.legado.app.help package io.legado.app.help
import android.net.Uri import android.net.Uri
import io.legado.app.R
import io.legado.app.constant.AppLog import io.legado.app.constant.AppLog
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
@@ -62,13 +63,12 @@ object AppWebDav {
suspend fun upConfig() { suspend fun upConfig() {
kotlin.runCatching { kotlin.runCatching {
authorization = null authorization = null
defaultBookWebDav = null
val account = appCtx.getPrefString(PreferKey.webDavAccount) val account = appCtx.getPrefString(PreferKey.webDavAccount)
val password = appCtx.getPrefString(PreferKey.webDavPassword) val password = appCtx.getPrefString(PreferKey.webDavPassword)
if (!account.isNullOrBlank() && !password.isNullOrBlank()) { if (!account.isNullOrBlank() && !password.isNullOrBlank()) {
val mAuthorization = Authorization(account, password) val mAuthorization = Authorization(account, password)
WebDav(rootWebDavUrl, mAuthorization).makeAsDir() checkAuthorization(mAuthorization)
WebDav(bookProgressUrl, mAuthorization).makeAsDir()
WebDav(exportsWebDavUrl, mAuthorization).makeAsDir()
val rootBooksUrl = "${rootWebDavUrl}books" val rootBooksUrl = "${rootWebDavUrl}books"
defaultBookWebDav = RemoteBookWebDav(rootBooksUrl, mAuthorization) defaultBookWebDav = RemoteBookWebDav(rootBooksUrl, mAuthorization)
authorization = 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) @Throws(Exception::class)
suspend fun getBackupNames(): ArrayList<String> { suspend fun getBackupNames(): ArrayList<String> {
val names = arrayListOf<String>() val names = arrayListOf<String>()
@@ -191,19 +191,19 @@ class BackupConfigFragment : PreferenceFragment(),
val preference = findPreference<Preference>(preferenceKey) ?: return val preference = findPreference<Preference>(preferenceKey) ?: return
when (preferenceKey) { when (preferenceKey) {
PreferKey.webDavUrl -> PreferKey.webDavUrl ->
if (value == null) { if (value.isNullOrBlank()) {
preference.summary = getString(R.string.web_dav_url_s) preference.summary = getString(R.string.web_dav_url_s)
} else { } else {
preference.summary = value.toString() preference.summary = value.toString()
} }
PreferKey.webDavAccount -> PreferKey.webDavAccount ->
if (value == null) { if (value.isNullOrBlank()) {
preference.summary = getString(R.string.web_dav_account_s) preference.summary = getString(R.string.web_dav_account_s)
} else { } else {
preference.summary = value.toString() preference.summary = value.toString()
} }
PreferKey.webDavPassword -> PreferKey.webDavPassword ->
if (value == null) { if (value.isNullOrBlank()) {
preference.summary = getString(R.string.web_dav_pw_s) preference.summary = getString(R.string.web_dav_pw_s)
} else { } else {
preference.summary = "*".repeat(value.toString().length) preference.summary = "*".repeat(value.toString().length)
@@ -1098,4 +1098,5 @@
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string> <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string> <string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string> <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
<string name="webdav_application_password_error">WebDav application password error</string>
</resources> </resources>
@@ -1101,4 +1101,5 @@
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string> <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string> <string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string> <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
<string name="webdav_application_password_error">WebDav application password error</string>
</resources> </resources>
@@ -1101,4 +1101,5 @@
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string> <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string> <string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string> <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
<string name="webdav_application_password_error">WebDav application password error</string>
</resources> </resources>
@@ -1098,4 +1098,5 @@
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string> <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string> <string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string> <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
<string name="webdav_application_password_error">webDav应用密码错误</string>
</resources> </resources>
@@ -1100,4 +1100,5 @@
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string> <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string> <string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string> <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
<string name="webdav_application_password_error">webDav应用密码错误</string>
</resources> </resources>
+1
View File
@@ -1100,4 +1100,5 @@
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string> <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string> <string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string> <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
<string name="webdav_application_password_error">webDav应用密码错误</string>
</resources> </resources>
+1
View File
@@ -1101,4 +1101,5 @@
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string> <string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string> <string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string> <string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
<string name="webdav_application_password_error">WebDav application password error</string>
</resources> </resources>