X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FDefaultElementLoader.kt;h=67d55387a510e7ad3715f138df93b6d9ec8bd16e;hp=5758c473e37552cf6cf35fd5ba8b8f1a97bd791d;hb=5a1d1f95e7d122752a405bf1730e67cafb0df177;hpb=7bb75fc81cd59d728fbc076a0d7356e43720c92a diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index 5758c47..67d5538 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -33,11 +33,20 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke 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)