]> git.ipfire.org Git - pbs.git/commitdiff
uploads: Show if payload has been received and block sending it again
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 09:48:36 +0000 (09:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 09:48:36 +0000 (09:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/uploads.py
src/web/uploads.py

index 56f8c1584bd0a5a8ef7c2cf6df7eb5b7d1bcdc54..cfac0a342e157c446e1bd300fa173c68d9a6b115 100644 (file)
@@ -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)
 
index 8df919f3bd5a1c5267f3e7f910ede2553ccff7de..dbce3d47c9102bb541cfbcf4e2bbdf1530a727a4 100644 (file)
@@ -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({