/*
- * Sone - DeleteImagePage.java - Copyright © 2011 David Roden
+ * Sone - DeleteImagePage.java - Copyright © 2011–2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
package net.pterodactylus.sone.web;
+import net.pterodactylus.sone.data.IdBuilder;
import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
/**
* Page that lets the user delete an {@link Image}.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
+ String imageId = (request.getMethod() == Method.POST) ? request.getHttpRequest().getPartAsStringFailsafe("image", IdBuilder.ID_STRING_LENGTH)
+ : request.getHttpRequest().getParam("image");
+ Image image = webInterface.getCore().getImage(imageId, false);
+ if (image == null) {
+ throw new RedirectException("invalid.html");
+ }
+ if (!image.getSone().isLocal()) {
+ throw new RedirectException("noPermission.html");
+ }
if (request.getMethod() == Method.POST) {
- String imageId = request.getHttpRequest().getPartAsStringFailsafe("image", 36);
- Image image = webInterface.getCore().getImage(imageId, false);
- if (image == null) {
- throw new RedirectException("invalid.html");
- }
- if (!webInterface.getCore().isLocalSone(image.getSone())) {
- throw new RedirectException("noPermission.html");
+ if (request.getHttpRequest().isPartSet("abortDelete")) {
+ throw new RedirectException("imageBrowser.html?image=" + image.getId());
}
webInterface.getCore().deleteImage(image);
throw new RedirectException("imageBrowser.html?album=" + image.getAlbum().getId());
}
+ templateContext.set("image", image);
}
}