56 lines
No EOL
1.3 KiB
JavaScript
56 lines
No EOL
1.3 KiB
JavaScript
// 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();
|
|
});
|
|
}
|
|
};
|