diff --git a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt b/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt index f9702d042..e6f1d8e39 100644 --- a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt +++ b/app/src/main/java/io/legado/app/help/DirectLinkUpload.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) diff --git a/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt b/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt index 91721c8e8..68f73ca18 100644 --- a/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt +++ b/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt @@ -121,12 +121,11 @@ fun Request.Builder.postForm(form: Map, encoded: Boolean = false fun Request.Builder.postMultipart(type: String, form: Map) { 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) }