Update to Kotlin 1.2.0
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteImagePage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.utils.isPOST
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8
9 /**
10  * Page that lets the user delete an {@link Image}.
11  */
12 class DeleteImagePage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, true) {
14
15         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
16                 if (freenetRequest.isPOST) {
17                         val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
18                         if (!image.sone.isLocal) {
19                                 throw RedirectException("noPermission.html")
20                         }
21                         if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
22                                 throw RedirectException("imageBrowser.html?image=${image.id}")
23                         }
24                         webInterface.core.deleteImage(image)
25                         throw RedirectException("imageBrowser.html?album=${image.album.id}")
26                 }
27                 val image = webInterface.core.getImage(freenetRequest.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html")
28                 if (!image.sone.isLocal) {
29                         throw RedirectException("noPermission.html")
30                 }
31                 templateContext["image"] = image
32         }
33
34 }