From e79ff276b38bc64d47c91e50017880df58b404a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=84=8F=E5=B8=86?= <1657098617@qq.com> Date: Sat, 9 Jul 2022 23:43:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=A7=E7=BB=AD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=87=AA=E5=BB=BAWebDav=E6=9C=8D=E5=8A=A1=E4=BD=BF=E7=94=A8Web?= =?UTF-8?q?Dav=E4=B9=A6=E7=B1=8D=E7=9A=84UG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 对列表项为文件夹的 resourceType 判断方式修改为更加细致的判断 2. 修复 caddy 服务自建 webdav 文件夹路径后缀引发的无法获取文件夹项的 BUG 3.对文件存在性的判断逻辑 --- app/src/main/java/io/legado/app/lib/webdav/WebDav.kt | 11 +++++++---- .../main/java/io/legado/app/lib/webdav/WebDavFile.kt | 8 ++++---- 2 files changed, 11 insertions(+), 8 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 571174a9c..7d7b7cd46 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 @@ -126,8 +126,11 @@ open class WebDav(val path: String, val authorization: Authorization) { httpUrl?.let { urlStr -> val baseUrl = NetworkUtils.getBaseUrl(urlStr) for (element in elements) { - val href = URLDecoder.decode(element.getElementsByTag("d:href")[0].text(), "UTF-8") - if (!href.endsWith("/")) { + //依然是优化支持 caddy 自建的 WebDav ,其目录后缀都为“/”, 所以删除“/”的判定,不然无法获取该目录项 + var href = URLDecoder.decode(element.getElementsByTag("d:href")[0].text(), "UTF-8") + if (href.endsWith("/")) { + href = href.removeSuffix("/") + } val fileName = href.substring(href.lastIndexOf("/") + 1) val webDavFile: WebDav try { @@ -167,7 +170,6 @@ open class WebDav(val path: String, val authorization: Authorization) { e.printOnDebug() } } - } } return list } @@ -184,7 +186,8 @@ open class WebDav(val path: String, val authorization: Authorization) { return okHttpClient.newCallResponse { url(testUrl) addHeader(authorization.name, authorization.data) - }.code == 200 + //某些自建的WebDav服务,请求数据时返回码不一定为 200,如 caddy 为207,所以改为在200-300区间 + }.isSuccessful }.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 48120d7f0..c1f1476c1 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 @@ -13,10 +13,10 @@ class WebDavFile( val contentType: String, val resourceType: String, val lastModify: Long -) : WebDav(urlStr, authorization) { + ) : WebDav(urlStr, authorization) { - val isDir by lazy { - contentType == "httpd/unix-directory" || resourceType.lowercase() == "" - } + val isDir by lazy { + contentType == "httpd/unix-directory" || resourceType.lowercase().contains("collection") + } } \ No newline at end of file