pull/1295/head
gedoor 3 years ago
parent 2a9457b183
commit 5cdf467993
  1. 7
      app/src/main/java/io/legado/app/help/DirectLinkUpload.kt
  2. 11
      app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt

@ -14,9 +14,14 @@ object DirectLinkUpload {
suspend fun upLoad(fileName: String, byteArray: ByteArray): String { suspend fun upLoad(fileName: String, byteArray: ByteArray): String {
val res = okHttpClient.newCallStrResponse { val res = okHttpClient.newCallStrResponse {
url("https://shuyuan.miaogongzi.site/upload.php") url("https://shuyuan.miaogongzi.site/upload.php")
val fileRequest = mapOf(
Pair("fileName", fileName),
Pair("file", byteArray),
Pair("contentType", "application/json")
)
postMultipart( postMultipart(
"multipart/form-data", "multipart/form-data",
mapOf("file" to Triple(fileName, byteArray, "application/json")) mapOf(Pair("file", fileRequest))
) )
} }
val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url) val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url)

@ -121,12 +121,11 @@ fun Request.Builder.postForm(form: Map<String, String>, encoded: Boolean = false
fun Request.Builder.postMultipart(type: String, form: Map<String, Any>) { fun Request.Builder.postMultipart(type: String, form: Map<String, Any>) {
val multipartBody = MultipartBody.Builder().setType(type.toMediaType()) val multipartBody = MultipartBody.Builder().setType(type.toMediaType())
form.forEach { form.forEach {
when (it.value) { when (val value = it.value) {
is Triple<*, *, *> -> { is Map<*, *> -> {
val triple = it.value as Triple<*, *, *> val fileName = value["fileName"] as String
val fileName = triple.first!!.toString() val file = value["file"] as ByteArray
val file = triple.second as ByteArray val mediaType = (value["contentType"] as? String)?.toMediaType()
val mediaType = triple.third?.toString()?.toMediaType()
val requestBody = file.toRequestBody(mediaType) val requestBody = file.toRequestBody(mediaType)
multipartBody.addFormDataPart(it.key, fileName, requestBody) multipartBody.addFormDataPart(it.key, fileName, requestBody)
} }

Loading…
Cancel
Save