WebDav: 检查应用密码是否正确;输入为空时保留提示
This commit is contained in:
@@ -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>()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user