♻️ Add freenet client interface
[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.data.*
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.*
9 import javax.inject.*
10
11 /**
12  * Page that lets the user delete an {@link Image}.
13  */
14 @TemplatePath("/templates/deleteImage.html")
15 @ToadletPath("deleteImage.html")
16 class DeleteImagePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
17                 LoggedInPage("Page.DeleteImage.Title", webInterface, loaders, templateRenderer) {
18
19         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20                 if (soneRequest.isPOST) {
21                         val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: redirectTo("invalid.html")
22                         if (!image.sone.isLocal) {
23                                 redirectTo("noPermission.html")
24                         }
25                         if (soneRequest.httpRequest.isPartSet("abortDelete")) {
26                                 redirectTo("imageBrowser.html?image=${image.id}")
27                         }
28                         soneRequest.core.deleteImage(image)
29                         redirectTo("imageBrowser.html?album=${image.album.id}")
30                 }
31                 val image = soneRequest.core.getImage(soneRequest.httpRequest.getParam("image")) ?: redirectTo("invalid.html")
32                 if (!image.sone.isLocal) {
33                         redirectTo("noPermission.html")
34                 }
35                 templateContext["image"] = image
36         }
37
38 }