mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-18 17:15:13 +01:00
Send message to front end when system fails to download bedrock server
This commit is contained in:
parent
37b8a4fa16
commit
a73db62b24
@ -132,22 +132,29 @@ class Helpers:
|
|||||||
target_linux = (
|
target_linux = (
|
||||||
'https://www.minecraft.net/bedrockdedicatedserver/bin-linux/[^"]*'
|
'https://www.minecraft.net/bedrockdedicatedserver/bin-linux/[^"]*'
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get minecraft server download page
|
# Get minecraft server download page
|
||||||
# (hopefully the don't change the structure)
|
# (hopefully the don't change the structure)
|
||||||
download_page = get(url, headers=headers, timeout=1)
|
download_page = get(url, headers=headers, timeout=1)
|
||||||
|
download_page.raise_for_status()
|
||||||
# Search for our string targets
|
# Search for our string targets
|
||||||
win_download_url = re.search(target_win, download_page.text).group(0)
|
win_search_result = re.search(target_win, download_page.text)
|
||||||
linux_download_url = re.search(target_linux, download_page.text).group(0)
|
linux_search_result = re.search(target_linux, download_page.text)
|
||||||
|
if win_search_result is None or linux_search_result is None:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Could not determine download URL from minecraft.net."
|
||||||
|
)
|
||||||
|
|
||||||
|
win_download_url = win_search_result.group(0)
|
||||||
|
linux_download_url = linux_search_result.group(0)
|
||||||
|
print(win_download_url, linux_download_url)
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
return win_download_url
|
return win_download_url
|
||||||
|
|
||||||
return linux_download_url
|
return linux_download_url
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Unable to resolve remote bedrock download url! \n{e}")
|
logger.error(f"Unable to resolve remote bedrock download url! \n{e}")
|
||||||
|
raise e
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_execution_java(self, value, execution_command):
|
def get_execution_java(self, value, execution_command):
|
||||||
|
@ -217,15 +217,16 @@ class ImportHelpers:
|
|||||||
FileHelpers.del_dirs(temp_dir)
|
FileHelpers.del_dirs(temp_dir)
|
||||||
|
|
||||||
def download_bedrock_server(self, path, new_id):
|
def download_bedrock_server(self, path, new_id):
|
||||||
|
bedrock_url = Helpers.get_latest_bedrock_url()
|
||||||
download_thread = threading.Thread(
|
download_thread = threading.Thread(
|
||||||
target=self.download_threaded_bedrock_server,
|
target=self.download_threaded_bedrock_server,
|
||||||
daemon=True,
|
daemon=True,
|
||||||
args=(path, new_id),
|
args=(path, new_id, bedrock_url),
|
||||||
name=f"{new_id}_download",
|
name=f"{new_id}_download",
|
||||||
)
|
)
|
||||||
download_thread.start()
|
download_thread.start()
|
||||||
|
|
||||||
def download_threaded_bedrock_server(self, path, new_id):
|
def download_threaded_bedrock_server(self, path, new_id, bedrock_url):
|
||||||
"""
|
"""
|
||||||
Downloads the latest Bedrock server, unzips it, sets necessary permissions.
|
Downloads the latest Bedrock server, unzips it, sets necessary permissions.
|
||||||
|
|
||||||
@ -236,10 +237,8 @@ class ImportHelpers:
|
|||||||
This method handles exceptions and logs errors for each step of the process.
|
This method handles exceptions and logs errors for each step of the process.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
bedrock_url = Helpers.get_latest_bedrock_url()
|
|
||||||
if bedrock_url:
|
if bedrock_url:
|
||||||
file_path = os.path.join(path, "bedrock_server.zip")
|
file_path = os.path.join(path, "bedrock_server.zip")
|
||||||
|
|
||||||
success = FileHelpers.ssl_get_file(
|
success = FileHelpers.ssl_get_file(
|
||||||
bedrock_url, path, "bedrock_server.zip"
|
bedrock_url, path, "bedrock_server.zip"
|
||||||
)
|
)
|
||||||
@ -263,6 +262,7 @@ class ImportHelpers:
|
|||||||
logger.critical(
|
logger.critical(
|
||||||
f"Failed to download bedrock executable during server creation! \n{e}"
|
f"Failed to download bedrock executable during server creation! \n{e}"
|
||||||
)
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
ServersController.finish_import(new_id)
|
ServersController.finish_import(new_id)
|
||||||
server_users = PermissionsServers.get_server_user_list(new_id)
|
server_users = PermissionsServers.get_server_user_list(new_id)
|
||||||
|
@ -725,7 +725,19 @@ class ApiServersIndexHandler(BaseApiHandler):
|
|||||||
405, {"status": "error", "error": "DATA CONSTRAINT FAILED"}
|
405, {"status": "error", "error": "DATA CONSTRAINT FAILED"}
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
new_server_id = self.controller.create_api_server(data, user["user_id"])
|
new_server_id = self.controller.create_api_server(data, user["user_id"])
|
||||||
|
except Exception as e:
|
||||||
|
self.controller.servers.stats.record_stats()
|
||||||
|
|
||||||
|
self.finish_json(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
"status": "error",
|
||||||
|
"error": "Could not create server",
|
||||||
|
"error_data": str(e),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
self.controller.servers.stats.record_stats()
|
self.controller.servers.stats.record_stats()
|
||||||
|
|
||||||
|
@ -624,7 +624,9 @@
|
|||||||
if (responseData.status === "ok") {
|
if (responseData.status === "ok") {
|
||||||
window.location.href = '/panel/dashboard';
|
window.location.href = '/panel/dashboard';
|
||||||
} else {
|
} else {
|
||||||
|
// Close the "be patient..." dialogue box
|
||||||
|
$('.bootbox-close-button').click();
|
||||||
|
// Alert the user that there was an issue.
|
||||||
bootbox.alert({
|
bootbox.alert({
|
||||||
title: responseData.error,
|
title: responseData.error,
|
||||||
message: responseData.error_data
|
message: responseData.error_data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user