private val elementCache: Cache<String, LinkedElement> = 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"))
}
.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)