package net.pterodactylus.sone.core
import com.google.common.base.Ticker
+import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import freenet.keys.FreenetURI
import java.io.ByteArrayInputStream
@Inject constructor(freenetInterface: FreenetInterface) : this(freenetInterface, Ticker.systemTicker())
- private val loadingLinks = CacheBuilder.newBuilder().build<String, Boolean>()
- private val failureCache = CacheBuilder.newBuilder().ticker(ticker).expireAfterWrite(30, MINUTES).build<String, Boolean>()
- private val imageCache = CacheBuilder.newBuilder().build<String, LinkedElement>()
+ private val loadingLinks: Cache<String, Boolean> = CacheBuilder.newBuilder().build<String, Boolean>()
+ private val failureCache: Cache<String, Boolean> = CacheBuilder.newBuilder().ticker(ticker).expireAfterWrite(30, MINUTES).build<String, Boolean>()
+ private val imageCache: Cache<String, LinkedElement> = CacheBuilder.newBuilder().build<String, LinkedElement>()
private val callback = object : FreenetInterface.BackgroundFetchCallback {
override fun shouldCancel(uri: FreenetURI, mimeType: String, size: Long): Boolean {
return !mimeType.startsWith("image/") || (size > 2097152)
return LinkedElement(link, loading = true)
}
- private fun String.decode() = URLDecoder.decode(this, "UTF-8")
- private fun String.normalize() = Normalizer.normalize(this, Normalizer.Form.NFC)
+ private fun String.decode() = URLDecoder.decode(this, "UTF-8")!!
+ private fun String.normalize() = Normalizer.normalize(this, Normalizer.Form.NFC)!!
}
private val freenetURI = FreenetURI(IMAGE_ID)
private const val decomposedKey = "CHK@DCiVgTWW9nnWHJc9EVwtFJ6jAfBSVyy~rgiPvhUKbS4,mNY85V0x7dYcv7SnEYo1PCC6y2wNWMDNt-y9UWQx9fI,AAMC--8/fru%CC%88hstu%CC%88ck.jpg"
private const val normalizedKey = "CHK@DCiVgTWW9nnWHJc9EVwtFJ6jAfBSVyy~rgiPvhUKbS4,mNY85V0x7dYcv7SnEYo1PCC6y2wNWMDNt-y9UWQx9fI,AAMC--8/frühstück.jpg"
- private val sizeOkay = 2097152L;
- private val sizeNotOkay = sizeOkay + 1;
+ private val sizeOkay = 2097152L
+ private val sizeNotOkay = sizeOkay + 1
}
private val freenetInterface = mock<FreenetInterface>()