X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FDefaultElementLoader.kt;h=eb90b34da018830f939f7e0615fabc038496afc1;hb=d50730f6a330439e0e7ef97ca9329dffe72d5640;hp=409d18c6f2004c1d698ea60913fa07ef4fc79001;hpb=fefcf90b0f97e09540dfcc957974840c21306f06;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index 409d18c..eb90b34 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -28,6 +28,13 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke private val elementCache: Cache = CacheBuilder.newBuilder().build() private val callback = object: FreenetInterface.BackgroundFetchCallback { override fun shouldCancel(uri: FreenetURI, mimeType: String, size: Long): Boolean { + if (mimeType.startsWith("audio/")) { + elementCache.get(uri.toString().decode().normalize()) { + LinkedElement(uri.toString(), properties = mapOf( + "type" to "audio", "size" to size, "sizeHuman" to size.human + )) + } + } return (size > 2097152) || (!mimeType.startsWith("image/") && !mimeType.startsWith("text/html")) } @@ -74,13 +81,15 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke .firstOrNull { !it.first.tagName().startsWith("h", ignoreCase = true) } ?.second - private val Int.human get() = when (this) { + private val Long.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" } + private val Int.human get() = toLong().human + override fun failed(uri: FreenetURI) { failureCache.put(uri.toString().decode().normalize(), true) removeLoadingLink(uri)