♻️ Copy session-handling code to FreenetRequest
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / core / DefaultElementLoader.kt
index ebdae49..d01aeb4 100644 (file)
@@ -31,15 +31,15 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke
                        return (size > 2097152) || (!mimeType.startsWith("image/") && !mimeType.startsWith("text/html"))
                }
 
-               override fun loaded(uri: FreenetURI, mimeType: String, data: ByteArray) {
-                       MimeType(mimeType).also { mimeType ->
+               override fun loaded(uri: FreenetURI, mimeTypeText: String, data: ByteArray) {
+                       MimeType(mimeTypeText).also { mimeType ->
                                when {
                                        mimeType.primaryType == "image" -> {
                                                ByteArrayInputStream(data).use {
                                                        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)
                                                        ))