mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 08:50:15 +08:00
[mock] Fix image multi-uploading; fix #2401
This commit is contained in:
parent
60dd4b5be6
commit
c957d008fb
@ -68,7 +68,20 @@ internal class TmpResourceServerImpl(
|
||||
override suspend fun uploadResourceAsImage(resource: ExternalResource): URI {
|
||||
val imgId = generateUUID(resource.md5)
|
||||
val resId = uploadResource(resource)
|
||||
images.resolve(imgId).createLinkPointingTo(storage.resolve(resId))
|
||||
|
||||
val imgPath = images.resolve(imgId)
|
||||
val storagePath = storage.resolve(resId).toAbsolutePath()
|
||||
|
||||
if (imgPath.exists()) {
|
||||
return resolveImageUrl(imgId)
|
||||
}
|
||||
|
||||
kotlin.runCatching {
|
||||
imgPath.createLinkPointingTo(storagePath)
|
||||
}.recoverCatchingSuppressed {
|
||||
imgPath.createSymbolicLinkPointingTo(storagePath)
|
||||
}.getOrThrow()
|
||||
|
||||
return resolveImageUrl(imgId)
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.net.URL
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
|
||||
@ -44,4 +45,13 @@ internal class ImageUploadTest {
|
||||
data.contentEquals(URL(img.queryUrl()).readBytes())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSameImageMultiUpload() = runBlocking<Unit> {
|
||||
Image.randomImageContent().toExternalResource().use { imgData ->
|
||||
val img1 = bot.asFriend.uploadImage(imgData)
|
||||
val img2 = bot.asFriend.uploadImage(imgData)
|
||||
assertEquals(img1, img2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user