From: David ‘Bombe’ Roden Date: Sun, 23 Apr 2017 14:13:54 +0000 (+0200) Subject: Include a type tag in the linked element’s properties X-Git-Tag: 0.9.7^2~241 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=992404e5183f824e478d6f2273d7998d48ceeea5;p=Sone.git Include a type tag in the linked element’s properties --- diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index ebdae49..3c0e77c 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -39,7 +39,7 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke 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)) } } } @@ -47,7 +47,7 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke 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) )) diff --git a/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt index d31900d..776d0c9 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt @@ -104,7 +104,9 @@ class DefaultElementLoaderTest { 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 @@ -114,6 +116,7 @@ class DefaultElementLoaderTest { 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", @@ -128,6 +131,7 @@ class DefaultElementLoaderTest { 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", @@ -142,6 +146,7 @@ class DefaultElementLoaderTest { 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", @@ -156,6 +161,7 @@ class DefaultElementLoaderTest { 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,