Move web pages to their own package
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteAlbumPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.utils.isPOST
4 import net.pterodactylus.sone.web.pages.SoneTemplatePage
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
9
10 /**
11  * Page that lets the user delete an {@link Album}.
12  */
13 class DeleteAlbumPage(template: Template, webInterface: WebInterface):
14                 SoneTemplatePage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, true) {
15
16         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
17                 val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36))
18                 templateContext["album"] = album ?: throw RedirectException("invalid.html")
19                 if (request.isPOST) {
20                         if (!album.sone.isLocal) {
21                                 throw RedirectException("noPermission.html")
22                         }
23                         if (request.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
24                                 throw RedirectException("imageBrowser.html?album=${album.id}")
25                         }
26                         webInterface.core.deleteAlbum(album)
27                         throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}")
28                 }
29         }
30
31 }