From: Michael Tremer Date: Thu, 26 May 2022 09:09:08 +0000 (+0000) Subject: hub: Drop old upload handlers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2388fcb2f985374e8fa64a0c113e8afd1ec07e3;p=pbs.git hub: Drop old upload handlers Signed-off-by: Michael Tremer --- diff --git a/src/hub/__init__.py b/src/hub/__init__.py index 34c2393b..675b6a15 100644 --- a/src/hub/__init__.py +++ b/src/hub/__init__.py @@ -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 diff --git a/src/hub/handlers.py b/src/hub/handlers.py index 8164dfee..47d566e9 100644 --- a/src/hub/handlers.py +++ b/src/hub/handlers.py @@ -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):