Clean up some imports
[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(request: FreenetRequest, templateContext: TemplateContext) {
16                 if (request.isPOST) {
17                         val image = webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
18                         if (!image.sone.isLocal) {
19                                 throw RedirectException("noPermission.html")
20                         }
21                         if (request.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(request.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 }