This commit is contained in:
pika 2025-04-03 16:58:01 +02:00
parent 2b36992be1
commit 25087d055c
16 changed files with 1394 additions and 816 deletions

View file

@ -0,0 +1,56 @@
// API Functions for reuse across the application
const apiFunctions = {
// Create a new location
createLocation: function (name, description, csrfToken) {
return fetch('/api/locations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({
name: name,
description: description
})
})
.then(response => {
if (!response.ok) {
throw new Error('Failed to create location');
}
return response.json();
});
},
// Create a new subnet
createSubnet: function (cidr, locationId, autoScan, csrfToken) {
return fetch('/api/subnets', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({
cidr: cidr,
location_id: locationId,
auto_scan: autoScan
})
})
.then(response => {
if (!response.ok) {
throw new Error('Failed to create subnet');
}
return response.json();
});
},
// Get all subnets
getSubnets: function () {
return fetch('/api/subnets')
.then(response => {
if (!response.ok) {
throw new Error('Failed to load subnets');
}
return response.json();
});
}
};