From 0a5d3097f7d5d2942da10c5b8738b6c4f4da6b60 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 13 Dec 2020 11:39:54 +0800 Subject: [PATCH] Correct format name of GroupImage --- .../src/commonMain/kotlin/utils/ExternalImage.kt | 7 ++++--- mirai-core/src/commonMain/kotlin/message/imagesImpl.kt | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mirai-core-api/src/commonMain/kotlin/utils/ExternalImage.kt b/mirai-core-api/src/commonMain/kotlin/utils/ExternalImage.kt index cf0e708b1..a0fcb1646 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/ExternalImage.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/ExternalImage.kt @@ -73,8 +73,9 @@ public class ExternalImage internal constructor( } @MiraiExperimentalApi - public fun generateImageId(md5: ByteArray): String { - return """{${generateUUID(md5)}}.$defaultFormatName""" + @JvmOverloads + public fun generateImageId(md5: ByteArray, format: String = defaultFormatName): String { + return """{${generateUUID(md5)}}.$format""" } } @@ -87,7 +88,7 @@ public class ExternalImage internal constructor( return "ExternalImage(${generateUUID(md5)})" } - internal fun calculateImageResourceId(): String = """{${generateUUID(md5)}}.$formatName""" + internal fun calculateImageResourceId(): String = generateImageId(md5, formatName) private fun String.detectFormatName(): String = when { startsWith("FFD8") -> "jpg" diff --git a/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt b/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt index 8f5ae165f..8d18a6544 100644 --- a/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt +++ b/mirai-core/src/commonMain/kotlin/message/imagesImpl.kt @@ -32,7 +32,10 @@ internal class OnlineGroupImageImpl( internal val delegate: ImMsgBody.CustomFace ) : @Suppress("DEPRECATION") OnlineGroupImage() { - override val imageId: String = delegate.filePath.takeIf { + override val imageId: String = ExternalImage.generateImageId( + delegate.md5, + delegate.filePath.substringAfterLast('.') + ).takeIf { GROUP_IMAGE_ID_REGEX.matches(it) } ?: ExternalImage.generateImageId(delegate.md5)