diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt index 753507315..a3bb4c412 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt @@ -36,27 +36,27 @@ class OverFileSizeMaxException : IllegalStateException() */ suspend fun Group.uploadImage(image: ExternalImage): ImageId = withSession { val userContext = coroutineContext - GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey) - .sendAndExpectAsync { - withContext(userContext) { - when (it) { - is GroupImageIdRequestPacket.Response.RequireUpload -> httpClient.postImage( - htcmd = "0x6ff0071", - uin = bot.qqAccount, - groupId = GroupId(id), - imageInput = image.input, - inputSize = image.inputSize, - uKeyHex = it.uKey.toUHexString("") - ) + val response = GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey).sendAndExpect() - is GroupImageIdRequestPacket.Response.AlreadyExists -> { - } + withContext(userContext) { + when (response) { + is GroupImageIdRequestPacket.Response.RequireUpload -> httpClient.postImage( + htcmd = "0x6ff0071", + uin = bot.qqAccount, + groupId = GroupId(id), + imageInput = image.input, + inputSize = image.inputSize, + uKeyHex = response.uKey.toUHexString("") + ) - is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException() - } + is GroupImageIdRequestPacket.Response.AlreadyExists -> { } - }.join() - image.groupImageId + + is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException() + } + } + + return image.groupImageId } /**