From f42f31849c4d77e4d14add7fa48e6e65e811ff4c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jun 2022 17:46:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/lib/webdav/WebDav.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 04d152845..fcd5ac6e4 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 @@ -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}")