with open('/home/creserver/Desktop/Vaishno_workspace/docs/API_DOCS_EDITOR.html') as f: text = f.read() # 1. Enhance CANDIDATES text = text.replace( "const CANDIDATES=[...new URLSearchParams(location.search).getAll('docs'),'FASTAPI_BACKEND_API_DOCS.html'", "const CANDIDATES=[...new URLSearchParams(location.search).getAll('docs'),'/docs/index.html','/docs/','FASTAPI_BACKEND_API_DOCS.html'" ) # 2. Header with session countdown pill, view docs, and logout old_header = text[text.find('
'):text.find('
')+9] new_header = """

API Docs Editor

Looking for your docs… 10:00 View Docs ↗ Log out
""" text = text.replace(old_header, new_header) # 3. Enhance save function to post to /docs/editor/save save_target = "async function save(){if(!D)return;try{const html=await buildHtml();\n if(!window.showSaveFilePicker)return download(html);" save_replacement = """async function save(){if(!D)return;try{const html=await buildHtml(); try { const resp = await fetch('/docs/editor/save', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ html }) }); if (resp.ok) { saved=JSON.stringify(D);dirty=false;saveDraft();updateUI();toast('Saved directly to server! Changes are now live in /docs/'); return; } } catch(err){console.warn('Server save error:', err);} if(!window.showSaveFilePicker)return download(html);""" text = text.replace(save_target, save_replacement) # 4. Append session countdown right before session_js = """ /* ---------- 10-Minute Session Auto-Logout ---------- */ let sessionRemaining = 600; async function checkSession(){ try { const res = await fetch('/docs/session'); if (!res.ok) { window.location.href = '/docs/editor/logout'; return; } const data = await res.json(); if (data.authenticated && typeof data.remaining_seconds === 'number') { sessionRemaining = data.remaining_seconds; updateSessionDisplay(); } else { window.location.href = '/docs/editor/logout'; } } catch(err){} } function updateSessionDisplay(){ const el = document.getElementById('timerCountdown'); const pill = document.getElementById('sessionPill'); if (!el) return; const m = Math.floor(sessionRemaining / 60); const s = sessionRemaining % 60; el.textContent = `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`; if (pill && sessionRemaining <= 60) { pill.style.borderColor = 'var(--bad)'; pill.style.color = 'var(--bad)'; } } setInterval(() => { sessionRemaining--; if (sessionRemaining <= 0) { toast('Admin session expired after 10 minutes. Logging out...'); setTimeout(() => { window.location.href = '/docs/editor/logout'; }, 600); return; } updateSessionDisplay(); }, 1000); setInterval(checkSession, 25000); checkSession(); """ text = text.replace('discover();\n', 'discover();\n' + session_js + '\n') with open('web/docs/editor.html', 'w') as f: f.write(text) print('Cleanly generated web/docs/editor.html, size:', len(text))