Initial commit: unified dashboard suite state with Khira and Image Manipulator 3-file setup
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
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('<header>'):text.find('</header>')+9]
|
||||
new_header = """<header>
|
||||
<h1>API Docs Editor</h1><span class="chip wait" id="status"><i></i><span>Looking for your docs…</span></span>
|
||||
<span class="chip" id="sessionPill" title="Security session expires in 10 minutes" style="font-family:var(--mono);font-size:12.5px;"><i style="background:var(--ok);"></i><span id="timerCountdown">10:00</span></span>
|
||||
<span class="sp"></span>
|
||||
<button class="btn" id="undo" disabled title="Undo (outside text fields)">Undo</button><button class="btn" id="redo" disabled>Redo</button>
|
||||
<button class="btn" id="pvb">Hide preview</button><button class="btn" id="dl" disabled>Download copy</button><button class="btn pri" id="save" disabled>Save Changes</button>
|
||||
<a href="/docs/" target="_blank" class="btn" style="text-decoration:none;">View Docs ↗</a>
|
||||
<a href="/docs/editor/logout" class="btn bad" style="text-decoration:none;">Log out</a>
|
||||
</header>"""
|
||||
|
||||
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 </script>
|
||||
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</script>', 'discover();\n' + session_js + '\n</script>')
|
||||
|
||||
with open('web/docs/editor.html', 'w') as f:
|
||||
f.write(text)
|
||||
|
||||
print('Cleanly generated web/docs/editor.html, size:', len(text))
|
||||
Reference in New Issue
Block a user