X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FGetImagePage.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FGetImagePage.java;h=fdd72a8abda5e341c978fa4e233c3ad8cf1f08b5;hb=456a0d35f3afcdaf4c2f82048f8cb440059f70e7;hp=0000000000000000000000000000000000000000;hpb=3968d1333827f11f4e599e8f47842ad5d3a95193;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/web/GetImagePage.java b/src/main/java/net/pterodactylus/sone/web/GetImagePage.java
new file mode 100644
index 0000000..fdd72a8
--- /dev/null
+++ b/src/main/java/net/pterodactylus/sone/web/GetImagePage.java
@@ -0,0 +1,64 @@
+/*
+ * Sone - GetImagePage.java - Copyright © 2011 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.pterodactylus.sone.web;
+
+import net.pterodactylus.sone.data.TemporaryImage;
+import net.pterodactylus.sone.web.page.Page;
+
+/**
+ * Page that delivers a {@link TemporaryImage} to the browser.
+ *
+ * @author David âBombeâ Roden
+ */
+public class GetImagePage implements Page {
+
+ /** The Sone web interface. */
+ private final WebInterface webInterface;
+
+ /**
+ * Creates a new âget imageâ page.
+ *
+ * @param webInterface
+ * The Sone web interface
+ */
+ public GetImagePage(WebInterface webInterface) {
+ this.webInterface = webInterface;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getPath() {
+ return "getImage.html";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Response handleRequest(Request request) {
+ String imageId = request.getHttpRequest().getParam("image");
+ TemporaryImage temporaryImage = webInterface.getCore().getTemporaryImage(imageId);
+ if (temporaryImage == null) {
+ return new Response(404, "Not found.", "text/plain; charset=utf-8", "");
+ }
+ return new Response(200, "OK", temporaryImage.getMimeType(), temporaryImage.getImageData()).setHeader("Content-Disposition", "attachment; filename=" + temporaryImage.getId() + "." + temporaryImage.getMimeType().substring(temporaryImage.getMimeType().lastIndexOf("/") + 1));
+ }
+
+}