X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FDefaultElementLoader.kt;h=d01aeb448284ef9d94b0a8b85eba0ed4a90dda9f;hp=ebdae49b4b9c22d57b455c96f0bc15ff4c36157e;hb=c28013c8a4bcb9776a1e2d82ffd6c4c8297ffb62;hpb=27a0934b7e68315756020e0de0bc2564355be90a diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index ebdae49..d01aeb4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -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) ))