1 package net.pterodactylus.sone.web.pages
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
10 * Page that lets the user delete an {@link Image}.
12 class DeleteImagePage(template: Template, webInterface: WebInterface):
13 SoneTemplatePage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, true) {
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")
21 if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
22 throw RedirectException("imageBrowser.html?image=${image.id}")
24 webInterface.core.deleteImage(image)
25 throw RedirectException("imageBrowser.html?album=${image.album.id}")
27 val image = webInterface.core.getImage(freenetRequest.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html")
28 if (!image.sone.isLocal) {
29 throw RedirectException("noPermission.html")
31 templateContext["image"] = image