diff --git a/app/classes/web/upload_handler.py b/app/classes/web/upload_handler.py index 91c23d84..8394b004 100644 --- a/app/classes/web/upload_handler.py +++ b/app/classes/web/upload_handler.py @@ -8,6 +8,7 @@ from app.classes.shared.console import console from app.classes.shared.main_controller import Controller from app.classes.web.websocket_helper import websocket_helper from app.classes.web.base_handler import BaseHandler +from app.classes.shared.translation import translation try: import tornado.web @@ -19,9 +20,6 @@ except ModuleNotFoundError as ex: logger = logging.getLogger(__name__) -# Class & Function Defination -MAX_STREAMED_SIZE = 1024 * 1024 * 1024 - @tornado.web.stream_request_body class UploadHandler(BaseHandler): @@ -35,14 +33,34 @@ class UploadHandler(BaseHandler): self.translator = translator def prepare(self): - self.do_upload = True - # pylint: disable=unused-variable - api_key, token_data, exec_user = self.current_user + # Class & Function Defination + api_key, _token_data, exec_user = self.current_user server_id = self.get_argument("server_id", None) superuser = exec_user["superuser"] if api_key is not None: superuser = superuser and api_key.superuser user_id = exec_user["user_id"] + stream_size_value = helper.get_setting("stream_size_GB") + MAX_STREAMED_SIZE = stream_size_value * 1073741824 + self.content_len = int(self.request.headers.get("Content-Length")) + if self.content_len > MAX_STREAMED_SIZE: + logger.error( + f"User with ID {user_id} attempted to upload a file that" + f" exceeded the max body size." + ) + websocket_helper.broadcast_user( + user_id, + "send_start_error", + { + "error": translation.translate( + "error", + "fileTooLarge", + self.controller.users.get_user_lang_by_id(user_id), + ), + }, + ) + return + self.do_upload = True if superuser: exec_user_server_permissions = ( @@ -113,12 +131,6 @@ class UploadHandler(BaseHandler): self.do_upload = False if self.do_upload: - self.content_len = int(self.request.headers.get("Content-Length")) - if self.content_len > MAX_STREAMED_SIZE: - logger.error( - f"User with ID {user_id} attempted to upload a file that" - f" exceeded the max body size." - ) try: self.f = open(full_path, "wb") except Exception as e: diff --git a/app/config/config.json b/app/config/config.json index aad33f03..93b3c7e3 100644 --- a/app/config/config.json +++ b/app/config/config.json @@ -15,6 +15,7 @@ "max_log_lines": 700, "max_audit_entries": 300, "disabled_language_files": ["lol_EN.json", ""], + "stream_size_GB": 1, "keywords": ["help", "chunk"], "allow_nsfw_profile_pictures": false } diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index 1095201e..8b129283 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -682,20 +682,6 @@ }, false); xmlHttpRequest.addEventListener('error', (e) => { console.error('Error while uploading file', file.name + '.', 'Event:', e) - var dialog = bootbox.dialog({ - title: 'Error on Upload', - message: "Fix size exceeded the max body size. Contact your system administrator.", - size: 'large', - buttons: { - ok: { - label: "Ok", - className: 'btn-info', - callback: function () { - document.location.reload(); - } - } - } - }); }, false); xmlHttpRequest.send(file); } diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index ff5d7670..56c17854 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -176,7 +176,8 @@ "not-downloaded": "We can't seem to find your executable file. Has it finished downloading? Are the permissions set to executable?", "portReminder": "We have detected this is the first time {} has been run. Make sure to forward port {} through your router/firewall to make this remotely accessible from the internet.", "start-error": "Server {} failed to start with error code: {}", - "terribleFailure": "What a Terrible Failure!" + "terribleFailure": "What a Terrible Failure!", + "fileTooLarge": "Upload failed. File upload too large. Contact system administrator for assistance." }, "footer": { "allRightsReserved": "All rights reserved",