1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Album
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.utils.Pagination
6 import net.pterodactylus.sone.utils.parameters
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.FreenetRequest
9 import net.pterodactylus.util.template.Template
10 import net.pterodactylus.util.template.TemplateContext
14 * The image browser page is the entry page for the image management.
16 class ImageBrowserPage(template: Template, webInterface: WebInterface):
17 SoneTemplatePage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true) {
19 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
20 if ("album" in request.parameters) {
21 templateContext["albumRequested"] = true
22 templateContext["album"] = webInterface.core.getAlbum(request.parameters["album"]!!)
23 templateContext["page"] = request.parameters["page"]
24 } else if ("image" in request.parameters) {
25 templateContext["imageRequested"] = true
26 templateContext["image"] = webInterface.core.getImage(request.parameters["image"])
27 } else if (request.parameters["mode"] == "gallery") {
28 templateContext["galleryRequested"] = true
29 webInterface.core.sones
30 .map(Sone::getRootAlbum)
31 .flatMap(Album::getAlbums)
32 .flatMap { Album.FLATTENER.apply(it)!! }
33 .filterNot(Album::isEmpty)
34 .sortedBy(Album::getTitle)
36 Pagination(albums, webInterface.core.preferences.imagesPerPage).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }.also { pagination ->
37 templateContext["albumPagination"] = pagination
38 templateContext["albums"] = pagination.items
42 templateContext["soneRequested"] = true
43 templateContext["sone"] = webInterface.core.getSone(request.httpRequest.getParam("sone")).orNull() ?: getCurrentSone(request.toadletContext)
47 override fun isLinkExcepted(link: URI?) = true