9d0dde4b57
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
2.4 KiB
JavaScript
26 lines
2.4 KiB
JavaScript
// Admin: status + the cycle reward ledger, read with the ADMIN_TOKEN (kept in this tab only).
|
|
(function () {
|
|
VBB.renderNav('');
|
|
const $ = VBB.$, esc = VBB.esc;
|
|
let tok = ''; try { tok = sessionStorage.getItem('vbb.admin') || ''; } catch (e) {}
|
|
const get = u => VBB.getJSON(u, { headers: { 'x-admin-token': tok } });
|
|
async function open() {
|
|
const s = await get('/api/admin/status');
|
|
if (s.error) { VBB.status('That token was not accepted.', 'err'); return; }
|
|
try { sessionStorage.setItem('vbb.admin', tok); } catch (e) {}
|
|
$('tokCard').hidden = true; $('adm').hidden = false; VBB.status('');
|
|
$('aStats').innerHTML = [['Loop filled', s.loop.filled + ' / ' + s.loop.size], ['Waiting', s.queue.length], ['Next shift', s.progress + ' / ' + s.config.perShift + (s.held ? ' (held)' : '')],
|
|
['Shifts today', s.today.shifts], ['Cycles today', s.today.cycles], ['Visitors today', s.today.visits], ['Cycles total', s.totals.cycles], ['Views recorded', VBB.n(s.ledger.views)], ['Views credited', VBB.n(s.ledger.credited)], ['Members', s.members]]
|
|
.map(x => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
|
|
$('aRaw').textContent = JSON.stringify(s, null, 2);
|
|
const l = await get('/api/admin/ledger?n=300');
|
|
const who = r => r.username ? '@' + r.username : VBB.short(r.address || r.owner);
|
|
$('aMembers').innerHTML = l.members && l.members.length ? '<table class="t"><tr><th>Member</th><th class="n">Cycles</th><th class="n">Views</th></tr>' + l.members.map(m => '<tr><td>' + esc(who(m)) + '</td><td class="n">' + m.cycles + '</td><td class="n">' + VBB.n(m.views) + '</td></tr>').join('') + '</table>' : '<p class="muted">No cycles yet.</p>';
|
|
$('aLedger').innerHTML = l.entries && l.entries.length ? '<table class="t"><tr><th>When (CT)</th><th>Entry</th><th>Banner</th><th>Member</th><th class="n">Views</th><th>Status</th></tr>'
|
|
+ l.entries.map(e => '<tr><td>' + esc(new Date(e.at).toLocaleString('en-US', { timeZone: 'America/Chicago' })) + '</td><td class="mono">' + esc(e.id) + '</td><td>#' + e.bannerId + '</td><td>' + esc(who(e)) + '</td><td class="n">' + VBB.n(e.views) + '</td><td>' + esc(e.status) + '</td></tr>').join('') + '</table>' : '<p class="muted">The ledger is empty.</p>';
|
|
}
|
|
$('tokBtn').onclick = () => { tok = $('tok').value.trim(); open(); };
|
|
$('tok').addEventListener('keydown', e => { if (e.key === 'Enter') $('tokBtn').click(); });
|
|
if (tok) open();
|
|
})();
|