]> git.ipfire.org Git - pbs.git/commitdiff
hub: Drop old upload handlers
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 09:09:08 +0000 (09:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 09:09:08 +0000 (09:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/hub/__init__.py
src/hub/handlers.py

index 34c2393b68b9bcf008aaac33471a74cc5f4d33df..675b6a156b26d3eb00375ae547be6524c7cbf306 100644 (file)
@@ -41,11 +41,6 @@ class Application(tornado.web.Application):
 
                        # Uploads
                        (r"/upload", handlers.UploadHandler),
-                       (r"/uploads/create", handlers.UploadsCreateHandler),
-                       (r"/uploads/stream", handlers.UploadsStreamHandler),
-                       (r"/uploads/(.*)/sendchunk", handlers.UploadsSendChunkHandler),
-                       (r"/uploads/(.*)/finished", handlers.UploadsFinishedHandler),
-                       (r"/uploads/(.*)/destroy", handlers.UploadsDestroyHandler),
                ], **settings)
 
                # Launch backend
index 8164dfee4c193dbb6a3d5c54ccdec0373dd6120d..47d566e9cf6ca614d7942abf767efc08752a7704 100644 (file)
@@ -6,12 +6,10 @@ import hmac
 import json
 import logging
 import tempfile
-import time
 import tornado.web
 
 from .. import builds
 from .. import builders
-from .. import uploads
 from .. import users
 
 log = logging.getLogger("pakfire.hub")
@@ -207,130 +205,6 @@ class UploadHandler(BaseHandler):
                return h, hexdigest
 
 
-class UploadsCreateHandler(BaseHandler):
-       """
-               Create a new upload object in the database and return a unique ID
-               to the uploader.
-       """
-
-       @tornado.web.authenticated
-       def get(self):
-               # XXX Check permissions
-
-               filename = self.get_argument("filename")
-               filesize = self.get_argument_int("filesize")
-               filehash = self.get_argument("hash", None)
-
-               with self.db.transaction():
-                       upload = self.backend.uploads.create(filename, filesize,
-                               filehash, user=self.user, builder=self.builder)
-
-                       self.finish(upload.uuid)
-
-
-@tornado.web.stream_request_body
-class UploadsStreamHandler(BaseHandler):
-       @tornado.web.authenticated
-       def prepare(self):
-               # Received file size
-               self.size = 0
-
-               upload_uuid = self.get_argument("id")
-
-               # Fetch upload object from database
-               self.upload = self.backend.uploads.get_by_uuid(upload_uuid)
-               if not self.upload:
-                       raise tornado.web.HTTPError(404)
-
-       def data_received(self, data):
-               logging.debug("Received chunk of %s bytes" % len(data))
-               self.size += len(data)
-
-               # Write the received chunk to disk
-               with self.db.transaction():
-                       self.upload.append(data)
-
-       def put(self):
-               logging.info("Received entire file (%s bytes)" % self.size)
-
-               with self.db.transaction():
-                       self.upload.finished()
-
-               self.finish("OK")
-
-
-class UploadsSendChunkHandler(BaseHandler):
-       @tornado.web.authenticated
-       def post(self, upload_id):
-               upload = self.backend.uploads.get_by_uuid(upload_id)
-               if not upload:
-                       raise tornado.web.HTTPError(404, "Invalid upload id.")
-
-               if not upload.builder == self.builder:
-                       raise tornado.web.HTTPError(403, "Uploading an other host's file.")
-
-               chksum = self.get_argument("chksum")
-               data = self.get_argument("data")
-
-               # Decode data.
-               data = base64.b64decode(data)
-
-               # Calculate hash and compare.
-               h = hashlib.new("sha512")
-               h.update(data)
-
-               if not chksum == h.hexdigest():
-                       raise tornado.web.HTTPError(400, "Checksum mismatch")
-
-               # Append the data to file.
-               with self.db.transaction():
-                       upload.append(data)
-
-
-class UploadsFinishedHandler(BaseHandler):
-       @tornado.web.authenticated
-       def get(self, upload_id):
-               upload = self.backend.uploads.get_by_uuid(upload_id)
-               if not upload:
-                       raise tornado.web.HTTPError(404, "Invalid upload id.")
-
-               if not upload.builder == self.builder:
-                       raise tornado.web.HTTPError(403, "Uploading an other host's file.")
-
-               # Validate the uploaded data to its hash.
-               ret = upload.validate()
-
-               # If the validation was successfull, we mark the upload
-               # as finished and send True to the client.
-               if ret:
-                       upload.finished()
-                       self.finish("OK")
-
-                       return
-
-               # In case the download was corrupted or incomplete, we delete it
-               # and tell the client to start over.
-               with self.db.transaction():
-                       upload.remove()
-
-               self.finish("ERROR: CORRUPTED OR INCOMPLETE FILE")
-
-
-class UploadsDestroyHandler(BaseHandler):
-       @tornado.web.authenticated
-       def get(self, upload_id):
-               upload = self.backend.uploads.get_by_uuid(upload_id)
-               if not upload:
-                       raise tornado.web.HTTPError(404, "Invalid upload id.")
-
-               if not upload.builder == self.builder:
-                       raise tornado.web.HTTPError(403, "Removing an other host's file.")
-
-               # Remove the upload from the database and trash the data.
-               with self.db.transaction():
-                       upload.remove()
-
-
 # Builds
 
 class BuildsCreateHandler(BaseHandler):