From bd90b4e0ec0e43c7b86b5dc25be8b9aff4fa9b88 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 2 Dec 2020 22:17:16 +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 --- .../io/legado/app/help/storage/WebDavHelp.kt | 2 +- .../app/lib/webdav/{http => }/HttpAuth.kt | 2 +- .../java/io/legado/app/lib/webdav/WebDav.kt | 34 +++++++------------ .../io/legado/app/lib/webdav/http/Handler.kt | 16 --------- 4 files changed, 15 insertions(+), 39 deletions(-) rename app/src/main/java/io/legado/app/lib/webdav/{http => }/HttpAuth.kt (75%) delete mode 100644 app/src/main/java/io/legado/app/lib/webdav/http/Handler.kt diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 407bcf2c5..ae6e34ffb 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -8,8 +8,8 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.webdav.HttpAuth import io.legado.app.lib.webdav.WebDav -import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main diff --git a/app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt b/app/src/main/java/io/legado/app/lib/webdav/HttpAuth.kt similarity index 75% rename from app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt rename to app/src/main/java/io/legado/app/lib/webdav/HttpAuth.kt index 07cab5855..d2f604a80 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/HttpAuth.kt @@ -1,4 +1,4 @@ -package io.legado.app.lib.webdav.http +package io.legado.app.lib.webdav object HttpAuth { 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 ab4f3303c..73ac6f141 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 @@ -1,8 +1,6 @@ package io.legado.app.lib.webdav import io.legado.app.help.http.HttpHelper -import io.legado.app.lib.webdav.http.Handler -import io.legado.app.lib.webdav.http.HttpAuth import okhttp3.* import org.jsoup.Jsoup import java.io.File @@ -14,7 +12,7 @@ import java.net.URL import java.net.URLEncoder import java.util.* -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") class WebDav(urlStr: String) { companion object { // 指定返回哪些属性 @@ -32,7 +30,7 @@ class WebDav(urlStr: String) { """ } - private val url: URL = URL(null, urlStr, Handler) + private val url: URL = URL(urlStr) private val httpUrl: String? by lazy { val raw = url.toString().replace("davs://", "https://").replace("dav://", "http://") try { @@ -45,25 +43,13 @@ class WebDav(urlStr: String) { return@lazy null } } - + val host: String? get() = url.host + val path get() = url.toString() var displayName: String? = null var size: Long = 0 var exists = false var parent = "" var urlName = "" - get() { - if (field.isEmpty()) { - this.urlName = ( - if (parent.isEmpty()) url.file - else url.toString().replace(parent, "") - ).replace("/", "") - } - return field - } - - val path get() = url.toString() - - val host: String? get() = url.host /** * 填充文件信息。实例化WebDAVFile对象时,并没有将远程文件的信息填充到实例中。需要手动填充! @@ -143,8 +129,8 @@ class WebDav(urlStr: String) { val list = ArrayList() val document = Jsoup.parse(s) val elements = document.getElementsByTag("d:response") - httpUrl?.let { url -> - val baseUrl = if (url.endsWith("/")) url else "$url/" + httpUrl?.let { urlStr -> + val baseUrl = if (urlStr.endsWith("/")) urlStr else "$urlStr/" for (element in elements) { val href = element.getElementsByTag("d:href")[0].text() if (!href.endsWith("/")) { @@ -153,7 +139,13 @@ class WebDav(urlStr: String) { try { webDavFile = WebDav(baseUrl + fileName) webDavFile.displayName = fileName - webDavFile.urlName = href + if (href.isEmpty()) { + webDavFile.urlName = + if (parent.isEmpty()) url.file.replace("/", "") + else url.toString().replace(parent, "").replace("/", "") + } else { + webDavFile.urlName = href + } list.add(webDavFile) } catch (e: MalformedURLException) { e.printStackTrace() diff --git a/app/src/main/java/io/legado/app/lib/webdav/http/Handler.kt b/app/src/main/java/io/legado/app/lib/webdav/http/Handler.kt deleted file mode 100644 index c3deec2e2..000000000 --- a/app/src/main/java/io/legado/app/lib/webdav/http/Handler.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.legado.app.lib.webdav.http - -import java.net.URL -import java.net.URLConnection -import java.net.URLStreamHandler - -object Handler : URLStreamHandler() { - - override fun getDefaultPort(): Int { - return 80 - } - - public override fun openConnection(u: URL): URLConnection? { - return null - } -}