def20f8ffe
adwriter.js: the server reads the member's page (or follows their LinkSpin spin link, max 5 hops),
SSRF-safe (http/https, ports 80/443, every hop's DNS answer checked and the connection pinned to it,
no private/loopback/link-local/metadata address, 8 s, 1.5 MB, text/html only), extracts title, meta
and og description, h1-h3 and the first paragraphs (about 2,500 tokens), and asks OpenRouter
deepseek/deepseek-v4-flash (reasoning off; fallback anthropic/claude-haiku-5.5) for 3 options
{headline <= 60, line <= 90} written only from the page. Every option goes through the new
safety.checkAdCopy (no dashes, income promises, guarantees, links, shouting; every number must be
on the page) plus the length limits; failing ones are dropped, one retry when none survive. The
member picks one, it fills the form, nothing is posted.
Limits: AI_AD_DAILY (5) per member per Central day, AI_AD_GLOBAL_DAILY (500), 12 an hour per IP,
one at a time, a 24 h cache by page (a repeat is free). Off and hidden without AI_AD_KEY (a dedicated
OpenRouter key, $5 a month). Admin status: writes today, tokens, estimated spend.
safety.privateIp: IPv4-mapped IPv6 in hex form (::ffff:7f00:1) and all of fe80::/10 now count as private.
Chatbot fact added (KNOWLEDGE_DATE 2026-11-17). Server wiring + form markup landed in 828abce.
qa/adwriter.test.mjs 82/82, qa/e2e.mjs 63/63, qa/chatbot.test.mjs 108/108.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
3.2 KiB
JavaScript
25 lines
3.2 KiB
JavaScript
// Admin: status, the L2 sign-up checks (release / reject / recheck), the pending-rewards ledger, and (staging only) the test-member switch.
|
|
// The token stays in this tab only (sessionStorage).
|
|
(function () {
|
|
const $ = VAS.$, esc = VAS.esc;
|
|
let tok = ''; try { tok = sessionStorage.getItem('vas.admin') || ''; } catch (e) {}
|
|
const H = () => ({ 'x-admin-token': tok, 'Content-Type': 'application/json' });
|
|
const api = (p, body) => VAS.getJSON(p, body ? { method: 'POST', headers: H(), body: JSON.stringify(body) } : { headers: H() });
|
|
async function load() {
|
|
if (!tok) return;
|
|
const s = await api('/api/admin/status'); $('statusOut').textContent = JSON.stringify(s, null, 2); $('testBox').hidden = !s.testSwitch;
|
|
{ const w = s.adWriter || {}; $('aiOut').textContent = 'AI ad writer: ' + (w.on ? 'on' : 'off (no AI_AD_KEY)') + '. Today (' + (w.day || '') + ' Central): ' + (w.writes || 0) + ' writes by ' + (w.members || 0) + ' members, ' + (w.cacheHits || 0) + ' free repeats, ' + (w.failed || 0) + ' failed, ' + (w.tokensIn || 0) + ' + ' + (w.tokensOut || 0) + ' tokens, estimated spend $' + Number(w.costUsd || 0).toFixed(4) + ' (key cap ' + (w.keyLimit || '') + ').'; }
|
|
const su = await api('/api/admin/signups');
|
|
$('suRows').innerHTML = (su.signups || []).map(x => '<tr><td class="mono">' + esc(x.id) + '</td><td>' + esc(x.status) + '</td><td>' + esc(x.email) + (x.confirmLink ? '<br><a href="' + esc(x.confirmLink) + '">staging confirm link</a>' : '') + '</td><td>' + esc(x.resharer || '')
|
|
+ '</td><td style="font-size:12px">' + esc(JSON.stringify(x.checks || {})) + (x.fail.length ? '<br><b>fail:</b> ' + esc(x.fail.join(', ')) : '') + (x.hold.length ? '<br><b>hold:</b> ' + esc(x.hold.join(', ')) : '')
|
|
+ '</td><td><button class="btn sm" data-a="release" data-id="' + esc(x.id) + '">Release</button> <button class="btn sm" data-a="reject" data-id="' + esc(x.id) + '">Reject</button> <button class="btn sm" data-a="recheck" data-id="' + esc(x.id) + '">Recheck</button></td></tr>').join('') || '<tr><td colspan="6" class="muted">none</td></tr>';
|
|
const rw = await api('/api/admin/rewards');
|
|
$('rwRows').innerHTML = (rw.rewards || []).map(r => '<tr><td class="mono">' + esc(r.id) + '</td><td>' + esc(r.toName || r.to) + '</td><td>' + esc(r.kind) + '</td><td>' + esc(r.cents) + '</td><td>' + esc(r.status)
|
|
+ '</td><td class="mono" style="font-size:12px">' + (r.voucher ? 'signed, nonce ' + esc(String(r.voucher.nonce).slice(0, 10)) + '...' : esc(r.note || '')) + '</td></tr>').join('') || '<tr><td colspan="6" class="muted">none</td></tr>';
|
|
}
|
|
document.addEventListener('click', async e => { const b = e.target.closest('button[data-a]'); if (!b) return; const r = await api('/api/admin/signup', { id: b.dataset.id, action: b.dataset.a }); if (r.error) VAS.status(r.error, 'err'); load(); });
|
|
$('go').onclick = () => { tok = $('tok').value.trim(); try { sessionStorage.setItem('vas.admin', tok); } catch (x) {} load(); };
|
|
$('tGo').onclick = async () => { const r = await api('/api/admin/test-member', { address: $('tAddr').value.trim(), username: $('tName').value.trim() || undefined }); VAS.status(r.error || 'Marked as a test member.', r.error ? 'err' : 'ok'); };
|
|
load();
|
|
})();
|