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,6 +602,8 @@ internal class GroupImpl( ...@@ -601,6 +602,8 @@ 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 -> {
// 每 100KB 等 1 秒
withTimeoutOrNull(image.inputSize / 1024 / 100) {
HighwayHelper.uploadImage( HighwayHelper.uploadImage(
client = bot.client, client = bot.client,
serverIp = response.uploadIpList.first().toIpV4AddressString(), serverIp = response.uploadIpList.first().toIpV4AddressString(),
...@@ -611,6 +614,7 @@ internal class GroupImpl( ...@@ -611,6 +614,7 @@ internal class GroupImpl(
uKey = response.uKey, uKey = response.uKey,
commandId = 2 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