mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 12:56:11 +01:00
Add max stream size to config.json
Add ability to translate error message
This commit is contained in:
parent
dc69a8a9f2
commit
657d3e92f2
@ -8,6 +8,7 @@ from app.classes.shared.console import console
|
|||||||
from app.classes.shared.main_controller import Controller
|
from app.classes.shared.main_controller import Controller
|
||||||
from app.classes.web.websocket_helper import websocket_helper
|
from app.classes.web.websocket_helper import websocket_helper
|
||||||
from app.classes.web.base_handler import BaseHandler
|
from app.classes.web.base_handler import BaseHandler
|
||||||
|
from app.classes.shared.translation import translation
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import tornado.web
|
import tornado.web
|
||||||
@ -19,9 +20,6 @@ except ModuleNotFoundError as ex:
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Class & Function Defination
|
|
||||||
MAX_STREAMED_SIZE = 1024 * 1024 * 1024
|
|
||||||
|
|
||||||
|
|
||||||
@tornado.web.stream_request_body
|
@tornado.web.stream_request_body
|
||||||
class UploadHandler(BaseHandler):
|
class UploadHandler(BaseHandler):
|
||||||
@ -35,14 +33,34 @@ class UploadHandler(BaseHandler):
|
|||||||
self.translator = translator
|
self.translator = translator
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
self.do_upload = True
|
# Class & Function Defination
|
||||||
# pylint: disable=unused-variable
|
api_key, _token_data, exec_user = self.current_user
|
||||||
api_key, token_data, exec_user = self.current_user
|
|
||||||
server_id = self.get_argument("server_id", None)
|
server_id = self.get_argument("server_id", None)
|
||||||
superuser = exec_user["superuser"]
|
superuser = exec_user["superuser"]
|
||||||
if api_key is not None:
|
if api_key is not None:
|
||||||
superuser = superuser and api_key.superuser
|
superuser = superuser and api_key.superuser
|
||||||
user_id = exec_user["user_id"]
|
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:
|
if superuser:
|
||||||
exec_user_server_permissions = (
|
exec_user_server_permissions = (
|
||||||
@ -113,12 +131,6 @@ class UploadHandler(BaseHandler):
|
|||||||
self.do_upload = False
|
self.do_upload = False
|
||||||
|
|
||||||
if self.do_upload:
|
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:
|
try:
|
||||||
self.f = open(full_path, "wb")
|
self.f = open(full_path, "wb")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"max_log_lines": 700,
|
"max_log_lines": 700,
|
||||||
"max_audit_entries": 300,
|
"max_audit_entries": 300,
|
||||||
"disabled_language_files": ["lol_EN.json", ""],
|
"disabled_language_files": ["lol_EN.json", ""],
|
||||||
|
"stream_size_GB": 1,
|
||||||
"keywords": ["help", "chunk"],
|
"keywords": ["help", "chunk"],
|
||||||
"allow_nsfw_profile_pictures": false
|
"allow_nsfw_profile_pictures": false
|
||||||
}
|
}
|
||||||
|
@ -682,20 +682,6 @@
|
|||||||
}, false);
|
}, false);
|
||||||
xmlHttpRequest.addEventListener('error', (e) => {
|
xmlHttpRequest.addEventListener('error', (e) => {
|
||||||
console.error('Error while uploading file', file.name + '.', 'Event:', 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);
|
}, false);
|
||||||
xmlHttpRequest.send(file);
|
xmlHttpRequest.send(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?",
|
"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.",
|
"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: {}",
|
"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": {
|
"footer": {
|
||||||
"allRightsReserved": "All rights reserved",
|
"allRightsReserved": "All rights reserved",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user