servii-backend/api_sender.html

114 lines
4.6 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: <label for="accountEmail"></label><input type="text" id="accountEmail"><br>
Port: <label for="accountPort"></label><input type="number" id="accountPort"><br>
Name: <label for="serverName"></label><input type="text" id="serverName"><br>
Version: <label for="serverVersion"></label><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>
<button type="button" class="actionButton" data-action="FetchServers">Fetch Servers</button>
2024-06-14 21:33:55 +00:00
</form>
<h2>Update Property</h2>
<form id="updatePropertyForm">
Property: <label for="update_property"></label><input type="text" id="update_property"><br>
Value: <label for="update_value"></label><input type="text" id="update_value"><br>
2024-06-14 21:33:55 +00:00
<button type="button" class="actionButton" data-action="UpdateProperty">Update Property</button>
</form>
<h2>Send Command</h2>
<form id="sendCommandForm">
Command: <label for="command"></label><input type="text" id="command"><br>
2024-06-14 21:33:55 +00:00
<button type="button" class="actionButton" data-action="Command">Send command</button>
</form>
<h2>Set Subdomain</h2>
<form id="sendCommandForm">
Command: <label for="subdomain"></label><input type="text" id="subdomain"><br>
<button type="button" class="actionButton" data-action="SetSubdomain">Send command</button>
</form>
2024-06-14 21:33:55 +00:00
<script>
document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('.actionButton');
buttons.forEach(button => {
button.addEventListener('click', async event => {
const action = button.dataset.action;
const token = "CJal6RJnc7Po2vxdj3DYVhrHZQL2";
const framework = "paper";
const subdomain = document.getElementById('subdomain').value;
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;
let data = {};
2024-06-14 21:33:55 +00:00
switch(action) {
case 'FetchServers':
data = {token};
break;
2024-06-14 21:33:55 +00:00
case 'AccountCreate':
data = {email, port, token};
2024-06-14 21:33:55 +00:00
break;
case 'AccountDelete':
data = {subdomain, port, token};
2024-06-14 21:33:55 +00:00
break;
case 'ServerCreate':
data = {port, name, version, token, framework};
2024-06-14 21:33:55 +00:00
break;
case 'ServerDelete':
data = {port, name, token};
2024-06-14 21:33:55 +00:00
break;
case 'ServerRun':
data = {port, name, token};
2024-06-14 21:33:55 +00:00
break;
case 'ServerStop':
data = {port, name, token};
2024-06-14 21:33:55 +00:00
break;
case 'UpdateProperty':
data = {port, name, prop, value, token};
2024-06-14 21:33:55 +00:00
break;
case 'Command':
data = {port, name, command, token};
break;
case 'SetSubdomain':
data = {token, subdomain}
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:3000/${endpoint}`, {
2024-06-14 21:33:55 +00:00
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
}
});
</script>
</body>
</html>