diff --git a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt index 6b6aac805..9ea0a8623 100644 --- a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt +++ b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt @@ -971,15 +971,16 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { val http = Mirai.Http val origin = resp.origin - val data = if (origin.msgExternInfo?.channelType == 2) { + val data: ByteArray = if (origin.msgExternInfo?.channelType == 2) { tryDownload( bot = bot, host = "https://ssl.htdata.qq.com", - port = 0, + port = 443, + times = 3, resourceKind = ResourceKind.LONG_MESSAGE, channelKind = ChannelKind.HTTP - ) { host, port -> - http.get("$host:$port${origin.thumbDownPara}") + ) { host, _ -> + http.get("$host${origin.thumbDownPara}") } } else tryServersDownload( bot = bot, diff --git a/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt b/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt index 68144652d..0b4078e57 100644 --- a/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt +++ b/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt @@ -159,21 +159,23 @@ internal suspend inline fun tryServersDownload( 5000, onFail = { throw IllegalStateException("cannot download $resourceKind, failed on all servers.", it) } ) { ip, port -> - tryUploadImplEach(bot, channelKind, resourceKind, ip, port, implOnEachServer) + tryDownloadImplEach(bot, channelKind, resourceKind, ip, port, implOnEachServer) } internal suspend inline fun tryDownload( bot: QQAndroidBot, host: String, port: Int, + times: Int = 1, resourceKind: ResourceKind, channelKind: ChannelKind, crossinline implOnEachServer: suspend (ip: String, port: Int) -> R -) = runCatching { - tryUploadImplEach(bot, channelKind, resourceKind, host, port, implOnEachServer) -}.getOrElse { throw IllegalStateException("cannot upload $resourceKind, failed on all servers.", it) } +) = retryCatching(times) { + tryDownloadImplEach(bot, channelKind, resourceKind, host, port, implOnEachServer) +}.getOrElse { throw IllegalStateException("Cannot download $resourceKind", it) } -private suspend inline fun tryUploadImplEach( + +private suspend inline fun tryDownloadImplEach( bot: QQAndroidBot, channelKind: ChannelKind, resourceKind: ResourceKind, @@ -182,7 +184,7 @@ private suspend inline fun tryUploadImplEach( crossinline implOnEachServer: suspend (ip: String, port: Int) -> R ): R { bot.network.logger.verbose { - "[${channelKind}] Downloading $resourceKind to ${host}:$port" + "[${channelKind}] Downloading $resourceKind from ${host}:$port" } var resp: R? = null @@ -190,7 +192,7 @@ private suspend inline fun tryUploadImplEach( resp = implOnEachServer(host, port) }.onFailure { bot.network.logger.verbose { - "[${channelKind}] Downloading $resourceKind to ${host}:$port failed: $it" + "[${channelKind}] Downloading $resourceKind from ${host}:$port failed: $it" } throw it }