Commit 0d089563 authored by Him188's avatar Him188

Add timeout check for uploading image

parent e2905635
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package net.mamoe.mirai.qqandroid package net.mamoe.mirai.qqandroid
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.io.core.Closeable import kotlinx.io.core.Closeable
import net.mamoe.mirai.contact.* import net.mamoe.mirai.contact.*
import net.mamoe.mirai.data.* import net.mamoe.mirai.data.*
...@@ -601,16 +602,19 @@ internal class GroupImpl( ...@@ -601,16 +602,19 @@ internal class GroupImpl(
).also { ImageUploadEvent.Succeed(this@GroupImpl, image, it).broadcast() } ).also { ImageUploadEvent.Succeed(this@GroupImpl, image, it).broadcast() }
} }
is ImgStore.GroupPicUp.Response.RequireUpload -> { is ImgStore.GroupPicUp.Response.RequireUpload -> {
HighwayHelper.uploadImage( // 每 100KB 等 1 秒
client = bot.client, withTimeoutOrNull(image.inputSize / 1024 / 100) {
serverIp = response.uploadIpList.first().toIpV4AddressString(), HighwayHelper.uploadImage(
serverPort = response.uploadPortList.first(), client = bot.client,
imageInput = image.input, serverIp = response.uploadIpList.first().toIpV4AddressString(),
inputSize = image.inputSize.toInt(), serverPort = response.uploadPortList.first(),
md5 = image.md5, imageInput = image.input,
uKey = response.uKey, inputSize = image.inputSize.toInt(),
commandId = 2 md5 = image.md5,
) uKey = response.uKey,
commandId = 2
)
} ?: error("timeout uploading image: ${image.filename}")
val resourceId = image.calculateImageResourceId() val resourceId = image.calculateImageResourceId()
// return NotOnlineImageFromFile( // return NotOnlineImageFromFile(
// resourceId = resourceId, // resourceId = resourceId,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment