Check server creation for clone server call

This commit is contained in:
amcmanu3 2024-02-19 18:07:17 -05:00
parent 1211b22183
commit e053f4a750
2 changed files with 23 additions and 18 deletions

View File

@ -30,7 +30,11 @@ class ApiServersServerActionHandler(BaseApiHandler):
return self.finish_json(400, {"status": "error", "error": "NOT_AUTHORIZED"})
if action == "clone_server":
if self.controller.crafty_perms.can_create_server(auth_data[4]["user_id"]):
return self._clone_server(server_id, auth_data[4]["user_id"])
return self.finish_json(
200, {"status": "error", "error": "SERVER_LIMIT_REACHED"}
)
if action == "eula":
return self._agree_eula(server_id, auth_data[4]["user_id"])

View File

@ -598,26 +598,27 @@
</script>
<script>
function send_command(server_id, command) {
async function send_command(server_id, command) {
/* this getCookie function is in base.html */
const token = getCookie("_xsrf");
$.ajax({
type: "POST",
headers: { 'X-XSRFToken': token },
url: `/api/v2/servers/${server_id}/action/${command}`,
success: function (data) {
console.log("got response:");
console.log(data);
if (command === "clone_server" && data.status === "ok") {
window.location.reload();
}
/*setTimeout(function () {
if (command != 'start_server') {
location.reload();
}
}, 10000);*/
}
let res = await fetch(`/api/v2/servers/${server_id}/action/${command}`, {
method: 'POST',
headers: {
'token': token,
},
});
let responseData = await res.json();
if (responseData.status === "ok") {
if (command === "clone_server"){
window.location.reload()
}
console.log("Command received successfully")
} else {
bootbox.alert({
title: responseData.status,
message: responseData.error
});
}
}