pull/1827/head
kunfei 3 years ago
parent 32156d92b0
commit ab8e44ee03
  1. 11
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt

@ -81,7 +81,10 @@ class WebDav(urlStr: String, val authorization: Authorization) {
* @param propsList 指定列出文件的哪些属性 * @param propsList 指定列出文件的哪些属性
*/ */
@Throws(WebDavException::class) @Throws(WebDavException::class)
private suspend fun propFindResponse(propsList: List<String> = emptyList()): String? { private suspend fun propFindResponse(
propsList: List<String> = emptyList(),
depth: Int = 1
): String? {
val requestProps = StringBuilder() val requestProps = StringBuilder()
for (p in propsList) { for (p in propsList) {
requestProps.append("<a:").append(p).append("/>\n") requestProps.append("<a:").append(p).append("/>\n")
@ -95,7 +98,7 @@ class WebDav(urlStr: String, val authorization: Authorization) {
return okHttpClient.newCallResponse { return okHttpClient.newCallResponse {
url(url) url(url)
addHeader(authorization.name, authorization.data) addHeader(authorization.name, authorization.data)
addHeader("Depth", "1") addHeader("Depth", depth.toString())
// 添加RequestBody对象,可以只返回的属性。如果设为null,则会返回全部属性 // 添加RequestBody对象,可以只返回的属性。如果设为null,则会返回全部属性
// 注意:尽量手动指定需要返回的属性。若返回全部属性,可能后由于Prop.java里没有该属性名,而崩溃。 // 注意:尽量手动指定需要返回的属性。若返回全部属性,可能后由于Prop.java里没有该属性名,而崩溃。
val requestBody = requestPropsStr.toRequestBody("text/plain".toMediaType()) val requestBody = requestPropsStr.toRequestBody("text/plain".toMediaType())
@ -144,12 +147,10 @@ class WebDav(urlStr: String, val authorization: Authorization) {
*/ */
suspend fun exists(): Boolean { suspend fun exists(): Boolean {
return kotlin.runCatching { return kotlin.runCatching {
val response = propFindResponse() ?: return false val response = propFindResponse(depth = 0) ?: return false
val document = Jsoup.parse(response) val document = Jsoup.parse(response)
val elements = document.getElementsByTag("d:response") val elements = document.getElementsByTag("d:response")
return elements.isNotEmpty() return elements.isNotEmpty()
}.onFailure {
AppLog.put("WebDav检测是否存在出错\n${it.localizedMessage}")
}.getOrDefault(false) }.getOrDefault(false)
} }

Loading…
Cancel
Save