ByteArrayInputStream(data).use {
ImageIO.read(it)
}?.let {
- imageCache.get(uri.toString().decode().normalize()) { LinkedElement(uri.toString()) }
+ imageCache.get(uri.toString().decode().normalize()) {
+ LinkedElement(uri.toString(), properties = mapOf("size" to data.size, "sizeHuman" to data.size.human))
+ }
}
removeLoadingLink(uri)
}
+ private val Int.human get() = when (this) {
+ in 0..1023 -> "$this B"
+ in 1024..1048575 -> "${this / 1024} KiB"
+ in 1048576..1073741823 -> "${this / 1048576} MiB"
+ else -> "${this / 1073741824} GiB"
+ }
+
override fun failed(uri: FreenetURI) {
failureCache.put(uri.toString().decode().normalize(), true)
removeLoadingLink(uri)
}
-data class LinkedElement(val link: String, val failed: Boolean = false, val loading: Boolean = false)
+data class LinkedElement(val link: String, val failed: Boolean = false, val loading: Boolean = false, val properties: Map<String, Any?> = emptyMap())
verify(freenetInterface).startFetch(eq(FreenetURI(decomposedKey)), callback.capture())
callback.value.loaded(FreenetURI(normalizedKey), "image/png", read("/static/images/unknown-image-0.png"))
val linkedElement = elementLoader.loadElement(decomposedKey)
- assertThat(linkedElement, `is`(LinkedElement(normalizedKey)))
+ assertThat(linkedElement, `is`(LinkedElement(normalizedKey, properties = mapOf("size" to 2451, "sizeHuman" to "2 KiB"))))
}
@Test