fix: 继续修复自建WebDav服务使用WebDav书籍的UG

1. 对列表项为文件夹的 resourceType 判断方式修改为更加细致的判断
2. 修复 caddy 服务自建 webdav 文件夹路径后缀引发的无法获取文件夹项的 BUG
3.对文件存在性的判断逻辑
pull/2046/head
谢意帆 2 years ago
parent 2e041fcf52
commit e79ff276b3
  1. 11
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  2. 4
      app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt

@ -126,8 +126,11 @@ open class WebDav(val path: String, val authorization: Authorization) {
httpUrl?.let { urlStr -> httpUrl?.let { urlStr ->
val baseUrl = NetworkUtils.getBaseUrl(urlStr) val baseUrl = NetworkUtils.getBaseUrl(urlStr)
for (element in elements) { for (element in elements) {
val href = URLDecoder.decode(element.getElementsByTag("d:href")[0].text(), "UTF-8") //依然是优化支持 caddy 自建的 WebDav ,其目录后缀都为“/”, 所以删除“/”的判定,不然无法获取该目录项
if (!href.endsWith("/")) { 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 fileName = href.substring(href.lastIndexOf("/") + 1)
val webDavFile: WebDav val webDavFile: WebDav
try { try {
@ -168,7 +171,6 @@ open class WebDav(val path: String, val authorization: Authorization) {
} }
} }
} }
}
return list return list
} }
@ -184,7 +186,8 @@ open class WebDav(val path: String, val authorization: Authorization) {
return okHttpClient.newCallResponse { return okHttpClient.newCallResponse {
url(testUrl) url(testUrl)
addHeader(authorization.name, authorization.data) addHeader(authorization.name, authorization.data)
}.code == 200 //某些自建的WebDav服务,请求数据时返回码不一定为 200,如 caddy 为207,所以改为在200-300区间
}.isSuccessful
}.getOrDefault(false) }.getOrDefault(false)
} }

@ -13,10 +13,10 @@ class WebDavFile(
val contentType: String, val contentType: String,
val resourceType: String, val resourceType: String,
val lastModify: Long val lastModify: Long
) : WebDav(urlStr, authorization) { ) : WebDav(urlStr, authorization) {
val isDir by lazy { val isDir by lazy {
contentType == "httpd/unix-directory" || resourceType.lowercase() == "<d:collection />" contentType == "httpd/unix-directory" || resourceType.lowercase().contains("collection")
} }
} }
Loading…
Cancel
Save