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