mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-08 22:32:34 +08:00
Fix calculateImageMd5ByImageId
This commit is contained in:
parent
c8e20800a0
commit
bf4b56ab07
@ -360,12 +360,11 @@ internal fun String.imageIdToMd5(offset: Int): ByteArray {
|
|||||||
internal fun calculateImageMd5ByImageId(imageId: String): ByteArray {
|
internal fun calculateImageMd5ByImageId(imageId: String): ByteArray {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
return when {
|
return when {
|
||||||
imageId.matches(FRIEND_IMAGE_ID_REGEX_1) -> imageId.imageIdToMd5(imageId.skipToSecondHyphen() + 1)
|
imageId matches FRIEND_IMAGE_ID_REGEX_2 -> imageId.imageIdToMd5(imageId.skipToSecondHyphen() + 1)
|
||||||
imageId.matches(FRIEND_IMAGE_ID_REGEX_2) ->
|
imageId matches FRIEND_IMAGE_ID_REGEX_1 -> imageId.imageIdToMd5(1)
|
||||||
imageId.imageIdToMd5(1)
|
imageId matches GROUP_IMAGE_ID_REGEX -> imageId.imageIdToMd5(1)
|
||||||
imageId.matches(GROUP_IMAGE_ID_REGEX) || imageId.matches(GROUP_IMAGE_ID_REGEX_OLD) -> {
|
imageId matches GROUP_IMAGE_ID_REGEX_OLD -> imageId.imageIdToMd5(1)
|
||||||
imageId.imageIdToMd5(1)
|
|
||||||
}
|
|
||||||
else -> error(
|
else -> error(
|
||||||
"illegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE"
|
"illegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE"
|
||||||
)
|
)
|
||||||
|
@ -36,7 +36,12 @@ internal class ImageTest {
|
|||||||
fun testCalculateImageMd5ByImageId() {
|
fun testCalculateImageMd5ByImageId() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"01E9451B-70ED-EAE3-B37C-101F1EEBF5B5".filterNot { it == '-' }.autoHexToBytes().contentToString(),
|
"01E9451B-70ED-EAE3-B37C-101F1EEBF5B5".filterNot { it == '-' }.autoHexToBytes().contentToString(),
|
||||||
calculateImageMd5ByImageId("{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.png").contentToString()
|
calculateImageMd5ByImageId("{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai").contentToString()
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"01E9451B-70ED-EAE3-B37C-101F1EEBF5B5".filterNot { it == '-' }.autoHexToBytes().contentToString(),
|
||||||
|
calculateImageMd5ByImageId("{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.gif").contentToString()
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
Loading…
Reference in New Issue
Block a user