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