// Admin (Marty): status, the review queue (approve = transplant, reject), held packets (link check yellow / red, reports), the export // for the CTB builder / DownlineHydra, a link recheck, and the staging-only test-member switch. The token stays in this tab only. (function () { const $ = YPB.$, esc = YPB.esc; let tok = ''; try { tok = sessionStorage.getItem('ypb.admin') || ''; } catch (e) {} $('tok').value = tok; const api = (url, body) => fetch(url, body ? { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: JSON.stringify(body) } : { headers: { 'x-admin-token': tok } }).then(r => r.json()); function row(x, acts) { const chk = x.check ? x.check.state + (x.check.why && x.check.why.length ? ': ' + x.check.why.join('; ') : '') : 'not checked'; return '
No. ' + esc(x.no) + ' ' + esc(x.name) + '' + esc(x.status) + ' / ' + esc(x.stage) + ' / ' + x.saves + ' of ' + x.need + ' saves
' + '

' + esc(x.desc) + '

' + esc(x.url) + ' (planter ID ' + esc(x.ownerId || '') + ', @' + esc(x.planter || '?') + ')

' + '

Link check: ' + esc(chk) + (x.flags && x.flags.length ? ' | flags: ' + esc(x.flags.join(', ')) : '') + (x.heldWhy ? ' | held: ' + esc(x.heldWhy) : '') + '

' + (x.reports && x.reports.length ? '

Reports: ' + x.reports.map(r => esc(r.reason + (r.note ? ' (' + r.note + ')' : '') + ' by ' + r.by)).join('; ') + '

' : '') + '
' + acts.map(a => '').join('') + '
'; } async function load() { try { sessionStorage.setItem('ypb.admin', tok); } catch (e) {} const s = await api('/api/admin/status'); if (s.error) { YPB.status('Wrong token.', 'err'); return; } YPB.status('', ''); $('aStats').innerHTML = [['Shown', s.packets.shown], ['Held', s.packets.held], ['In review', s.packets.review], ['Transplanted', s.packets.approved], ['Dormant', s.packets.dormant], ['Saved IDs', s.saves], ['Members', s.members], ['Old links', s.oldrefs]].map(v => '
' + YPB.n(v[1]) + '' + v[0] + '
').join(''); $('aRaw').textContent = JSON.stringify({ config: s.config, shop: s.shop, hub: s.hub, hubLookup: s.hubLookup, sso: s.sso, linkspin: s.linkspin, docstore: s.docstore, adWriter: s.adWriter }, null, 1); $('testBox').hidden = !s.testSwitch; const q = await api('/api/admin/queue'); $('qReview').innerHTML = q.review.length ? q.review.map(x => row(x, ['approve', 'reject', 'hold', 'remove'])).join('') : '

Nothing in review.

'; $('qHeld').innerHTML = q.held.length ? q.held.map(x => row(x, ['show', 'recheck', 'remove'])).join('') : '

Nothing held.

'; $('qApproved').innerHTML = q.approved.length ? q.approved.map(x => row(x, ['reopen'])).join('') : '

Nothing transplanted yet.

'; document.querySelectorAll('[data-act]').forEach(b => { b.onclick = async () => { b.disabled = true; const note = (document.querySelector('[data-note="' + b.dataset.id + '"]') || {}).value || ''; const r = await api('/api/admin/packet', { id: Number(b.dataset.id), action: b.dataset.act, note }); YPB.status(r.error || 'Done: ' + b.dataset.act, r.error ? 'err' : 'ok'); load(); }; }); } $('go').onclick = () => { tok = $('tok').value.trim(); load(); }; $('recheck').onclick = async () => { const r = await api('/api/admin/recheck', { max: 50 }); YPB.status(r.error || 'Rechecked ' + r.checked + ' packets.', r.error ? 'err' : 'ok'); load(); }; $('exportBtn').onclick = async e => { e.preventDefault(); const r = await api('/api/admin/export?all=1'); const blob = new Blob([JSON.stringify(r, null, 1)], { type: 'application/json' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'ypb-transplants-' + new Date().toISOString().slice(0, 10) + '.json'; a.click(); }; $('tGo').onclick = async () => { const r = await api('/api/admin/test-member', { address: $('tAddr').value.trim(), username: $('tName').value.trim() || undefined }); YPB.status(r.error || 'Marked ' + r.member.address + ' as a test network member.', r.error ? 'err' : 'ok'); }; if (tok) load(); })();