From 7389b37198e67e64a9e43453d2b643e0c2e2174f Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 22 Aug 2021 10:17:33 -0400 Subject: [PATCH] Initial commit on this broken branch --- app/classes/web/tornado.py | 2 ++ app/classes/web/upload_handler.py | 34 +++++++++++++++++++ .../templates/panel/server_files.html | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/classes/web/upload_handler.py diff --git a/app/classes/web/tornado.py b/app/classes/web/tornado.py index e3f51619..4b770b55 100644 --- a/app/classes/web/tornado.py +++ b/app/classes/web/tornado.py @@ -27,6 +27,7 @@ try: from app.classes.web.websocket_handler import SocketHandler from app.classes.web.static_handler import CustomStaticHandler from app.classes.shared.translation import translation + from app.classes.web.upload_handler import UploadHandler except ModuleNotFoundError as e: logger.critical("Import Error: Unable to load {} module".format(e, e.name)) @@ -129,6 +130,7 @@ class Webserver: (r'/api/stats/servers', ServersStats, handler_args), (r'/api/stats/node', NodeStats, handler_args), (r'/ws', SocketHandler, handler_args), + (r'/upload', UploadHandler, handler_args), ] app = tornado.web.Application( diff --git a/app/classes/web/upload_handler.py b/app/classes/web/upload_handler.py new file mode 100644 index 00000000..c0e35f07 --- /dev/null +++ b/app/classes/web/upload_handler.py @@ -0,0 +1,34 @@ +from tornado.concurrent import Future +from tornado.escape import utf8 +from tornado import gen +from tornado.httpclient import AsyncHTTPClient +from tornado.ioloop import IOLoop +from tornado.options import parse_command_line, define, options +from tornado.web import Application, RequestHandler, stream_request_body + +import logging + +logger = logging.getLogger(__name__) + + +define('server_delay', default=2.0) +define('client_delay', default=1.0) +define('num_chunks', default=40) + +@stream_request_body +class UploadHandler(RequestHandler): + def prepare(self): + print("In PREPARE") + logger.info('UploadHandler.prepare') + + @gen.coroutine + def data_received(self, chunk): + print("In RECIEVED") + logger.info('UploadHandler.data_received(%d bytes: %r)', + len(chunk), chunk[:9]) + yield gen.Task(IOLoop.current().call_later, options.server_delay) + + def put(self): + print("In PUT") + logger.info('UploadHandler.put') + self.write('ok') diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index cd67b68b..0921e3f6 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -526,7 +526,7 @@ $(function () { server_id = {{ data['server_stats']['server_id']['server_id'] }}; var uploadHtml = "
" + - '
{% raw xsrf_form_html() %}'+"