wip
This commit is contained in:
parent
2b36992be1
commit
25087d055c
16 changed files with 1394 additions and 816 deletions
56
app/static/js/api-functions.js
Normal file
56
app/static/js/api-functions.js
Normal 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();
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue