mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-03 08:41:35 -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:
@@ -419,7 +419,12 @@ async function renderSmallBoxes() {
|
||||
const apiToken = getSetting("API_TOKEN");
|
||||
|
||||
const apiBaseUrl = getApiBase();
|
||||
const url = `${apiBaseUrl}/device/${getMac()}?period=${encodeURIComponent(period)}`;
|
||||
// Ensure period is a string, not an element
|
||||
let periodValue = period;
|
||||
if (typeof period === 'object' && period !== null && 'value' in period) {
|
||||
periodValue = period.value;
|
||||
}
|
||||
const url = `${apiBaseUrl}/device/${getMac()}?period=${encodeURIComponent(periodValue)}`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
@@ -553,20 +558,24 @@ function updateDevicePageName(mac) {
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
// Call renderSmallBoxes, then main
|
||||
(async () => {
|
||||
await renderSmallBoxes();
|
||||
main();
|
||||
})();
|
||||
|
||||
|
||||
window.onload = function async()
|
||||
{
|
||||
mac = getMac()
|
||||
// initializeTabs();
|
||||
updateChevrons(mac);
|
||||
updateDevicePageName(mac);
|
||||
|
||||
window.onload = function() {
|
||||
// Always trigger app-init bootstrap
|
||||
if (typeof executeOnce === 'function') {
|
||||
executeOnce();
|
||||
}
|
||||
|
||||
mac = getMac();
|
||||
|
||||
// Wait for app initialization (cache populated) before using cached data
|
||||
callAfterAppInitialized(async () => {
|
||||
updateDevicePageName(mac);
|
||||
updateChevrons(mac);
|
||||
await renderSmallBoxes();
|
||||
main();
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user