// 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 '
' + 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('; ') + '
' : '') + '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(); })();