fix webdav exists bug

This commit is contained in:
821938089 committed 2022-07-04 20:33:33 +08:00
1 parent 9049b3d791
commit 6e38daab63
1 file changed
+10 -1
@@ -171,7 +171,16 @@ open class WebDav(val path: String, val authorization: Authorization) {
* 文件是否存在
*/
suspend fun exists(): Boolean {
return getWebDavFile() != null
return kotlin.runCatching {
val requestPropsStr = DIR.replace("%s", "")
return okHttpClient.newCallResponse {
url(url)
addHeader(authorization.name, authorization.data)
addHeader("Depth", "0")
val requestBody = requestPropsStr.toRequestBody("application/xml".toMediaType())
method("PROPFIND", requestBody)
}.code == 207
}.getOrDefault(false)
}
/**