X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FUploadImagePage.java;h=673e439ea2b3c6381affd7d83bc42928cac7af65;hb=00a434a23c9ea1e57c63d8a3c0fc4b09277af431;hp=2c7b0a9a55ff55865de54386704b524944d5e880;hpb=6b65a32a69b0e3721c58b4501a6b58fa4989f162;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java b/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java index 2c7b0a9..673e439 100644 --- a/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java @@ -45,6 +45,7 @@ import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.web.Method; +import com.google.common.base.Optional; import com.google.common.io.ByteStreams; import freenet.support.api.Bucket; @@ -85,11 +86,11 @@ public class UploadImagePage extends SoneTemplatePage { if (request.getMethod() == Method.POST) { Sone currentSone = getCurrentSone(request.getToadletContext()); String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", IdBuilder.ID_STRING_LENGTH); - Album parent = webInterface.getCore().getAlbum(parentId); - if (parent == null) { + Optional parent = webInterface.getCore().getAlbum(parentId); + if (!parent.isPresent()) { throw new RedirectException("noPermission.html"); } - if (!currentSone.equals(parent.getSone())) { + if (!currentSone.equals(parent.get().getSone())) { throw new RedirectException("noPermission.html"); } String name = request.getHttpRequest().getPartAsStringFailsafe("title", 200); @@ -123,7 +124,7 @@ public class UploadImagePage extends SoneTemplatePage { } String mimeType = getMimeType(imageData); TemporaryImage temporaryImage = webInterface.getCore().createTemporaryImage(mimeType, imageData); - net.pterodactylus.sone.data.Image image = webInterface.getCore().createImage(currentSone, parent, temporaryImage); + net.pterodactylus.sone.data.Image image = webInterface.getCore().createImage(currentSone, parent.get(), temporaryImage); image.modify().setTitle(name).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).setWidth(uploadedImage.getWidth(null)).setHeight(uploadedImage.getHeight(null)).update(); } catch (IOException ioe1) { logger.log(Level.WARNING, "Could not read uploaded image!", ioe1); @@ -134,7 +135,7 @@ public class UploadImagePage extends SoneTemplatePage { Closer.close(imageDataInputStream); Closer.flush(uploadedImage); } - throw new RedirectException("imageBrowser.html?album=" + parent.getId()); + throw new RedirectException("imageBrowser.html?album=" + parent.get().getId()); } }