Send message to front end when system fails to download bedrock server

This commit is contained in:
Adam Plante 2024-10-02 19:06:16 +00:00
parent 37b8a4fa16
commit a73db62b24
4 changed files with 32 additions and 11 deletions

View File

@ -132,22 +132,29 @@ class Helpers:
target_linux = (
'https://www.minecraft.net/bedrockdedicatedserver/bin-linux/[^"]*'
)
try:
# Get minecraft server download page
# (hopefully the don't change the structure)
download_page = get(url, headers=headers, timeout=1)
download_page.raise_for_status()
# Search for our string targets
win_download_url = re.search(target_win, download_page.text).group(0)
linux_download_url = re.search(target_linux, download_page.text).group(0)
win_search_result = re.search(target_win, download_page.text)
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":
return win_download_url
return linux_download_url
except Exception as e:
logger.error(f"Unable to resolve remote bedrock download url! \n{e}")
raise e
return False
def get_execution_java(self, value, execution_command):

View File

@ -217,15 +217,16 @@ class ImportHelpers:
FileHelpers.del_dirs(temp_dir)
def download_bedrock_server(self, path, new_id):
bedrock_url = Helpers.get_latest_bedrock_url()
download_thread = threading.Thread(
target=self.download_threaded_bedrock_server,
daemon=True,
args=(path, new_id),
args=(path, new_id, bedrock_url),
name=f"{new_id}_download",
)
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.
@ -236,10 +237,8 @@ class ImportHelpers:
This method handles exceptions and logs errors for each step of the process.
"""
try:
bedrock_url = Helpers.get_latest_bedrock_url()
if bedrock_url:
file_path = os.path.join(path, "bedrock_server.zip")
success = FileHelpers.ssl_get_file(
bedrock_url, path, "bedrock_server.zip"
)
@ -263,6 +262,7 @@ class ImportHelpers:
logger.critical(
f"Failed to download bedrock executable during server creation! \n{e}"
)
raise e
ServersController.finish_import(new_id)
server_users = PermissionsServers.get_server_user_list(new_id)

View File

@ -725,7 +725,19 @@ class ApiServersIndexHandler(BaseApiHandler):
405, {"status": "error", "error": "DATA CONSTRAINT FAILED"}
)
return
new_server_id = self.controller.create_api_server(data, user["user_id"])
try:
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()

View File

@ -624,7 +624,9 @@
if (responseData.status === "ok") {
window.location.href = '/panel/dashboard';
} else {
// Close the "be patient..." dialogue box
$('.bootbox-close-button').click();
// Alert the user that there was an issue.
bootbox.alert({
title: responseData.error,
message: responseData.error_data
@ -783,4 +785,4 @@
</script>
<script type="text/javascript" src="../../static/assets/js/shared/root-dir.js"></script>
<script src="../../static/assets/js/shared/bootstrap-select-1.13.18.js"></script>
{% end %}
{% end %}