From: Michael Tremer Date: Sun, 23 Oct 2022 15:49:28 +0000 (+0000) Subject: hub: Implement listing all uploads X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=962e472bff0ae23f64a9a13c7f9ce803655100df;p=pbs.git hub: Implement listing all uploads Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/users.py b/src/buildservice/users.py index 4dd2a498..65d08948 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -540,6 +540,27 @@ class User(base.DataObject): slug, ) + @property + def uploads(self): + """ + Returns all uploads that belong to this user + """ + uploads = self.backend.uploads._get_uploads(""" + SELECT + * + FROM + uploads + WHERE + user_id = %s + AND + expires_at > CURRENT_TIMESTAMP + ORDER BY + created_at DESC + """, self.id, + ) + + return list(uploads) + class QuotaExceededError(Exception): pass diff --git a/src/hub/uploads.py b/src/hub/uploads.py index 86ab35d7..88797de1 100644 --- a/src/hub/uploads.py +++ b/src/hub/uploads.py @@ -37,6 +37,25 @@ class IndexHandler(BaseHandler): """ self.buffer.write(data) + @tornado.web.authenticated + def get(self): + uploads = [] + + for upload in self.current_user.uploads: + uploads.append({ + "id" : upload.uuid, + "filename" : upload.filename, + "size" : upload.size, + + "created_at" : upload.created_at.isoformat(), + "expires_at" : upload.expires_at.isoformat(), + }) + + self.finish({ + "status" : "ok", + "uploads" : uploads, + }) + @tornado.web.authenticated async def put(self): """