Add max stream size to config.json

Add ability to translate error message
This commit is contained in:
amcmanu3 2022-04-02 13:50:40 -04:00
parent dc69a8a9f2
commit 657d3e92f2
4 changed files with 27 additions and 27 deletions

View File

@ -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:

View File

@ -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
}

View File

@ -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);
}

View File

@ -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",