ImageIO.read(it)
}?.let {
elementCache.get(uri.toString().decode().normalize()) {
- LinkedElement(uri.toString(), properties = mapOf("size" to data.size, "sizeHuman" to data.size.human))
+ LinkedElement(uri.toString(), properties = mapOf("type" to "image", "size" to data.size, "sizeHuman" to data.size.human))
}
}
}
val document = Jsoup.parse(data.toString(Charset.forName(mimeType.getParameter("charset") ?: "UTF-8")))
elementCache.get(uri.toString().decode().normalize()) {
LinkedElement(uri.toString(), properties = mapOf(
- "size" to data.size, "sizeHuman" to data.size.human,
+ "type" to "html", "size" to data.size, "sizeHuman" to data.size.human,
"title" to document.title().emptyToNull,
"description" to (document.metaDescription ?: document.firstNonHeadingParagraph)
))
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, properties = mapOf("size" to 2451, "sizeHuman" to "2 KiB"))))
+ assertThat(linkedElement, `is`(LinkedElement(normalizedKey, properties = mapOf(
+ "type" to "image", "size" to 2451, "sizeHuman" to "2 KiB"
+ ))))
}
@Test
callback.value.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader.html"))
val linkedElement = elementLoader.loadElement(textKey)
assertThat(linkedElement, equalTo(LinkedElement(textKey, properties = mapOf(
+ "type" to "html",
"size" to 266,
"sizeHuman" to "266 B",
"title" to "Some Nice Page Title",
callback.value.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader2.html"))
val linkedElement = elementLoader.loadElement(textKey)
assertThat(linkedElement, equalTo(LinkedElement(textKey, properties = mapOf(
+ "type" to "html",
"size" to 185,
"sizeHuman" to "185 B",
"title" to "Some Nice Page Title",
callback.value.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader3.html"))
val linkedElement = elementLoader.loadElement(textKey)
assertThat(linkedElement, equalTo(LinkedElement(textKey, properties = mapOf(
+ "type" to "html",
"size" to 204,
"sizeHuman" to "204 B",
"title" to "Some Nice Page Title",
callback.value.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader4.html"))
val linkedElement = elementLoader.loadElement(textKey)
assertThat(linkedElement, equalTo(LinkedElement(textKey, properties = mapOf(
+ "type" to "html",
"size" to 229,
"sizeHuman" to "229 B",
"title" to null,