Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: ImageType.JPEG #1862

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4543,6 +4543,7 @@ public final class net/mamoe/mirai/message/data/ImageType : java/lang/Enum {
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;
Expand Down
1 change: 1 addition & 0 deletions mirai-core-api/compatibility-validation/jvm/api/jvm.api
Original file line number Diff line number Diff line change
Expand Up @@ -4543,6 +4543,7 @@ public final class net/mamoe/mirai/message/data/ImageType : java/lang/Enum {
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;
Expand Down
5 changes: 3 additions & 2 deletions mirai-core-api/src/commonMain/kotlin/message/data/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,11 @@ 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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议这里用小写,可以修改匹配的代码来支持

GIF("gif"),
//WEBP, //Unsupported by pc client
APNG("png"),
Expand All @@ -391,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) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secondaryNames里全是小写,但input被uppercase处理了,会匹配不到任何信息

另外,建议在getByExt(大意)之类的地方改

}
}
}
Expand Down