From effc48f4e8821a9de326639309e988603b296bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=84=8F=E5=B8=86?= <1657098617@qq.com> Date: Fri, 8 Jul 2022 18:40:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=BB=BAWebD?= =?UTF-8?q?av=E6=9C=8D=E5=8A=A1=E4=BD=BF=E7=94=A8WebDav=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9BBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 增加 resourceType 加强判断是否是文件夹,有些自建服务 文件夹 contentType 属性为空 2. 修复自建服务对文件夹存在性判断的问题 --- app/src/main/java/io/legado/app/lib/webdav/WebDav.kt | 11 +++++++++-- .../main/java/io/legado/app/lib/webdav/WebDavFile.kt | 3 ++- 2 files changed, 11 insertions(+), 3 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 207a707c4..ced66ae09 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 @@ -137,6 +137,9 @@ open class WebDav(val path: String, val authorization: Authorization) { val contentType = element .getElementsByTag("d:getcontenttype") .firstOrNull()?.text().orEmpty() + val resourceType = element + .getElementsByTag("d:resourcetype") + .firstOrNull()?.html()?.trim().orEmpty() val size = kotlin.runCatching { element.getElementsByTag("d:getcontentlength") .firstOrNull()?.text()?.toLong() ?: 0 @@ -155,6 +158,7 @@ open class WebDav(val path: String, val authorization: Authorization) { urlName = urlName, size = size, contentType = contentType, + resourceType = resourceType, lastModify = lastModify ) list.add(webDavFile) @@ -171,11 +175,14 @@ open class WebDav(val path: String, val authorization: Authorization) { * 文件是否存在 */ suspend fun exists(): Boolean { + val url = httpUrl ?: return false + //当使用自建的WebDav服务时,在末尾有否 ”/“ 会影响请求的成功与否 + //使用坚果云的WebDav则不会,这里做一个简单的替换来解决这个问题 + val testUrl = url.removeSuffix("/") + "/" return kotlin.runCatching { return okHttpClient.newCallResponse { - url(url) + url(testUrl) addHeader(authorization.name, authorization.data) - head() }.code == 200 }.getOrDefault(false) } diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt index fea46ea0b..48120d7f0 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt @@ -11,11 +11,12 @@ class WebDavFile( val urlName: String, val size: Long, val contentType: String, + val resourceType: String, val lastModify: Long ) : WebDav(urlStr, authorization) { val isDir by lazy { - contentType == "httpd/unix-directory" + contentType == "httpd/unix-directory" || resourceType.lowercase() == "" } } \ No newline at end of file