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. 8
      app/src/main/java/io/legado/app/lib/webdav/http/OkHttp.kt

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

@ -3,11 +3,6 @@ package io.legado.app.lib.webdav.http
object HttpAuth {
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)

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