From ace32caa282352befdc4c321437563d2d0dd6b6f Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 16 Oct 2021 16:52:06 +0800 Subject: [PATCH] Fix cross images downloading url; fix #1600 --- .../src/commonMain/kotlin/message/imagesImpl.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt b/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt index 49a327e1d..5b29e9665 100644 --- a/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt +++ b/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt @@ -58,10 +58,7 @@ internal class OnlineGroupImageImpl( override val originUrl: String get() = if (delegate.origUrl.isBlank()) { - "http://gchat.qpic.cn/gchatpic_new/0/0-0-${ - imageId.substring(1..36) - .replace("-", "") - }/0?term=2" + gchatImageUrlByImageId(imageId) } else "http://gchat.qpic.cn" + delegate.origUrl override val isEmoji: Boolean by lazy { @@ -78,6 +75,13 @@ private fun ByteArray.pbImageResv_checkIsEmoji(seri }.getOrNull() ?: false } +private fun gchatImageUrlByImageId(imageId: String) = + "http://gchat.qpic.cn/gchatpic_new/0/0-0-${ + imageId.substring(1..36) + .replace("-", "") + }/0?term=2" + + private val imageLogger: MiraiLogger by lazy { MiraiLogger.Factory.create(Image::class) } internal val Image.Key.logger get() = imageLogger @@ -117,6 +121,9 @@ OnlineFriendImage() { override val originUrl: String get() = if (delegate.origUrl.isNotBlank()) { "http://c2cpicdw.qpic.cn" + this.delegate.origUrl + } else if (delegate.resId.isNotEmpty() && delegate.resId[0] == '{') { + // https://github.com/mamoe/mirai/issues/1600 + gchatImageUrlByImageId(imageId) } else { "http://c2cpicdw.qpic.cn/offpic_new/0/" + delegate.resId + "/0?term=2" }