* Save credentials for a target
()
| 20644 | const previousList = wifiInterfaceMetadata || []; |
| 20645 | let previousSlug = null; |
| 20646 | if (selectedWifiInterface) { |
| 20647 | const prevMeta = Array.isArray(previousList) |
| 20648 | ? previousList.find(entry => entry && entry.name === selectedWifiInterface) |
| 20649 | : null; |
| 20650 | if (prevMeta) { |
| 20651 | previousSlug = prevMeta.network_slug || (prevMeta.connected_ssid ? slugifyNetworkIdentifier(prevMeta.connected_ssid) : null); |
| 20652 | } |
| 20653 | } |
| 20654 | |
| 20655 | wifiInterfaceMetadata = entries ? normalizeInterfaceMetadata(entries) : []; |
| 20656 | |
| 20657 | if (selectedWifiInterface) { |
| 20658 | const nextMeta = wifiInterfaceMetadata.find(entry => entry && entry.name === selectedWifiInterface); |
| 20659 | const nextSlug = nextMeta ? (nextMeta.network_slug || (nextMeta.connected_ssid ? slugifyNetworkIdentifier(nextMeta.connected_ssid) : null)) : null; |
| 20660 | if (previousSlug !== nextSlug) { |
| 20661 | clearDashboardStatsCache(); |
| 20662 | refreshDashboardStatsForCurrentSelection({ forceRefresh: true }).catch(err => { |
| 20663 | console.debug('Dashboard stats refresh failed after interface metadata update', err); |
| 20664 | }); |
| 20665 | } |
| 20666 | } |
| 20667 | } |
| 20668 | |
| 20669 | function clearDashboardStatsCache() { |
| 20670 | dashboardStatsCache = { key: null, timestamp: 0, data: null }; |
| 20671 | } |
| 20672 | |
| 20673 | async function fetchDashboardStatsForSelection(options = {}) { |
| 20674 | const { forceRefresh = false } = options; |
| 20675 | const { network } = getSelectedDashboardNetworkKey(); |
| 20676 | const cacheKey = network ? `network:${network}` : 'network:global'; |
| 20677 | const now = Date.now(); |
| 20678 | |
| 20679 | const cached = dashboardStatsCache; |
| 20680 | if (!forceRefresh && cached.key === cacheKey && (now - cached.timestamp) < DASHBOARD_STATS_CACHE_TTL && cached.data) { |
| 20681 | return cached.data; |
| 20682 | } |
| 20683 | |
| 20684 | if (!forceRefresh && dashboardStatsRequestState && dashboardStatsRequestState.key === cacheKey) { |
| 20685 | return dashboardStatsRequestState.promise; |
| 20686 | } |
| 20687 | |
| 20688 | const query = network ? `/api/dashboard/stats?network=${encodeURIComponent(network)}` : '/api/dashboard/stats'; |
| 20689 | const requestPromise = (async () => { |
| 20690 | try { |
| 20691 | const payload = await fetchAPI(query); |
| 20692 | dashboardStatsCache = { key: cacheKey, timestamp: Date.now(), data: payload }; |
| 20693 | return payload; |
| 20694 | } finally { |
| 20695 | if (dashboardStatsRequestState && dashboardStatsRequestState.key === cacheKey) { |
| 20696 | dashboardStatsRequestState = null; |
| 20697 | } |
| 20698 | } |
| 20699 | })(); |
| 20700 | |
| 20701 | dashboardStatsRequestState = { key: cacheKey, promise: requestPromise }; |
| 20702 | return requestPromise; |
| 20703 | } |
nothing calls this directly
no test coverage detected