From ab8e44ee03278edfa34f3f8736c552af2a12fa58 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 27 Apr 2022 23:45:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/lib/webdav/WebDav.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 1ca422703..6f5c20d17 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -81,7 +81,10 @@ class WebDav(urlStr: String, val authorization: Authorization) { * @param propsList 指定列出文件的哪些属性 */ @Throws(WebDavException::class) - private suspend fun propFindResponse(propsList: List = emptyList()): String? { + private suspend fun propFindResponse( + propsList: List = emptyList(), + depth: Int = 1 + ): String? { val requestProps = StringBuilder() for (p in propsList) { requestProps.append("\n") @@ -95,7 +98,7 @@ class WebDav(urlStr: String, val authorization: Authorization) { return okHttpClient.newCallResponse { url(url) addHeader(authorization.name, authorization.data) - addHeader("Depth", "1") + addHeader("Depth", depth.toString()) // 添加RequestBody对象,可以只返回的属性。如果设为null,则会返回全部属性 // 注意:尽量手动指定需要返回的属性。若返回全部属性,可能后由于Prop.java里没有该属性名,而崩溃。 val requestBody = requestPropsStr.toRequestBody("text/plain".toMediaType()) @@ -144,12 +147,10 @@ class WebDav(urlStr: String, val authorization: Authorization) { */ suspend fun exists(): Boolean { return kotlin.runCatching { - val response = propFindResponse() ?: return false + val response = propFindResponse(depth = 0) ?: return false val document = Jsoup.parse(response) val elements = document.getElementsByTag("d:response") return elements.isNotEmpty() - }.onFailure { - AppLog.put("WebDav检测是否存在出错\n${it.localizedMessage}") }.getOrDefault(false) }