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.paginate
6 import net.pterodactylus.sone.utils.parameters
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.template.Template
10 import net.pterodactylus.util.template.TemplateContext
12 import javax.inject.Inject
15 * The image browser page is the entry page for the image management.
17 class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface):
18 LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface) {
20 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
21 if ("album" in soneRequest.parameters) {
22 templateContext["albumRequested"] = true
23 templateContext["album"] = soneRequest.core.getAlbum(soneRequest.parameters["album"]!!)
24 templateContext["page"] = soneRequest.parameters["page"]
25 } else if ("image" in soneRequest.parameters) {
26 templateContext["imageRequested"] = true
27 templateContext["image"] = soneRequest.core.getImage(soneRequest.parameters["image"])
28 } else if (soneRequest.parameters["mode"] == "gallery") {
29 templateContext["galleryRequested"] = true
30 soneRequest.core.sones
31 .map(Sone::getRootAlbum)
32 .flatMap(Album::getAlbums)
33 .flatMap { Album.FLATTENER.apply(it)!! }
34 .filterNot(Album::isEmpty)
35 .sortedBy(Album::getTitle)
37 albums.paginate(soneRequest.core.preferences.imagesPerPage)
38 .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
40 templateContext["albumPagination"] = pagination
41 templateContext["albums"] = pagination.items
45 templateContext["soneRequested"] = true
46 templateContext["sone"] = soneRequest.core.getSone(soneRequest.httpRequest.getParam("sone")) ?: currentSone
50 override fun isLinkExcepted(link: URI) = true