X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeleteImagePage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeleteImagePage.kt;h=183705a91608858f170d8069ff0b7f9815918dc0;hb=de7568a82eb4150bf6d2b0553841b7b69f84c968;hp=0000000000000000000000000000000000000000;hpb=9acbc5bdec4ccb752e0856a501568b0bb6161579;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt new file mode 100644 index 0000000..183705a --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt @@ -0,0 +1,31 @@ +package net.pterodactylus.sone.web.pages + +import net.pterodactylus.sone.utils.isPOST +import net.pterodactylus.sone.web.pages.SoneTemplatePage +import net.pterodactylus.sone.web.WebInterface +import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.util.template.Template +import net.pterodactylus.util.template.TemplateContext + +/** + * Page that lets the user delete an {@link Image}. + */ +class DeleteImagePage(template: Template, webInterface: WebInterface): + SoneTemplatePage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, true) { + + override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { + val image = webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html") + if (!image.sone.isLocal) { + throw RedirectException("noPermission.html") + } + if (request.isPOST) { + if (request.httpRequest.isPartSet("abortDelete")) { + throw RedirectException("imageBrowser.html?image=${image.id}") + } + webInterface.core.deleteImage(image) + throw RedirectException("imageBrowser.html?album=${image.album.id}") + } + templateContext["image"] = image + } + +}