mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user