Fix search for Sone elements
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / RescuePage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
11
12 /**
13  * Page that lets the user control the rescue mode for a Sone.
14  */
15 class RescuePage @Inject constructor(template: Template, webInterface: WebInterface):
16                 LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface) {
17
18         override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
19                 val soneRescuer = webInterface.core.getSoneRescuer(currentSone)
20                 templateContext["soneRescuer"] = soneRescuer
21                 if (freenetRequest.isPOST) {
22                         freenetRequest.parameters["edition", 9]?.toIntOrNull()?.also {
23                                 if (it > -1) {
24                                         soneRescuer.setEdition(it.toLong())
25                                 }
26                         }
27                         if (freenetRequest.parameters["fetch", 8] == "true") {
28                                 soneRescuer.startNextFetch()
29                         }
30                         throw RedirectException("rescue.html")
31                 }
32         }
33
34 }