1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.utils.isPOST
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
13 * Page that lets the user edit the name and description of an album.
15 class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface):
16 LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface) {
18 override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
19 if (freenetRequest.isPOST) {
20 val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
21 album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
22 if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
23 album.parent?.moveAlbumUp(album)
24 webInterface.core.touchConfiguration()
25 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
26 } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
27 album.parent?.moveAlbumDown(album)
28 webInterface.core.touchConfiguration()
29 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
33 .setTitle(freenetRequest.httpRequest.getPartAsStringFailsafe("title", 100))
34 .setDescription(freenetRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
36 } catch (e: AlbumTitleMustNotBeEmpty) {
37 throw RedirectException("emptyAlbumTitle.html")
39 webInterface.core.touchConfiguration()
40 throw RedirectException("imageBrowser.html?album=${album.id}")