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 LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface) {
19 override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
20 if ("album" in freenetRequest.parameters) {
21 templateContext["albumRequested"] = true
22 templateContext["album"] = webInterface.core.getAlbum(freenetRequest.parameters["album"]!!)
23 templateContext["page"] = freenetRequest.parameters["page"]
24 } else if ("image" in freenetRequest.parameters) {
25 templateContext["imageRequested"] = true
26 templateContext["image"] = webInterface.core.getImage(freenetRequest.parameters["image"])
27 } else if (freenetRequest.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 = freenetRequest.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(freenetRequest.httpRequest.getParam("sone")) ?: currentSone
47 override fun isLinkExcepted(link: URI?) = true