[V2+] api_sender.html

Signed-off-by: Charles Le Maux <charles.le-maux@epitech.eu>
This commit is contained in:
Charles Le Maux 2024-06-25 23:15:44 +01:00
parent cac649c013
commit 7704818f6f

View File

@ -18,6 +18,7 @@
<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>
</form>
<h2>Update Property</h2>
@ -33,6 +34,12 @@
<button type="button" class="actionButton" data-action="Command">Send command</button>
</form>
<h2>Set Subdomain</h2>
<form id="sendCommandForm">
Command: <input type="text" id="subdomain"><br>
<button type="button" class="actionButton" data-action="SetSubdomain">Send command</button>
</form>
<script>
document.addEventListener('DOMContentLoaded', () => {
const forms = document.querySelectorAll('form');
@ -42,6 +49,9 @@ document.addEventListener('DOMContentLoaded', () => {
button.addEventListener('click', async event => {
const form = event.target.closest('form');
const action = button.dataset.action;
const token = "gqZN3eCHF3V2er3Py3rlgk8u2t83";
const framework = "paper"
const subdomain = document.getElementById('subdomain').value;
const email = document.getElementById('accountEmail').value;
const port = document.getElementById('accountPort').value;
const name = document.getElementById('serverName').value;
@ -49,31 +59,37 @@ document.addEventListener('DOMContentLoaded', () => {
const prop = document.getElementById('update_property').value;
const value = document.getElementById('update_value').value;
const command = document.getElementById('command').value;
var data = {}
let data = {};
switch(action) {
case 'FetchServers':
data = {token};
break;
case 'AccountCreate':
data = {email, port}
data = {email, port, token};
break;
case 'AccountDelete':
data = {email, port}
data = {subdomain, port, token};
break;
case 'ServerCreate':
data = {port, name, version}
data = {port, name, version, token, framework};
break;
case 'ServerDelete':
data = {port, name}
data = {port, name, token};
break;
case 'ServerRun':
data = {port, name}
data = {port, name, token};
break;
case 'ServerStop':
data = {port, name}
data = {port, name, token};
break;
case 'UpdateProperty':
data = {port, name, prop, value}
data = {port, name, prop, value, token};
break;
case 'Command':
data = {port, name, command}
data = {port, name, command, token};
break;
case 'SetSubdomain':
data = {token, subdomain}
break;
}
sendRequest(action, data)
@ -84,7 +100,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
function sendRequest(endpoint, payload) {
return fetch(`http://localhost:3005/${endpoint}`, {
return fetch(`http://localhost:3000/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'