// 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 => '
' + esc(x[1]) + '' + esc(x[0]) + '
').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 ? '' + l.members.map(m => '').join('') + '
MemberCyclesViews
' + esc(who(m)) + '' + m.cycles + '' + VBB.n(m.views) + '
' : '

No cycles yet.

'; $('aLedger').innerHTML = l.entries && l.entries.length ? '' + l.entries.map(e => '').join('') + '
When (CT)EntryBannerMemberViewsStatus
' + esc(new Date(e.at).toLocaleString('en-US', { timeZone: 'America/Chicago' })) + '' + esc(e.id) + '#' + e.bannerId + '' + esc(who(e)) + '' + VBB.n(e.views) + '' + esc(e.status) + '
' : '

The ledger is empty.

'; } $('tokBtn').onclick = () => { tok = $('tok').value.trim(); open(); }; $('tok').addEventListener('keydown', e => { if (e.key === 'Enter') $('tokBtn').click(); }); if (tok) open(); })();