Files
webworthit/public/assets/admin.js
T
martbost 47de249a8b Free check partly gated behind joining the network (Marty 2026-11-16)
Not signed in: grade, verdict, first finding and the opinion line; the rest (scores, findings,
chain facts, screenshot, evidence) stays on the server. Join or sign in by one-time email link
(hub /v1/join with the wwi.ref sponsor when HUB_JOIN=1; staging reads only). 1 free check a day
without an account, 3 for members. Red flags deduped (deterministic VERIFIED one kept), grade
recomputed on read. Privacy: joining and emails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 11:36:29 -06:00

45 lines
9.0 KiB
JavaScript

// Admin: checks (cost, timings, publish to "Network, checked"), test purchases with the sponsor line that would be paid,
// voucher codes (create, disable, redemptions), and an admin-run check for our own contracts. The token stays in this browser.
(function () {
'use strict';
var $ = WWI.$, esc = WWI.esc, tok = '';
try { tok = sessionStorage.getItem('wwi.admin') || ''; } catch (e) {}
function api(path, body) {
return fetch(path, { method: body ? 'POST' : 'GET', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: body ? JSON.stringify(body) : undefined }).then(function (r) { return r.json(); });
}
var ct = function (t) { return t ? new Date(Number(t)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : ''; };
function load() {
api('/api/admin/overview').then(function (j) {
if (j.error) { $('out').innerHTML = '<div class="notice">' + esc(j.error) + '</div>'; return; }
$('tok').classList.add('hide');
var h = '<div class="card"><span class="t">Totals</span><span class="b">' + j.cost.n + ' checks, OpenRouter cost $' + Number(j.cost.usd || 0).toFixed(4) + '. Hub sign-in ' + (j.sso ? 'on' : 'off') + '. Ad zones: ' + (Object.keys(j.zones || {}).length ? esc(JSON.stringify(j.zones)) : 'none set (WWI_ZONES)') + '.</span></div>';
h += '<div class="card"><span class="t">Run a check (admin, no limit)</span><div style="display:flex;gap:8px;flex-wrap:wrap"><input id="aAddr" class="code" placeholder="0x... contract" style="flex:2 1 300px"><input id="aSite" class="code" placeholder="https://website (optional)" style="flex:1 1 200px"><select id="aChain" class="code"><option value="polygon">Polygon</option><option value="bsc">BNB Chain</option><option value="eth">Ethereum</option><option value="base">Base</option></select><select id="aKind" class="code"><option value="deep">deep</option><option value="free">free</option></select><input id="aLabel" class="code" placeholder="public label (optional)"><label><input id="aPub" type="checkbox"> public</label><button id="aRun" class="btn dark" type="button">Run</button></div><span id="aMsg" class="b"></span></div>';
h += '<div class="card"><span class="t">Checks</span><span class="b">Tick Public to show a check on "Network, checked"; the label comes from this box: <input id="pubLabel" class="code" placeholder="public label, e.g. Viral Banner Blitz"></span><div class="tblwrap"><table class="t"><thead><tr><th>When</th><th>Kind</th><th>What</th><th>Status</th><th>Model</th><th>Cost</th><th>Time</th><th>Public</th></tr></thead><tbody>' + j.checks.map(function (c) {
var tm = c.timings_json ? JSON.parse(c.timings_json) : null;
return '<tr><td>' + ct(c.created) + '</td><td>' + esc(c.kind) + '</td><td><a href="/c/' + esc(c.id) + '" target="_blank">' + esc(c.website || '') + ' ' + esc(WWI.short(c.address) || '') + ' ' + esc(c.chain || '') + '</a>' + (c.error ? '<br><span style="color:var(--acc2)">' + esc(c.error.slice(0, 160)) + '</span>' : '') + '</td><td>' + esc(c.status) + (c.status !== 'done' ? ' (' + esc(c.step || '') + ')' : '') + '</td><td>' + esc(c.model || '') + '</td><td>$' + Number(c.cost_usd || 0).toFixed(4) + '</td><td>' + (tm ? Math.round(tm.total_s) + ' s' : '') + '</td>'
+ '<td><label><input type="checkbox" data-pub="' + esc(c.id) + '"' + (c.is_public ? ' checked' : '') + '> ' + esc(c.public_label || '') + '</label></td></tr>';
}).join('') + '</tbody></table></div></div>';
h += '<div class="card"><span class="t">Join and sign-in links (no email is sent while MAIL_URL is unset)</span><div class="tblwrap"><table class="t"><thead><tr><th>When</th><th>Email</th><th>Ref</th><th>Opt-in</th><th>Back to</th><th>Status</th><th>Hub</th></tr></thead><tbody>' + (j.joins || []).map(function (x) {
return '<tr><td>' + ct(x.created) + '</td><td>' + esc(x.email) + '</td><td>' + esc(x.ref || '') + '</td><td>' + (x.optin ? 'yes' : 'no') + '</td><td>' + esc(x.to_path || '') + '</td><td>' + esc(x.status) + (x.mailed ? ', mailed' : '') + '</td><td>' + esc(x.hub_result || '') + '</td></tr>';
}).join('') + '</tbody></table></div></div>';
h += '<div class="card"><span class="t">Test purchases and the sponsor line (nothing paid in staging)</span><div class="tblwrap"><table class="t"><thead><tr><th>When</th><th>Buyer</th><th>Item</th><th>Via</th><th>Ref</th><th>Line source</th><th>Would pay</th><th>Company</th></tr></thead><tbody>' + j.purchases.map(function (p) {
var s = p.split || {}; var l = p.line || {};
return '<tr><td>' + ct(p.at) + '</td><td>' + esc(p.buyer_username ? '@' + p.buyer_username : p.buyer || 'visitor') + '</td><td>' + esc(p.item) + ' $' + Number(p.usd).toFixed(2) + '</td><td>' + esc(p.via) + '</td><td>' + esc(p.ref || '') + '</td><td>' + esc(l.source || '') + (l.ok === false ? ' (hub partial)' : '') + '<br><span style="font-size:12px">' + (l.line || []).map(function (x) { return (x.username ? '@' + esc(x.username) : esc(WWI.short(x.wallet) || '?')) + (x.qualified ? ' (bought)' : ' (passed over)'); }).join(' &gt; ') + '</span></td><td>'
+ (s.levels || []).map(function (x) { return 'L' + x.level + ' ' + x.pct + '% $' + Number(x.usd).toFixed(2) + ' ' + (x.username ? '@' + esc(x.username) : 'company'); }).join('<br>') + (s.note ? '<br><i>' + esc(s.note) + '</i>' : '') + '</td><td>$' + Number(s.company || 0).toFixed(2) + '</td></tr>';
}).join('') + '</tbody></table></div></div>';
h += '<div class="card"><span class="t">Vouchers</span><div style="display:flex;gap:8px;flex-wrap:wrap"><input id="pCode" class="code" placeholder="CODE (blank = random)"><select id="pKind" class="code"><option value="deep">deep reports</option><option value="free">extra free checks</option></select><input id="pAmt" class="code" type="number" min="1" value="1" style="width:90px" title="amount per redemption"><input id="pMax" class="code" type="number" min="1" value="1" style="width:110px" title="max uses"><input id="pExp" class="code" type="date" title="expires"><label><input id="pOnce" type="checkbox" checked> once per person</label><input id="pNote" class="code" placeholder="note: who it was given to" style="flex:1 1 220px"><button id="pMake" class="btn dark" type="button">Create</button></div><span id="pMsg" class="b"></span>'
+ '<div class="tblwrap"><table class="t"><thead><tr><th>Code</th><th>Gives</th><th>Uses</th><th>Expires</th><th>Note</th><th></th></tr></thead><tbody>' + j.promos.map(function (p) {
return '<tr><td class="mono">' + esc(p.code) + '</td><td>' + p.amount + ' ' + (p.kind === 'deep' ? 'deep' : 'free') + '</td><td>' + p.uses + ' / ' + p.max_uses + (p.per_holder_once ? ' (once each)' : '') + '</td><td>' + (p.expires ? ct(p.expires) : '') + '</td><td>' + esc(p.note || '') + '</td><td><button class="btn line" type="button" data-dis="' + esc(p.code) + '" data-en="' + (p.disabled ? 1 : 0) + '">' + (p.disabled ? 'Enable' : 'Disable') + '</button></td></tr>';
}).join('') + '</tbody></table></div>'
+ '<span class="t" style="font-size:16px">Redemptions</span><div class="tblwrap"><table class="t"><thead><tr><th>When</th><th>Code</th><th>Holder</th><th>Gave</th></tr></thead><tbody>' + j.redemptions.map(function (r) { return '<tr><td>' + ct(r.at) + '</td><td class="mono">' + esc(r.code) + '</td><td>' + esc(String(r.holder).replace(/^t:(.{6}).*/, 'browser $1...')) + '</td><td>' + r.amount + ' ' + esc(r.kind) + '</td></tr>'; }).join('') + '</tbody></table></div></div>';
$('out').innerHTML = h;
$('aRun').addEventListener('click', function () { api('/api/admin/check', { address: $('aAddr').value.trim(), website: $('aSite').value.trim(), chain: $('aChain').value, kind: $('aKind').value, label: $('aLabel').value.trim(), public: $('aPub').checked }).then(function (r) { $('aMsg').innerHTML = r.id ? 'Started: <a href="/c/' + r.id + '" target="_blank">' + r.id + '</a>' : esc(r.error); }); });
$('pMake').addEventListener('click', function () { api('/api/admin/promo', { code: $('pCode').value.trim(), kind: $('pKind').value, amount: $('pAmt').value, maxUses: $('pMax').value, expires: $('pExp').value || null, perHolderOnce: $('pOnce').checked, note: $('pNote').value }).then(function (r) { $('pMsg').textContent = r.ok ? 'Created ' + r.code : r.error; if (r.ok) setTimeout(load, 600); }); });
document.querySelectorAll('[data-dis]').forEach(function (b) { b.addEventListener('click', function () { api('/api/admin/promo/disable', { code: b.getAttribute('data-dis'), enable: b.getAttribute('data-en') === '1' }).then(load); }); });
document.querySelectorAll('[data-pub]').forEach(function (b) { b.addEventListener('change', function () { var label = b.checked ? $('pubLabel').value.trim() : ''; api('/api/admin/publish', { id: b.getAttribute('data-pub'), public: b.checked, label: label }).then(load); }); });
});
}
$('save').addEventListener('click', function () { tok = $('token').value.trim(); try { sessionStorage.setItem('wwi.admin', tok); } catch (e) {} load(); });
if (tok) load();
})();