mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-04 09:11:34 -07:00
Refactor network API calls to use centralized authentication context and improve cache handling
- Removed redundant getApiToken function and replaced its usage with getAuthContext in network-api.js, network-events.js, and network-init.js. - Updated cache handling in network-events.js and network-init.js to use CACHE_KEYS constants for better maintainability. - Introduced cache.js for centralized cache management functions and constants, including cache initialization and retrieval. - Added app-init.js for application lifecycle management, including cache orchestration and initialization checks. - Created app_config.php to securely fetch API token and GraphQL port from configuration. - Improved error handling and logging throughout the codebase for better debugging and maintenance.
This commit is contained in:
@@ -12,8 +12,8 @@ var showOffline = false;
|
||||
*/
|
||||
function initNetworkTopology() {
|
||||
networkDeviceTypes = getSetting("NETWORK_DEVICE_TYPES").replace("[", "").replace("]", "");
|
||||
showArchived = getCache('showArchived') === "true";
|
||||
showOffline = getCache('showOffline') === "true";
|
||||
showArchived = getCache(CACHE_KEYS.SHOW_ARCHIVED) === "true";
|
||||
showOffline = getCache(CACHE_KEYS.SHOW_OFFLINE) === "true";
|
||||
|
||||
console.log('showArchived:', showArchived);
|
||||
console.log('showOffline:', showOffline);
|
||||
@@ -33,8 +33,7 @@ function initNetworkTopology() {
|
||||
FROM Devices a
|
||||
`;
|
||||
|
||||
const apiBase = getApiBase();
|
||||
const apiToken = getApiToken();
|
||||
const { token: apiToken, apiBase, authHeader } = getAuthContext();
|
||||
|
||||
// Verify token is available before making API call
|
||||
if (!apiToken || apiToken.trim() === '') {
|
||||
@@ -51,7 +50,7 @@ function initNetworkTopology() {
|
||||
$.ajax({
|
||||
url,
|
||||
method: "POST",
|
||||
headers: { "Authorization": `Bearer ${apiToken}` },
|
||||
headers: { ...authHeader, "Content-Type": "application/json" },
|
||||
data: JSON.stringify({ rawSql: btoa(unescape(encodeURIComponent(rawSql))) }),
|
||||
contentType: "application/json",
|
||||
success: function(data) {
|
||||
@@ -121,7 +120,7 @@ function initNetworkTopology() {
|
||||
}
|
||||
});
|
||||
|
||||
setCache('devicesListNew', JSON.stringify(devicesSorted));
|
||||
setCache(CACHE_KEYS.DEVICES_TOPOLOGY, JSON.stringify(devicesSorted));
|
||||
deviceListGlobal = devicesSorted;
|
||||
|
||||
// Render filtered result
|
||||
|
||||
Reference in New Issue
Block a user