servii-backend/api_sender.html

101 lines
3.8 KiB
HTML
Raw Normal View History

2024-06-14 21:33:55 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API Interaction Form</title>
</head>
<body>
<h2>Generic Calls</h2>
<form id="genericForm">
Email: <input type="text" id="accountEmail"><br>
Port: <input type="number" id="accountPort"><br>
Name: <input type="text" id="serverName"><br>
2024-06-15 04:26:39 +00:00
Version: <input type="text" id="serverVersion"><br>
2024-06-14 21:33:55 +00:00
<button type="button" class="actionButton" data-action="AccountCreate">Create Account</button>
<button type="button" class="actionButton" data-action="AccountDelete">Delete Account</button>
<button type="button" class="actionButton" data-action="ServerCreate">Create Server</button>
<button type="button" class="actionButton" data-action="ServerDelete">Delete Server</button>
<button type="button" class="actionButton" data-action="ServerRun">Start Server</button>
<button type="button" class="actionButton" data-action="ServerStop">Stop Server</button>
</form>
<h2>Update Property</h2>
<form id="updatePropertyForm">
Property: <input type="text" id="update_property"><br>
Value: <input type="text" id="update_value"><br>
<button type="button" class="actionButton" data-action="UpdateProperty">Update Property</button>
</form>
<h2>Send Command</h2>
<form id="sendCommandForm">
Command: <input type="text" id="command"><br>
<button type="button" class="actionButton" data-action="Command">Send command</button>
</form>
<script>
document.addEventListener('DOMContentLoaded', () => {
const forms = document.querySelectorAll('form');
const buttons = document.querySelectorAll('.actionButton');
buttons.forEach(button => {
button.addEventListener('click', async event => {
const form = event.target.closest('form');
const action = button.dataset.action;
const jwt = "0";
2024-06-14 21:33:55 +00:00
const email = document.getElementById('accountEmail').value;
const port = document.getElementById('accountPort').value;
const name = document.getElementById('serverName').value;
const version = document.getElementById('serverVersion').value;
const prop = document.getElementById('update_property').value;
2024-06-14 21:33:55 +00:00
const value = document.getElementById('update_value').value;
const command = document.getElementById('command').value;
var data = {}
switch(action) {
case 'AccountCreate':
data = {email, port, jwt}
2024-06-14 21:33:55 +00:00
break;
case 'AccountDelete':
data = {email, port, jwt}
2024-06-14 21:33:55 +00:00
break;
case 'ServerCreate':
data = {port, name, version, jwt}
2024-06-14 21:33:55 +00:00
break;
case 'ServerDelete':
data = {port, name, jwt}
2024-06-14 21:33:55 +00:00
break;
case 'ServerRun':
data = {port, name, jwt}
2024-06-14 21:33:55 +00:00
break;
case 'ServerStop':
data = {port, name, jwt}
2024-06-14 21:33:55 +00:00
break;
case 'UpdateProperty':
data = {port, name, prop, value, jwt}
2024-06-14 21:33:55 +00:00
break;
case 'Command':
data = {port, name, command, jwt}
2024-06-14 21:33:55 +00:00
break;
}
sendRequest(action, data)
.then(response => response.text())
.then(data => alert(`Response: ${data}`))
.catch(error => console.error('Error:', error));
});
});
function sendRequest(endpoint, payload) {
return fetch(`http://localhost:3005/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
}
});
</script>
</body>
</html>