Migrate inspector and links pages to TDS lt.* APIs
Lint / Python (flake8) (push) Failing after 1m22s
Lint / JS (eslint) (push) Successful in 10s
Security / Python Security (bandit) (push) Failing after 49s
Lint / Notify on failure (push) Has been cancelled
Lint / Deploy (push) Has been cancelled
Test / Python Tests (pytest) (push) Has been cancelled

- Add escHtml alias (lt.escHtml) to both pages so existing template strings work without touching 40+ call sites
- Replace raw fetch() with lt.api.get/post in loadInspector, loadLinks, runDiagnostic, pollDiagnostic
- Replace setInterval(load*, 60000) with lt.autoRefresh.start() for intelligent polling
- Add lt.toast.error() to catch blocks for user-visible error feedback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-18 23:59:19 -04:00
parent c1c3905179
commit a17b1382bc
2 changed files with 19 additions and 31 deletions
+14 -23
View File
@@ -24,6 +24,8 @@
{% block scripts %}
<script>
const escHtml = s => lt.escHtml(s);
// ── Switch layout config ─────────────────────────────────────────────────
// keys match the model field returned by the UniFi API
// rows: array of rows, each row is an array of port_idx values
@@ -451,18 +453,17 @@ function renderInspector(data) {
// ── Fetch and render ─────────────────────────────────────────────────────
async function loadInspector() {
try {
const resp = await fetch('/api/links');
if (!resp.ok) throw new Error('API error');
const data = await resp.json();
const data = await lt.api.get('/api/links');
renderInspector(data);
} catch (e) {
document.getElementById('inspector-main').innerHTML =
'<p class="empty-state">Failed to load inspector data.</p>';
lt.toast.error('Failed to load inspector data');
}
}
loadInspector();
setInterval(loadInspector, 60000);
lt.autoRefresh.start(loadInspector, 60000);
// ── Link Diagnostics ─────────────────────────────────────────────────
let _diagPollTimer = null;
@@ -478,23 +479,14 @@ function runDiagnostic(swName, portIdx) {
statusEl.textContent = 'Submitting to Pulse...';
resultsEl.innerHTML = '';
fetch('/api/diagnose', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({switch_name: swName, port_idx: portIdx}),
})
.then(r => r.json())
.then(resp => {
if (resp.error) {
statusEl.textContent = 'Error: ' + resp.error;
return;
}
statusEl.textContent = 'Collecting diagnostics via Pulse...';
pollDiagnostic(resp.job_id, statusEl, resultsEl);
})
.catch(e => {
statusEl.textContent = 'Request failed: ' + e;
});
lt.api.post('/api/diagnose', {switch_name: swName, port_idx: portIdx})
.then(resp => {
statusEl.textContent = 'Collecting diagnostics via Pulse...';
pollDiagnostic(resp.job_id, statusEl, resultsEl);
})
.catch(e => {
statusEl.textContent = 'Error: ' + (e.message || 'Request failed');
});
}
function pollDiagnostic(jobId, statusEl, resultsEl) {
@@ -506,8 +498,7 @@ function pollDiagnostic(jobId, statusEl, resultsEl) {
statusEl.textContent = 'Timed out waiting for results.';
return;
}
fetch(`/api/diagnose/${jobId}`)
.then(r => r.json())
lt.api.get(`/api/diagnose/${jobId}`)
.then(resp => {
if (resp.status === 'done') {
clearInterval(_diagPollTimer);