This commit is contained in:
kunfei
2022-06-08 17:46:47 +08:00
parent ea06eb5d85
commit f42f31849c

View File

@@ -278,6 +278,25 @@ open class WebDav(urlStr: String, val authorization: Authorization) {
return byteStream ?: throw WebDavException("WebDav下载出错\nNull Exception")
}
/**
* 移除文件/文件夹
*/
suspend fun delete(): Boolean {
val url = httpUrl ?: return false
//防止报错
return kotlin.runCatching {
okHttpClient.newCallResponse {
url(url)
method("DELETE", null)
addHeader(authorization.name, authorization.data)
}.let {
checkResult(it)
}
}.onFailure {
AppLog.put("WebDav删除失败\n${it.localizedMessage}")
}.isSuccess
}
private fun checkResult(response: Response) {
if (!response.isSuccessful) {
throw WebDavException("${url}\n${response.code}:${response.message}")