From 6cdec88e86387207b60edeb4286da81ebba9d1f5 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 20 Oct 2023 09:48:36 +0000 Subject: [PATCH] uploads: Show if payload has been received and block sending it again Signed-off-by: Michael Tremer --- src/buildservice/uploads.py | 15 +++++++++++++++ src/web/uploads.py | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/buildservice/uploads.py b/src/buildservice/uploads.py index 56f8c158..cfac0a34 100644 --- a/src/buildservice/uploads.py +++ b/src/buildservice/uploads.py @@ -232,10 +232,25 @@ class Upload(base.DataObject): def expires_at(self): return self.data.expires_at + async def has_payload(self): + """ + Returns True if this upload has received its payload + """ + # We must have a path + if not self.path: + return False + + # The data must exist on disk + return await self.backend.exists(self.path) + async def copyfrom(self, src): """ Copies the content of this upload from the source file descriptor """ + # Cannot do this if we already have a payload + if await self.has_payload(): + raise FileExistsError("We already have the payload") + # Reset the source file handle src.seek(0) diff --git a/src/web/uploads.py b/src/web/uploads.py index 8df919f3..dbce3d47 100644 --- a/src/web/uploads.py +++ b/src/web/uploads.py @@ -32,7 +32,7 @@ class APIv1IndexHandler(base.APIMixin, tornado.web.RequestHandler): allow_users = True @base.negotiate - def get(self): + async def get(self): uploads = [] for upload in self.current_user.uploads: @@ -43,6 +43,9 @@ class APIv1IndexHandler(base.APIMixin, tornado.web.RequestHandler): "created_at" : upload.created_at.isoformat(), "expires_at" : upload.expires_at.isoformat(), + + # Show whether we have received the payload + "has-payload": await upload.has_payload(), }) self.finish({ -- 2.47.3