mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 03:22:36 +08:00
[core] 修复从可确定图片类型的字符串组成的 mirai code 构造的图片 type 为 UNKNOW 或与期望类型不一致 (#2761)
* [core]修复从可确定图片类型的字符串组成的mirai code构造的图片type为UNKNOW或与期望类型不一致 * [core]修复从可确定图片类型的字符串组成的mirai code构造的图片type为UNKNOW或与期望类型不一致 * [core]修复从可确定图片类型的字符串组成的mirai code构造的图片type为UNKNOW或与期望类型不一致 * Update mirai-core-api/src/commonMain/kotlin/message/data/Image.kt --------- Co-authored-by: Him188 <Him188@mamoe.net>
This commit is contained in:
parent
0aad162cad
commit
e61b058153
@ -306,7 +306,6 @@ public interface Image : Message, MessageContent, CodableMessage {
|
||||
* @see Image.imageType
|
||||
*/
|
||||
public var type: ImageType = ImageType.UNKNOWN
|
||||
|
||||
/**
|
||||
* @see Image.width
|
||||
*/
|
||||
@ -324,6 +323,9 @@ public interface Image : Message, MessageContent, CodableMessage {
|
||||
|
||||
|
||||
public fun build(): Image {
|
||||
if (type == ImageType.UNKNOWN) {
|
||||
type = ImageType.match(imageId.split(".").last())
|
||||
}
|
||||
@OptIn(MiraiInternalApi::class)
|
||||
return InternalImageProtocol.instance.createImage(
|
||||
imageId = imageId,
|
||||
|
@ -19,6 +19,10 @@ import kotlin.test.assertEquals
|
||||
internal class ImageBuilderTest : AbstractTest() {
|
||||
companion object {
|
||||
private const val IMAGE_ID = "{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.jpg"
|
||||
private const val IMAGE_ID_PNG = "{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.png"
|
||||
private const val IMAGE_ID_BMP = "{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.bmp"
|
||||
private const val IMAGE_ID_GIF = "{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.gif"
|
||||
private const val IMAGE_ID_UNKNOW = "/01E9451B-70ED-EAE3-B37C-101F1EEBF5B5"
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -57,6 +61,50 @@ internal class ImageBuilderTest : AbstractTest() {
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.JPG, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun imageType() {
|
||||
Image(IMAGE_ID).run {
|
||||
assertEquals(IMAGE_ID, imageId)
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.JPG, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
Image(IMAGE_ID_PNG).run {
|
||||
assertEquals(IMAGE_ID_PNG, imageId)
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.PNG, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
Image(IMAGE_ID_BMP).run {
|
||||
assertEquals(IMAGE_ID_BMP, imageId)
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.BMP, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
Image(IMAGE_ID_GIF).run {
|
||||
assertEquals(IMAGE_ID_GIF, imageId)
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.GIF, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
Image(IMAGE_ID_UNKNOW).run {
|
||||
assertEquals(IMAGE_ID_UNKNOW, imageId)
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.UNKNOWN, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
@ -71,7 +119,7 @@ internal class ImageBuilderTest : AbstractTest() {
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.UNKNOWN, imageType)
|
||||
assertEquals(ImageType.JPG, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
Image.fromId(IMAGE_ID).run {
|
||||
@ -79,7 +127,7 @@ internal class ImageBuilderTest : AbstractTest() {
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.UNKNOWN, imageType)
|
||||
assertEquals(ImageType.JPG, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
Image(IMAGE_ID).run {
|
||||
@ -87,7 +135,7 @@ internal class ImageBuilderTest : AbstractTest() {
|
||||
assertEquals(0, width)
|
||||
assertEquals(0, height)
|
||||
assertEquals(0, size)
|
||||
assertEquals(ImageType.UNKNOWN, imageType)
|
||||
assertEquals(ImageType.JPG, imageType)
|
||||
assertEquals(false, isEmoji)
|
||||
}
|
||||
Image(IMAGE_ID) {
|
||||
|
@ -76,7 +76,7 @@ internal class LongMessageProtocolTest : AbstractMessageProtocolTest() {
|
||||
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
|
||||
<msg serviceID="35" templateID="1" action="viewMultiMsg"
|
||||
brief="testqGnJ1R..."
|
||||
m_resid="(size=1)DBD2AB20196EEB631C95DEF40E20C709"
|
||||
m_resid="(size=1)6C6FD4AEC362AA8E54058A27B422FA42"
|
||||
m_fileName="160023" sourceMsgId="0" url=""
|
||||
flag="3" adverSign="0" multiMsgFlag="1">
|
||||
<item layout="1">
|
||||
@ -86,7 +86,7 @@ internal class LongMessageProtocolTest : AbstractMessageProtocolTest() {
|
||||
</item>
|
||||
<source name="聊天记录" icon="" action="" appid="-1"/>
|
||||
</msg>
|
||||
""".trimIndent(), "(size=1)DBD2AB20196EEB631C95DEF40E20C709"
|
||||
""".trimIndent(), "(size=1)6C6FD4AEC362AA8E54058A27B422FA42"
|
||||
) + IgnoreLengthCheck + ForceAsLongMessage, context.currentMessageChain
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user