From bd74907f6818deed36765dd849a0da041cab2e1d Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 3 Jan 2020 19:08:58 +0800 Subject: [PATCH] Image uploading logs --- .../network/ContactImpl.kt | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/ContactImpl.kt b/mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/ContactImpl.kt index 34cf17c6c..23813bcf7 100644 --- a/mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/ContactImpl.kt +++ b/mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/ContactImpl.kt @@ -64,16 +64,17 @@ internal class GroupImpl internal constructor(bot: TIMPCBot, val groupId: GroupI withContext(userContext) { when (response) { - is ImageUploadInfo -> response.uKey?.let { - Http.postImage( + is ImageUploadInfo -> response.uKey?.let { uKey -> + check(Http.postImage( htcmd = "0x6ff0071", uin = bot.qqAccount, groupId = GroupId(id), imageInput = image.input, inputSize = image.inputSize, - uKeyHex = it.toUHexString("") - ) - } // if null: image already exists + uKeyHex = uKey.toUHexString("").also { require(it.length == 128 * 2) { "Illegal uKey. expected size=256, actual size=${it.length}" } } + )) { "Group image upload failed: cannot access api" } + logger.verbose("group image uploaded") + } ?: logger.verbose("Group image upload: already exists") // TODO: 2019/11/17 超过大小的情况 //is Overfile -> throw OverFileSizeMaxException() @@ -118,14 +119,17 @@ internal class QQImpl @PublishedApi internal constructor(bot: TIMPCBot, override FriendImagePacket.RequestImageId(qqAccount, sessionKey, id, image).sendAndExpect().let { when (it) { is FriendImageUKey -> { - Http.postImage( - htcmd = "0x6ff0070", - uin = bot.qqAccount, - groupId = null, - uKeyHex = it.uKey.toUHexString(""), - imageInput = image.input, - inputSize = image.inputSize - ) + check( + Http.postImage( + htcmd = "0x6ff0070", + uin = bot.qqAccount, + groupId = null, + uKeyHex = it.uKey.toUHexString(""), + imageInput = image.input, + inputSize = image.inputSize + ) + ) { "Friend image upload failed: cannot access api" } + logger.verbose("friend image uploaded") it.imageId } is FriendImageAlreadyExists -> it.imageId