pull/32/head
kunfei 6 years ago
parent c41cfb070c
commit 6efa706a66
  1. 4
      app/build.gradle
  2. 11
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  3. 5
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  4. 6
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt

@ -127,8 +127,8 @@ dependencies {
implementation 'com.github.gedoor:rhino-android:1.3' implementation 'com.github.gedoor:rhino-android:1.3'
//Retrofit //Retrofit
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.0' implementation 'com.squareup.okhttp3:logging-interceptor:4.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0' implementation 'com.squareup.retrofit2:retrofit:2.6.1'
//Glide //Glide
implementation 'com.github.bumptech.glide:glide:4.9.0' implementation 'com.github.bumptech.glide:glide:4.9.0'

@ -4,6 +4,7 @@ import io.legado.app.lib.webdav.http.Handler
import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.lib.webdav.http.HttpAuth
import io.legado.app.lib.webdav.http.OkHttp import io.legado.app.lib.webdav.http.OkHttp
import okhttp3.* import okhttp3.*
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import org.jsoup.Jsoup import org.jsoup.Jsoup
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
@ -42,7 +43,7 @@ constructor(url: String) {
HttpAuth.auth?.let { request.header("Authorization", Credentials.basic(it.user, it.pass)) } HttpAuth.auth?.let { request.header("Authorization", Credentials.basic(it.user, it.pass)) }
try { try {
return okHttpClient.newCall(request.build()).execute().body()?.byteStream() return okHttpClient.newCall(request.build()).execute().body?.byteStream()
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
@ -82,7 +83,7 @@ constructor(url: String) {
this.exists = false this.exists = false
return false return false
} }
response.body()?.let { response.body?.let {
if (it.string().isNotEmpty()) { if (it.string().isNotEmpty()) {
return true return true
} }
@ -102,7 +103,7 @@ constructor(url: String) {
fun listFiles(propsList: ArrayList<String> = ArrayList()): List<WebDav> { fun listFiles(propsList: ArrayList<String> = ArrayList()): List<WebDav> {
propFindResponse(propsList)?.let { response -> propFindResponse(propsList)?.let { response ->
if (response.isSuccessful) { if (response.isSuccessful) {
response.body()?.let { body -> response.body?.let { body ->
return parseDir(body.string()) return parseDir(body.string())
} }
} }
@ -128,7 +129,7 @@ constructor(url: String) {
.url(url) .url(url)
// 添加RequestBody对象,可以只返回的属性。如果设为null,则会返回全部属性 // 添加RequestBody对象,可以只返回的属性。如果设为null,则会返回全部属性
// 注意:尽量手动指定需要返回的属性。若返回全部属性,可能后由于Prop.java里没有该属性名,而崩溃。 // 注意:尽量手动指定需要返回的属性。若返回全部属性,可能后由于Prop.java里没有该属性名,而崩溃。
.method("PROPFIND", RequestBody.create(MediaType.parse("text/plain"), requestPropsStr)) .method("PROPFIND", RequestBody.create("text/plain".toMediaTypeOrNull(), requestPropsStr))
HttpAuth.auth?.let { request.header("Authorization", Credentials.basic(it.user, it.pass)) } HttpAuth.auth?.let { request.header("Authorization", Credentials.basic(it.user, it.pass)) }
@ -206,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 MediaType.parse(contentType) val mediaType = if (contentType == null) null else contentType.toMediaTypeOrNull()
// 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息
val fileBody = RequestBody.create(mediaType, file) val fileBody = RequestBody.create(mediaType, file)
getUrl()?.let { getUrl()?.let {

@ -12,9 +12,8 @@ import io.legado.app.help.http.HttpHelper
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.Response import retrofit2.Response
import java.net.URLEncoder import java.net.URLEncoder
import java.util.* import java.util.*
@ -38,7 +37,7 @@ class AnalyzeUrl(
) { ) {
companion object { companion object {
private val pagePattern = Pattern.compile("<(.*?)>") private val pagePattern = Pattern.compile("<(.*?)>")
private val jsonType = MediaType.parse("application/json; charset=utf-8") private val jsonType = "application/json; charset=utf-8".toMediaTypeOrNull()
} }
private var baseUrl: String = "" private var baseUrl: String = ""

@ -7,9 +7,9 @@ import java.util.*
object NetworkUtils { object NetworkUtils {
fun getUrl(response: Response<*>): String { fun getUrl(response: Response<*>): String {
val networkResponse = response.raw().networkResponse() val networkResponse = response.raw().networkResponse
return networkResponse?.request()?.url()?.toString() return networkResponse?.request?.url?.toString()
?: response.raw().request().url().toString() ?: response.raw().request.url.toString()
} }
private val notNeedEncoding: BitSet by lazy { private val notNeedEncoding: BitSet by lazy {

Loading…
Cancel
Save