1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.web.pages.SoneTemplatePage
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
12 * Page that lets the user edit the name and description of an album.
14 class EditAlbumPage(template: Template, webInterface: WebInterface):
15 SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) {
17 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
19 val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
20 album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
21 if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
22 album.parent?.moveAlbumUp(album)
23 webInterface.core.touchConfiguration()
24 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
25 } else if (request.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
26 album.parent?.moveAlbumDown(album)
27 webInterface.core.touchConfiguration()
28 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
32 .setTitle(request.httpRequest.getPartAsStringFailsafe("title", 100))
33 .setDescription(request.httpRequest.getPartAsStringFailsafe("description", 1000))
35 } catch (e: AlbumTitleMustNotBeEmpty) {
36 throw RedirectException("emptyAlbumTitle.html")
38 webInterface.core.touchConfiguration()
39 throw RedirectException("imageBrowser.html?album=${album.id}")