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 {
val res = okHttpClient.newCallStrResponse {
url("https://shuyuan.miaogongzi.site/upload.php")
val fileRequest = mapOf(
Pair("fileName", fileName),
Pair("file", byteArray),
Pair("contentType", "application/json")
)
postMultipart(
"multipart/form-data",
mapOf("file" to Triple(fileName, byteArray, "application/json"))
mapOf(Pair("file", fileRequest))
)
}
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>) {
val multipartBody = MultipartBody.Builder().setType(type.toMediaType())
form.forEach {
when (it.value) {
is Triple<*, *, *> -> {
val triple = it.value as Triple<*, *, *>
val fileName = triple.first!!.toString()
val file = triple.second as ByteArray
val mediaType = triple.third?.toString()?.toMediaType()
when (val value = it.value) {
is Map<*, *> -> {
val fileName = value["fileName"] as String
val file = value["file"] as ByteArray
val mediaType = (value["contentType"] as? String)?.toMediaType()
val requestBody = file.toRequestBody(mediaType)
multipartBody.addFormDataPart(it.key, fileName, requestBody)
}

Loading…
Cancel
Save