]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blobdiff - webapp/handlers_nopaste.py
nopaste: Send filename of uploaded files in the header
[people/shoehn/ipfire.org.git] / webapp / handlers_nopaste.py
index 5199b9c5f6a0e12592235cd68d3d3011fc4b327e..6c2b75b011a76b5512cc7fd2ba47aa848d9cdb77 100644 (file)
@@ -57,7 +57,7 @@ class NopasteCreateHandler(BaseHandler):
        def _max_size(self):
                # Authenticated users are allowed to upload up to 10MB
                if self.current_user:
-                       return 10 * (1024 ** 2)
+                       return 25 * (1024 ** 2)
 
                # The rest is only allowed to upload up to 2MB
                return 2 * (1024 ** 2)
@@ -69,11 +69,26 @@ class NopasteRawHandler(BaseHandler):
                if not entry:
                        raise tornado.web.HTTPError(404)
 
+               # Set the filename
+               self.set_header("Content-Disposition", "inline; filename=\"%s\"" % entry.subject)
+
                # Set mimetype
                self.set_header("Content-Type", entry.mimetype)
 
+               # Set expiry headers
+               expires = entry.time_expires or \
+                       (datetime.datetime.utcnow() + datetime.timedelta(days=30))
+
+               # For HTTP/1.0
+               self.set_header("Expires", expires)
+
+               # For HTTP/1.1
+               max_age = expires - datetime.datetime.utcnow()
+               self.set_header("Cache-Control", "public,max-age=%d" % max_age.total_seconds())
+
                # Send content
-               self.finish(entry.content)
+               content = self.backend.nopaste.get_content(entry.uuid)
+               self.finish(content)
 
 
 class NopasteViewHandler(BaseHandler):
@@ -82,4 +97,10 @@ class NopasteViewHandler(BaseHandler):
                if not entry:
                        raise tornado.web.HTTPError(404)
 
-               self.render("nopaste/view.html", entry=entry)
+               # Fetch the content if the output should be displayed
+               if entry.mimetype.startswith("text/"):
+                       content = self.backend.nopaste.get_content(entry.uuid)
+               else:
+                       content = None
+
+               self.render("nopaste/view.html", entry=entry, content=content)