X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FRescuePage.java;h=1ba86e965cce1835b103613ebe03c61eb864f5eb;hb=01e37a5196463006ce4ce4e1f505971af794817f;hp=feeb0bf0c6457c46661ab99f07021594b92e26ac;hpb=d5efb086bee8f103cbe90c7a953ffbb7ff27b689;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/RescuePage.java b/src/main/java/net/pterodactylus/sone/web/RescuePage.java index feeb0bf..1ba86e9 100644 --- a/src/main/java/net/pterodactylus/sone/web/RescuePage.java +++ b/src/main/java/net/pterodactylus/sone/web/RescuePage.java @@ -17,16 +17,19 @@ package net.pterodactylus.sone.web; +import static net.pterodactylus.sone.utils.NumberParsers.parseLong; + +import java.util.Arrays; +import java.util.Collections; + import net.pterodactylus.sone.core.SoneRescuer; -import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Header; import net.pterodactylus.util.web.Method; -import com.google.common.base.Optional; -import com.google.common.primitives.Longs; - /** * Page that lets the user control the rescue mode for a Sone. * @@ -57,11 +60,11 @@ public class RescuePage extends SoneTemplatePage { @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - Sone currentSone = getCurrentSone(request.getToadletContext(), false); + LocalSone currentSone = getCurrentSone(request.getToadletContext(), false).get(); SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone); if (request.getMethod() == Method.POST) { if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("fetch", 4))) { - long edition = Optional.fromNullable(Longs.tryParse(request.getHttpRequest().getPartAsStringFailsafe("edition", 8))).or(-1L); + long edition = parseLong(request.getHttpRequest().getPartAsStringFailsafe("edition", 8), -1L); if (edition > -1) { soneRescuer.setEdition(edition); } @@ -72,4 +75,16 @@ public class RescuePage extends SoneTemplatePage { templateContext.set("soneRescuer", soneRescuer); } + @Override + protected Iterable
getAdditionalHeaders(FreenetRequest request) { + LocalSone currentSone = getCurrentSone(request.getToadletContext(), false).get(); + SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone); + if ((request.getMethod() == Method.GET) && soneRescuer.isFetching()) { + final Header header = new Header("Refresh"); + header.addValue("5; url=rescue.html"); + return Arrays.asList(header); + } + return Collections.emptyList(); + } + }