]> git.ipfire.org Git - pbs.git/commitdiff
uploads: Add a debug handler to download any uploaded payload
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Jan 2025 10:40:11 +0000 (10:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Jan 2025 10:40:11 +0000 (10:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/uploads.py

index 9190b35c24a9e2273887613e9be320e41d57c76d..1458c2cefa8741872ba1211ef301ec6e79544f39 100644 (file)
@@ -124,6 +124,26 @@ class APIv1DetailHandler(base.APIMixin, base.BaseHandler):
                """
                self.buffer.write(data)
 
+       @base.negotiate
+       async def get(self, uuid):
+               """
+                       This is mostly for debugging so that we can download
+                       any uploaded content for inspection.
+               """
+               # Only allow this for admins
+               if not self.current_user.is_admin():
+                       raise tornado.web.HTTPError(403)
+
+               # Fetch the upload
+               upload = await self.backend.uploads.get_by_uuid(uuid)
+               if not upload:
+                       raise tornado.web.HTTPError(404, "Could not find upload %s" % uuid)
+
+               # XXX we should guess the mime type here
+
+               # Send it to the browser
+               await upload.copyinto(self)
+
        @base.negotiate
        async def put(self, uuid):
                """