Fix calculateImageMd5ByImageId

This commit is contained in:
Him188 2020-04-24 16:55:39 +08:00
parent c8e20800a0
commit bf4b56ab07
2 changed files with 11 additions and 7 deletions

View File

@ -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"
) )

View File

@ -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(