From: Michael Tremer Date: Wed, 29 Jan 2025 10:40:11 +0000 (+0000) Subject: uploads: Add a debug handler to download any uploaded payload X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e44bf3f7e6014d00c3a92479ef699f579846f479;p=pbs.git uploads: Add a debug handler to download any uploaded payload Signed-off-by: Michael Tremer --- diff --git a/src/web/uploads.py b/src/web/uploads.py index 9190b35c..1458c2ce 100644 --- a/src/web/uploads.py +++ b/src/web/uploads.py @@ -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): """