From 64f70439065bc9c8ee7eaba3d36a6a093cd8feef Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sun, 30 Jan 2022 20:19:09 +0800 Subject: [PATCH 1/5] add: ImageType.JPEG --- mirai-core-api/src/commonMain/kotlin/message/data/Image.kt | 1 + mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt index d8c460a4eff..e749733b1ec 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt @@ -378,6 +378,7 @@ public enum class ImageType( GIF("gif"), //WEBP, //Unsupported by pc client APNG("png"), + JPEG("jpg"), UNKNOWN("gif"); // bad design, should use `null` to represent unknown, but we cannot change it anymore. public companion object { diff --git a/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt b/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt index 51381515382..c6b6f130a12 100644 --- a/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt +++ b/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt @@ -152,7 +152,7 @@ internal fun ExternalResource.calculateImageInfo(): ImageInfo { val imageType = ImageType.match(formatName) return inputStream().asInput().withUse { when (imageType) { - ImageType.JPG -> getJPGImageInfo() + ImageType.JPG, ImageType.JPEG -> getJPGImageInfo() ImageType.BMP -> getBMPImageInfo() ImageType.GIF -> getGIFImageInfo() ImageType.PNG, ImageType.APNG -> getPNGImageInfo() From d8def8e6623611126b128a13db4a1e754e96cab8 Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sun, 30 Jan 2022 21:09:59 +0800 Subject: [PATCH 2/5] add: api dump --- mirai-core-api/compatibility-validation/android/api/android.api | 1 + mirai-core-api/compatibility-validation/jvm/api/jvm.api | 1 + 2 files changed, 2 insertions(+) diff --git a/mirai-core-api/compatibility-validation/android/api/android.api b/mirai-core-api/compatibility-validation/android/api/android.api index a8342399e94..200584def88 100644 --- a/mirai-core-api/compatibility-validation/android/api/android.api +++ b/mirai-core-api/compatibility-validation/android/api/android.api @@ -4539,6 +4539,7 @@ public final class net/mamoe/mirai/message/data/ImageType : java/lang/Enum { public static final field BMP Lnet/mamoe/mirai/message/data/ImageType; public static final field Companion Lnet/mamoe/mirai/message/data/ImageType$Companion; public static final field GIF Lnet/mamoe/mirai/message/data/ImageType; + public static final field JPEG Lnet/mamoe/mirai/message/data/ImageType; public static final field JPG Lnet/mamoe/mirai/message/data/ImageType; public static final field PNG Lnet/mamoe/mirai/message/data/ImageType; public static final field UNKNOWN Lnet/mamoe/mirai/message/data/ImageType; diff --git a/mirai-core-api/compatibility-validation/jvm/api/jvm.api b/mirai-core-api/compatibility-validation/jvm/api/jvm.api index e1605441d65..a215b09bdf6 100644 --- a/mirai-core-api/compatibility-validation/jvm/api/jvm.api +++ b/mirai-core-api/compatibility-validation/jvm/api/jvm.api @@ -4539,6 +4539,7 @@ public final class net/mamoe/mirai/message/data/ImageType : java/lang/Enum { public static final field BMP Lnet/mamoe/mirai/message/data/ImageType; public static final field Companion Lnet/mamoe/mirai/message/data/ImageType$Companion; public static final field GIF Lnet/mamoe/mirai/message/data/ImageType; + public static final field JPEG Lnet/mamoe/mirai/message/data/ImageType; public static final field JPG Lnet/mamoe/mirai/message/data/ImageType; public static final field PNG Lnet/mamoe/mirai/message/data/ImageType; public static final field UNKNOWN Lnet/mamoe/mirai/message/data/ImageType; From e6cdc81c7d1317917d9830f63dbe4763aa4e0c32 Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sat, 19 Feb 2022 22:43:36 +0800 Subject: [PATCH 3/5] add: secondaryNames --- .../compatibility-validation/android/api/android.api | 2 +- mirai-core-api/compatibility-validation/jvm/api/jvm.api | 2 +- mirai-core-api/src/commonMain/kotlin/message/data/Image.kt | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mirai-core-api/compatibility-validation/android/api/android.api b/mirai-core-api/compatibility-validation/android/api/android.api index 200584def88..39207c8b634 100644 --- a/mirai-core-api/compatibility-validation/android/api/android.api +++ b/mirai-core-api/compatibility-validation/android/api/android.api @@ -4539,11 +4539,11 @@ public final class net/mamoe/mirai/message/data/ImageType : java/lang/Enum { public static final field BMP Lnet/mamoe/mirai/message/data/ImageType; public static final field Companion Lnet/mamoe/mirai/message/data/ImageType$Companion; public static final field GIF Lnet/mamoe/mirai/message/data/ImageType; - public static final field JPEG Lnet/mamoe/mirai/message/data/ImageType; public static final field JPG Lnet/mamoe/mirai/message/data/ImageType; public static final field PNG Lnet/mamoe/mirai/message/data/ImageType; public static final field UNKNOWN Lnet/mamoe/mirai/message/data/ImageType; public final fun getFormatName ()Ljava/lang/String; + public final fun getSecondaryNames ()[Ljava/lang/String; public static final fun match (Ljava/lang/String;)Lnet/mamoe/mirai/message/data/ImageType; public static final fun matchOrNull (Ljava/lang/String;)Lnet/mamoe/mirai/message/data/ImageType; public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/message/data/ImageType; diff --git a/mirai-core-api/compatibility-validation/jvm/api/jvm.api b/mirai-core-api/compatibility-validation/jvm/api/jvm.api index a215b09bdf6..fc4ffe3421c 100644 --- a/mirai-core-api/compatibility-validation/jvm/api/jvm.api +++ b/mirai-core-api/compatibility-validation/jvm/api/jvm.api @@ -4539,11 +4539,11 @@ public final class net/mamoe/mirai/message/data/ImageType : java/lang/Enum { public static final field BMP Lnet/mamoe/mirai/message/data/ImageType; public static final field Companion Lnet/mamoe/mirai/message/data/ImageType$Companion; public static final field GIF Lnet/mamoe/mirai/message/data/ImageType; - public static final field JPEG Lnet/mamoe/mirai/message/data/ImageType; public static final field JPG Lnet/mamoe/mirai/message/data/ImageType; public static final field PNG Lnet/mamoe/mirai/message/data/ImageType; public static final field UNKNOWN Lnet/mamoe/mirai/message/data/ImageType; public final fun getFormatName ()Ljava/lang/String; + public final fun getSecondaryNames ()[Ljava/lang/String; public static final fun match (Ljava/lang/String;)Lnet/mamoe/mirai/message/data/ImageType; public static final fun matchOrNull (Ljava/lang/String;)Lnet/mamoe/mirai/message/data/ImageType; public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/message/data/ImageType; diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt index e749733b1ec..c25ed1a1f3d 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt @@ -371,14 +371,14 @@ public enum class ImageType( * @since 2.9.0 */ @MiraiInternalApi public val formatName: String, + @MiraiInternalApi public vararg val secondaryNames: String ) { PNG("png"), BMP("bmp"), - JPG("jpg"), + JPG("jpg", "jpeg", "jpe"), GIF("gif"), //WEBP, //Unsupported by pc client APNG("png"), - JPEG("jpg"), UNKNOWN("gif"); // bad design, should use `null` to represent unknown, but we cannot change it anymore. public companion object { @@ -392,7 +392,7 @@ public enum class ImageType( @JvmStatic public fun matchOrNull(str: String): ImageType? { val input = str.uppercase() - return IMAGE_TYPE_ENUM_LIST.firstOrNull { it.name == input } + return IMAGE_TYPE_ENUM_LIST.firstOrNull { it.name == input || it.secondaryNames.contains(input) } } } } From 19bd14dfc6999dbd13114a78b451d138f7781c6c Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sat, 19 Feb 2022 22:45:38 +0800 Subject: [PATCH 4/5] add: secondaryNames --- mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt b/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt index c6b6f130a12..51381515382 100644 --- a/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt +++ b/mirai-core/src/commonMain/kotlin/message/ImageDecoder.kt @@ -152,7 +152,7 @@ internal fun ExternalResource.calculateImageInfo(): ImageInfo { val imageType = ImageType.match(formatName) return inputStream().asInput().withUse { when (imageType) { - ImageType.JPG, ImageType.JPEG -> getJPGImageInfo() + ImageType.JPG -> getJPGImageInfo() ImageType.BMP -> getBMPImageInfo() ImageType.GIF -> getGIFImageInfo() ImageType.PNG, ImageType.APNG -> getPNGImageInfo() From 8d3bd2fdada4ee580fe78be54bf75feb0efc9aa2 Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sat, 19 Feb 2022 23:08:10 +0800 Subject: [PATCH 5/5] fix: uppercase --- mirai-core-api/src/commonMain/kotlin/message/data/Image.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt index c25ed1a1f3d..f39a3362356 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt @@ -375,7 +375,7 @@ public enum class ImageType( ) { PNG("png"), BMP("bmp"), - JPG("jpg", "jpeg", "jpe"), + JPG("jpg", "JPEG", "JPE"), GIF("gif"), //WEBP, //Unsupported by pc client APNG("png"),