pull/32/head
kunfei 5 years ago
parent 99a5105cd2
commit 94fdb64557
  1. 4
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  2. 5
      app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt
  3. 6
      app/src/main/java/io/legado/app/lib/webdav/http/OkHttp.kt

@ -32,7 +32,7 @@ constructor(url: String) {
return field return field
} }
private val okHttpClient: OkHttpClient = OkHttp.SingletonHelper.okHttpClient private val okHttpClient: OkHttpClient = OkHttp.okHttpClient
val path: String val path: String
get() = url.toString() get() = url.toString()
@ -207,7 +207,7 @@ constructor(url: String) {
fun upload(localPath: String, contentType: String? = null): Boolean { fun upload(localPath: String, contentType: String? = null): Boolean {
val file = File(localPath) val file = File(localPath)
if (!file.exists()) return false if (!file.exists()) return false
val mediaType = if (contentType == null) null else contentType.toMediaTypeOrNull() val mediaType = contentType?.toMediaTypeOrNull()
// 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息
val fileBody = RequestBody.create(mediaType, file) val fileBody = RequestBody.create(mediaType, file)
getUrl()?.let { getUrl()?.let {

@ -3,11 +3,6 @@ package io.legado.app.lib.webdav.http
object HttpAuth { object HttpAuth {
var auth: Auth? = null var auth: Auth? = null
private set
fun setAuth(user: String, password: String) {
auth = Auth(user, password)
}
class Auth internal constructor(val user: String, val pass: String) class Auth internal constructor(val user: String, val pass: String)

@ -2,10 +2,6 @@ package io.legado.app.lib.webdav.http
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
class OkHttp private constructor() { object OkHttp {
object SingletonHelper {
val okHttpClient: OkHttpClient = OkHttpClient.Builder().build() val okHttpClient: OkHttpClient = OkHttpClient.Builder().build()
}
} }
Loading…
Cancel
Save