X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FDeleteAlbumPage.java;h=f325332959d16445093953960f554094e0e6d52d;hb=00d6cb2688d8dda20ce55d71825b4446701a3a7a;hp=98e8909433c06e7dc6410cb43a1ef27f0f377e57;hpb=ec06ae64c86f0b06bb0cf9f8b289e7907e81dffa;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java index 98e8909..f325332 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java @@ -18,11 +18,14 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.IdBuilder; 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; +import com.google.common.base.Optional; + /** * Page that lets the user delete an {@link Album}. * @@ -46,30 +49,29 @@ public class DeleteAlbumPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { - super.processTemplate(request, templateContext); + protected void processSonePage(FreenetRequest request, TemplateContext templateContext) throws RedirectException { if (request.getMethod() == Method.POST) { - String albumId = request.getHttpRequest().getPartAsStringFailsafe("album", 36); - Album album = webInterface.getCore().getAlbum(albumId); - if (album == null) { + String albumId = request.getHttpRequest().getPartAsStringFailsafe("album", IdBuilder.ID_STRING_LENGTH); + Optional album = webInterface.getCore().getAlbum(albumId); + if (!album.isPresent()) { throw new RedirectException("invalid.html"); } - if (!album.getSone().isLocal()) { + if (!album.get().getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if (request.getHttpRequest().isPartSet("abortDelete")) { - throw new RedirectException("imageBrowser.html?album=" + album.getId()); + throw new RedirectException("imageBrowser.html?album=" + album.get().getId()); } - Album parentAlbum = album.getParent(); - webInterface.getCore().deleteAlbum(album); - if (parentAlbum.equals(album.getSone().getRootAlbum())) { - throw new RedirectException("imageBrowser.html?sone=" + album.getSone().getId()); + Album parentAlbum = album.get().getParent(); + webInterface.getCore().deleteAlbum(album.get()); + if (parentAlbum.equals(album.get().getSone().getRootAlbum())) { + throw new RedirectException("imageBrowser.html?sone=" + album.get().getSone().getId()); } throw new RedirectException("imageBrowser.html?album=" + parentAlbum.getId()); } String albumId = request.getHttpRequest().getParam("album"); - Album album = webInterface.getCore().getAlbum(albumId); - if (album == null) { + Optional album = webInterface.getCore().getAlbum(albumId); + if (!album.isPresent()) { throw new RedirectException("invalid.html"); } templateContext.set("album", album);