Include a type tag in the linked element’s properties
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 23 Apr 2017 14:13:54 +0000 (16:13 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 23 Apr 2017 14:13:54 +0000 (16:13 +0200)
src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt
src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt

index ebdae49..3c0e77c 100644 (file)
@@ -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)
                                                        ))
index d31900d..776d0c9 100644 (file)
@@ -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,