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.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
11 * Page that lets the user edit the name and description of an album.
13 class EditAlbumPage(template: Template, webInterface: WebInterface):
14 SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) {
16 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
18 val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
19 album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
20 if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
21 album.parent?.moveAlbumUp(album)
22 webInterface.core.touchConfiguration()
23 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
24 } else if (request.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
25 album.parent?.moveAlbumDown(album)
26 webInterface.core.touchConfiguration()
27 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
31 .setTitle(request.httpRequest.getPartAsStringFailsafe("title", 100))
32 .setDescription(request.httpRequest.getPartAsStringFailsafe("description", 1000))
34 } catch (e: AlbumTitleMustNotBeEmpty) {
35 throw RedirectException("emptyAlbumTitle.html")
37 webInterface.core.touchConfiguration()
38 throw RedirectException("imageBrowser.html?album=${album.id}")