MCPcopy
hub / github.com/koala73/worldmonitor / refreshTrafficLog

Function refreshTrafficLog

src/settings-main.ts:702–725  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

700 void syncVerboseState();
701
702 async function refreshTrafficLog(): Promise<void> {
703 if (!trafficLogEl) return;
704 try {
705 const res = await diagFetch('/api/local-traffic-log');
706 const data = await res.json();
707 const entries: Array<{ timestamp: string; method: string; path: string; status: number; durationMs: number }> = data.entries || [];
708 if (trafficCount) trafficCount.textContent = `(${entries.length})`;
709
710 if (entries.length === 0) {
711 trafficLogEl.innerHTML = `<p class="diag-empty">${t('modals.settingsWindow.noTraffic')}</p>`;
712 return;
713 }
714
715 const rows = entries.slice().reverse().map((e) => {
716 const ts = e.timestamp.split('T')[1]?.replace('Z', '') || e.timestamp;
717 const cls = e.status < 300 ? 'ok' : e.status < 500 ? 'warn' : 'err';
718 return `<tr class="diag-${cls}"><td>${escapeHtml(ts)}</td><td>${e.method}</td><td title="${escapeHtml(e.path)}">${escapeHtml(e.path)}</td><td>${e.status}</td><td>${e.durationMs}ms</td></tr>`;
719 }).join('');
720
721 trafficLogEl.innerHTML = `<table class="diag-table"><thead><tr><th>${t('modals.settingsWindow.table.time')}</th><th>${t('modals.settingsWindow.table.method')}</th><th>${t('modals.settingsWindow.table.path')}</th><th>${t('modals.settingsWindow.table.status')}</th><th>${t('modals.settingsWindow.table.duration')}</th></tr></thead><tbody>${rows}</tbody></table>`;
722 } catch {
723 trafficLogEl.innerHTML = `<p class="diag-empty">${t('modals.settingsWindow.sidecarUnreachable')}</p>`;
724 }
725 }
726
727 refreshBtn?.addEventListener('click', () => void refreshTrafficLog());
728

Callers 2

initDiagnosticsFunction · 0.85
startAutoRefreshFunction · 0.85

Calls 3

tFunction · 0.90
escapeHtmlFunction · 0.90
diagFetchFunction · 0.85

Tested by

no test coverage detected