Merge pull request #1612 from Netrvin/master

Data URI 支持(TXT)
pull/1615/head
kunfei 3 years ago committed by GitHub
commit c35f208e49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt

@ -1,6 +1,7 @@
package io.legado.app.model.analyzeRule package io.legado.app.model.analyzeRule
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.util.Base64
import androidx.annotation.Keep import androidx.annotation.Keep
import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.load.model.LazyHeaders import com.bumptech.glide.load.model.LazyHeaders
@ -461,30 +462,39 @@ class AnalyzeUrl(
* 访问网站,返回ByteArray * 访问网站,返回ByteArray
*/ */
suspend fun getByteArrayAwait(): ByteArray { suspend fun getByteArrayAwait(): ByteArray {
val dataUriRegex = Regex("data:[\\w/\\-\\.]+;base64,(.*)")
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
val concurrentRecord = fetchStart() val concurrentRecord = fetchStart()
setCookie(source?.getKey()) setCookie(source?.getKey())
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
val byteArray = getProxyClient(proxy).newCallResponseBody(retry) { if (dataUriFindResult != null){
addHeaders(headerMap) val dataUriBase64 = dataUriFindResult.groupValues?.get(1)
when (method) { val byteArray = Base64.decode(dataUriBase64, Base64.DEFAULT)
RequestMethod.POST -> { fetchEnd(concurrentRecord)
url(urlNoQuery) return byteArray
val contentType = headerMap["Content-Type"] }else {
val body = body val byteArray = getProxyClient(proxy).newCallResponseBody(retry) {
if (fieldMap.isNotEmpty() || body.isNullOrBlank()) { addHeaders(headerMap)
postForm(fieldMap, true) when (method) {
} else if (!contentType.isNullOrBlank()) { RequestMethod.POST -> {
val requestBody = body.toRequestBody(contentType.toMediaType()) url(urlNoQuery)
post(requestBody) val contentType = headerMap["Content-Type"]
} else { val body = body
postJson(body) if (fieldMap.isNotEmpty() || body.isNullOrBlank()) {
postForm(fieldMap, true)
} else if (!contentType.isNullOrBlank()) {
val requestBody = body.toRequestBody(contentType.toMediaType())
post(requestBody)
} else {
postJson(body)
}
} }
else -> get(urlNoQuery, fieldMap, true)
} }
else -> get(urlNoQuery, fieldMap, true) }.bytes()
} fetchEnd(concurrentRecord)
}.bytes() return byteArray
fetchEnd(concurrentRecord) }
return byteArray
} }
fun getByteArray(): ByteArray { fun getByteArray(): ByteArray {

Loading…
Cancel
Save