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.main.*
6 import net.pterodactylus.sone.utils.isPOST
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
11 import javax.inject.Inject
14 * Page that lets the user edit the name and description of an album.
16 class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
17 LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, loaders) {
19 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20 if (soneRequest.isPOST) {
21 val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
22 album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
23 if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
24 album.parent?.moveAlbumUp(album)
25 soneRequest.core.touchConfiguration()
26 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
27 } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
28 album.parent?.moveAlbumDown(album)
29 soneRequest.core.touchConfiguration()
30 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
34 .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100))
35 .setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
37 } catch (e: AlbumTitleMustNotBeEmpty) {
38 throw RedirectException("emptyAlbumTitle.html")
40 soneRequest.core.touchConfiguration()
41 throw RedirectException("imageBrowser.html?album=${album.id}")