Merge pull request #2076 from 821938089/compatible-custom-webdav

优化自建webdav
This commit is contained in:
kunfei
2022-07-17 22:37:43 +08:00
committed by GitHub
4 changed files with 11 additions and 7 deletions

View File

@@ -70,10 +70,13 @@ open class WebDav(val path: String, val authorization: Authorization) {
}
private val webDavClient by lazy {
val authInterceptor = Interceptor { chain ->
val request = chain.request()
.newBuilder()
.header(authorization.name, authorization.data)
.build()
var request = chain.request()
if (request.url.host == host) {
request = request
.newBuilder()
.header(authorization.name, authorization.data)
.build()
}
chain.proceed(request)
}
okHttpClient.newBuilder().run {

View File

@@ -151,7 +151,7 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
viewModel.dataCallback?.clear()
adapter.selected.clear()
viewModel.loadRemoteBookList(
viewModel.dirList.lastOrNull()?.path ?: RemoteBookWebDav.rootBookUrl
viewModel.dirList.lastOrNull()?.path
) {
if (it) {
waitDialog.show()

View File

@@ -74,9 +74,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
}
}
fun loadRemoteBookList(path: String, loadCallback: (loading: Boolean) -> Unit) {
fun loadRemoteBookList(path: String?, loadCallback: (loading: Boolean) -> Unit) {
execute {
dataCallback?.clear()
val path = path ?: RemoteBookWebDav.rootBookUrl
val bookList = RemoteBookWebDav.getRemoteBookList(path)
dataCallback?.setItems(bookList)
}.onError {

View File

@@ -286,7 +286,7 @@ class BackupConfigFragment : PreferenceFragment(),
}
fun restore() {
Coroutine.async(context = Main) {
Coroutine.async {
AppWebDav.showRestoreDialog(requireContext())
}.onError {
alert {