pull/517/head
gedoor 4 years ago
parent 08b0520bd2
commit bd90b4e0ec
  1. 2
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt
  2. 2
      app/src/main/java/io/legado/app/lib/webdav/HttpAuth.kt
  3. 34
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  4. 16
      app/src/main/java/io/legado/app/lib/webdav/http/Handler.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

@ -1,4 +1,4 @@
package io.legado.app.lib.webdav.http
package io.legado.app.lib.webdav
object HttpAuth {

@ -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) {
</a:propfind>"""
}
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<WebDav>()
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()

@ -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
}
}
Loading…
Cancel
Save