mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Use API v2 for jar creation and jar import
This commit is contained in:
parent
4358a78e93
commit
470ab04bb2
@ -348,12 +348,14 @@ class Controller:
|
||||
server_file = f"{create_data['type']}-{create_data['version']}.jar"
|
||||
|
||||
# Create an EULA file
|
||||
with open(
|
||||
os.path.join(new_server_path, "eula.txt"), "w", encoding="utf-8"
|
||||
) as file:
|
||||
file.write(
|
||||
"eula=" + ("true" if create_data["agree_to_eula"] else "false")
|
||||
)
|
||||
if "agree_to_eula" in create_data:
|
||||
with open(
|
||||
os.path.join(new_server_path, "eula.txt"), "w", encoding="utf-8"
|
||||
) as file:
|
||||
file.write(
|
||||
"eula="
|
||||
+ ("true" if create_data["agree_to_eula"] else "false")
|
||||
)
|
||||
elif root_create_data["create_type"] == "import_server":
|
||||
_copy_import_dir_files(create_data["existing_server_path"])
|
||||
server_file = create_data["jarfile"]
|
||||
@ -376,11 +378,41 @@ class Controller:
|
||||
def _wrap_jar_if_windows():
|
||||
return f'"{server_file}"' if Helpers.is_os_windows() else server_file
|
||||
|
||||
server_command = (
|
||||
f"java -Xms{_gibs_to_mibs(min_mem)}M "
|
||||
f"-Xmx{_gibs_to_mibs(max_mem)}M "
|
||||
f"-jar {_wrap_jar_if_windows()} nogui"
|
||||
)
|
||||
if root_create_data["create_type"] == "download_jar":
|
||||
if Helpers.is_os_windows():
|
||||
# Let's check for and setup for install server commands
|
||||
if create_data["type"] == "forge":
|
||||
server_command = (
|
||||
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
||||
f'-jar "{server_file}" --installServer'
|
||||
)
|
||||
else:
|
||||
server_command = (
|
||||
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
||||
f'-jar "{server_file}" nogui'
|
||||
)
|
||||
else:
|
||||
if create_data["type"] == "forge":
|
||||
server_command = (
|
||||
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
||||
f"-jar {server_file} --installServer"
|
||||
)
|
||||
else:
|
||||
server_command = (
|
||||
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
||||
f"-jar {server_file} nogui"
|
||||
)
|
||||
else:
|
||||
server_command = (
|
||||
f"java -Xms{_gibs_to_mibs(min_mem)}M "
|
||||
f"-Xmx{_gibs_to_mibs(max_mem)}M "
|
||||
f"-jar {_wrap_jar_if_windows()} nogui"
|
||||
)
|
||||
|
||||
elif data["create_type"] == "minecraft_bedrock":
|
||||
if root_create_data["create_type"] == "import_server":
|
||||
existing_server_path = Helpers.get_os_understandable_path(
|
||||
|
@ -29,7 +29,7 @@
|
||||
<br />
|
||||
<p class="card-description">
|
||||
|
||||
<form method="post" class="server-wizard" onSubmit="wait_msg()">
|
||||
<form method="post" id="download_jar">
|
||||
{% if data["server_api"] and data["online"] %}
|
||||
<fieldset>
|
||||
{% else %}
|
||||
@ -89,7 +89,7 @@
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label for="server_type">{{ translate('serverWizard', 'serverSelect', data['lang']) }}</label>
|
||||
<select required class="form-control form-control-lg select-css" id="server_type" name="server_type" onchange="serverTypeChange(this)">
|
||||
<select required class="form-control form-control-lg select-css" id="server_type" name="type" onchange="serverTypeChange(this)">
|
||||
<option value="">{{ translate('serverWizard', 'selectServer', data['lang']) }}</option>
|
||||
</select>
|
||||
</div>
|
||||
@ -98,7 +98,7 @@
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label for="server_version">{{ translate('serverWizard', 'serverVersion', data['lang']) }}</label>
|
||||
<select required class="form-control form-control-lg select-css" id="server" name="server">
|
||||
<select required class="form-control form-control-lg select-css" id="server" name="version">
|
||||
<option value="">{{ translate('serverWizard', 'selectVersion', data['lang']) }}</option>
|
||||
</select>
|
||||
</div>
|
||||
@ -107,7 +107,7 @@
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label for="server_name">{{ translate('serverWizard', 'serverName', data['lang']) }}</label>
|
||||
<input type="text" class="form-control" id="server_name" name="server_name" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
<input type="text" class="form-control" id="server_name" name="name" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -122,7 +122,7 @@
|
||||
<div class="form-group">
|
||||
<label for="min_memory1">{{ translate('serverWizard', 'minMem', data['lang']) }} <small> - {{
|
||||
translate('serverWizard', 'sizeInGB', data['lang']) }}</small></label>
|
||||
<input type="number" class="form-control" id="min_memory1" name="min_memory" value="1" step="0.5" min="0.5" required>
|
||||
<input type="number" class="form-control" id="min_memory1" name="mem_min" value="1" step="0.5" min="0.5" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -130,7 +130,7 @@
|
||||
<div class="form-group">
|
||||
<label for="max_memory1">{{ translate('serverWizard', 'maxMem', data['lang']) }} <small> - {{
|
||||
translate('serverWizard', 'sizeInGB', data['lang']) }}</small></label>
|
||||
<input type="number" class="form-control" id="max_memory1" name="max_memory" value="2" step="0.5" min="0.5" required>
|
||||
<input type="number" class="form-control" id="max_memory1" name="mem_max" value="2" step="0.5" min="0.5" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -197,7 +197,7 @@
|
||||
<br />
|
||||
<p class="card-description">
|
||||
|
||||
<form method="post" class="server-wizard" onSubmit="wait_msg(true)">
|
||||
<form class="server-wizard" id="jar-import">
|
||||
{% raw xsrf_form_html() %}
|
||||
<input type="hidden" value="import_jar" name="create_type">
|
||||
<div class="row">
|
||||
@ -205,7 +205,7 @@
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label for="server_name">{{ translate('serverWizard', 'serverName', data['lang']) }}</label>
|
||||
<input type="text" class="form-control" id="server_name" name="server_name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
<input type="text" class="form-control" id="server_name" name="name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -237,7 +237,7 @@
|
||||
<div class="form-group">
|
||||
<label for="min_memory2">{{ translate('serverWizard', 'minMem', data['lang']) }} <small> - {{
|
||||
translate('serverWizard', 'sizeInGB', data['lang']) }}</small></label>
|
||||
<input type="number" class="form-control" id="min_memory2" name="min_memory" value="1" step="0.5" min="0.5" required>
|
||||
<input type="number" class="form-control" id="min_memory2" name="mem_min" value="1" step="0.5" min="0.5" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -245,7 +245,7 @@
|
||||
<div class="form-group">
|
||||
<label for="max_memory2">{{ translate('serverWizard', 'maxMem', data['lang']) }} <small> - {{
|
||||
translate('serverWizard', 'sizeInGB', data['lang']) }}</small></label>
|
||||
<input type="number" class="form-control" id="max_memory2" name="max_memory" value="2" step="0.5" min="0.5" required>
|
||||
<input type="number" class="form-control" id="max_memory2" name="mem_max" value="2" step="0.5" min="0.5" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -759,7 +759,7 @@
|
||||
|
||||
{% end %}
|
||||
|
||||
{% block js%}
|
||||
{% block js %}
|
||||
|
||||
<script>
|
||||
document.getElementById("root_files_button").addEventListener("click", function () {
|
||||
@ -893,6 +893,130 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function replacer(key, value) {
|
||||
if (key != "ignored_exits") {
|
||||
if (typeof value == "boolean" || key === "host" || key === "version") {
|
||||
return value
|
||||
} else {
|
||||
return (isNaN(value) ? value : +value);
|
||||
}
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
$(document).ready(function () {
|
||||
|
||||
$("#download_jar").on("submit", async function (e) {
|
||||
wait_msg();
|
||||
e.preventDefault();
|
||||
var token = getCookie("_xsrf")
|
||||
let jarForm = document.getElementById("download_jar");
|
||||
|
||||
let formData = new FormData(jarForm);
|
||||
//Create an object from the form data entries
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"monitoring_type": "minecraft_java",
|
||||
"minecraft_java_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
"port": formDataObject.port
|
||||
},
|
||||
"create_type": "minecraft_java",
|
||||
"minecraft_java_create_data": {
|
||||
"create_type": "download_jar",
|
||||
"download_jar_create_data": {
|
||||
"category": formDataObject.version.split("|")[0],
|
||||
"type": formDataObject.version.split("|")[1],
|
||||
"version": formDataObject.version.split("|")[2],
|
||||
"mem_min": formDataObject.mem_min,
|
||||
"mem_max": formDataObject.mem_max,
|
||||
"server_properties_port": formDataObject.port
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(send_data);
|
||||
// Format the plain form data as JSON
|
||||
let formDataJsonString = JSON.stringify(send_data, replacer);
|
||||
|
||||
|
||||
console.log(formDataJsonString);
|
||||
|
||||
let res = await fetch(`/api/v2/servers/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-XSRFToken': token
|
||||
},
|
||||
body: formDataJsonString,
|
||||
});
|
||||
let responseData = await res.json();
|
||||
if (responseData.status === "ok") {
|
||||
window.location.href = '/panel/dashboard';
|
||||
} else {
|
||||
|
||||
bootbox.alert({
|
||||
title: responseData.error,
|
||||
message: responseData.error_data
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#import-jar").on("submit", async function (e) {
|
||||
wait_msg();
|
||||
e.preventDefault();
|
||||
var token = getCookie("_xsrf")
|
||||
let jarForm = document.getElementById("import-jar");
|
||||
|
||||
let formData = new FormData(jarForm);
|
||||
//Create an object from the form data entries
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"monitoring_type": "minecraft_java",
|
||||
"minecraft_java_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
"port": formDataObject.port
|
||||
},
|
||||
"create_type": "minecraft_java",
|
||||
"minecraft_java_create_data": {
|
||||
"create_type": "import_server",
|
||||
"import_server_create_data": {
|
||||
"existing_server_path": formDataObject.server_path,
|
||||
"jarfile": formDataObject.server_jar,
|
||||
"mem_min": formDataObject.mem_min,
|
||||
"mem_max": formDataObject.mem_max,
|
||||
"server_properties_port": formDataObject.port
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(send_data);
|
||||
// Format the plain form data as JSON
|
||||
let formDataJsonString = JSON.stringify(send_data, replacer);
|
||||
|
||||
let res = await fetch(`/api/v2/servers/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-XSRFToken': token
|
||||
},
|
||||
body: formDataJsonString,
|
||||
});
|
||||
let responseData = await res.json();
|
||||
if (responseData.status === "ok") {
|
||||
window.location.href = '/panel/dashboard';
|
||||
} else {
|
||||
|
||||
bootbox.alert({
|
||||
title: responseData.error,
|
||||
message: responseData.error_data
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(".tree-reset").on("click", function () {
|
||||
location.href = "/server/step1";
|
||||
|
Loading…
Reference in New Issue
Block a user