One swap per banner + admin takedown (Marty 2026-11-15: "allow the member to swap it only, and they can only do it one time. Admin takes down the option to credit back or none.")

Member swap: My Banners shows "Swap image or link" on a banner that is waiting or in the loop, usable once (then "Swap used"). POST /api/my/banners/<id>/swap changes the image and/or link (or a Banner Spin to another of the member's own 125x125/250x250 spins via lsspins), same checks as a new post (checkLink, probeLink, upload/https image checks); id, place, clicks and loop progress stay. Logged on the banner (swaps: old/new image + link, time). No withdraw, removal or refund for members.

Admin takedown: /admin finds banners (#id, wallet, username), POST /api/admin/banners/<id>/takedown {reason required, credit: back|none}. The banner is hidden at once (splash loop + waiting line show a house tile in its place, /go goes home, no look/teaser/swap); its place rides out on time so nobody moves, then it ends with no cycle, no network views, no prize count. My Banners shows "Taken down" with the reason. Restore reverses a given credit (when the owner still holds one) and, if its place rode out meanwhile, records the cycle then. Admin ledger: GET /api/admin/actions (who, when, reason, credit decision).

Chatbot: CANNED 'swap' + FACTS line (KNOWLEDGE_DATE already 2026-11-15), chat-qa entry. my.js?v=4, admin.js?v=3, vbb.css?v=8.
Tests: smoke section 15 (swap once, refused twice, keeps place, bad link/image refused, spin swap, takedown credit back vs none, others keep places, ride-out without a cycle, restore, admin ledger, phone UI): 308/308 with the committed networksso.js; chatbot.test 182/182; qa:chain 49/49.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 15:18:49 -06:00
parent 666cdd9569
commit 8e6d2f9cd0
11 changed files with 409 additions and 28 deletions
+5 -1
View File
@@ -5,7 +5,7 @@
// ad views per cycle recorded but not credited yet, 6 s visit, 3 browsers per connection a day, 1 free post credit a day for network
// members, 3 banners waiting per member, packs 10 for $3 and 40 for $10, banner look $2), ../contracts VBBShop (SPONSOR_BPS 3000,
// PRIZE_BPS 1000, company the rest, sponsor bound once by voucher, no owner withdraw, failed sends claimable), server.js (100 KB
// image, 125x125, Banner Spin posting 125x125 or 250x250), lsspins.js (SPIN tiles in empty places never shift, cycle or earn),
// image, 125x125, Banner Spin posting 125x125 or 250x250, one swap per banner and the admin takedown, 2026-11-15), lsspins.js (SPIN tiles in empty places never shift, cycle or earn),
// public/how.html, packages.html, leaders.html. The prize pot's floor and cap are internal and never shown (Marty's rule).
// HOUSE RULE: when a feature changes, update CANNED and FACTS in the same commit and bump KNOWLEDGE_DATE.
// Plain words, no em dashes, never a promise of income, "SafePal or any other crypto wallet", never RM Circle.
@@ -36,6 +36,9 @@ const CANNED = [
{ id: 'free-credit', title: 'Free post credits', q: ['How do I get a free post credit?', 'Is posting free?', 'Why did I not get my free credit?'], tags: ['free credit', 'post credit', 'daily', 'network member'],
re: /(free (post )?credits?|post credits?|is (it|posting) free|daily credit|credit (a|per|each) day)/i,
a: 'Network members (anyone with an InstantAdPay or LinkSpin account) get one free post credit each day they sign in, Central time. Each credit posts one banner into the loop. Want to post more? Credit packs are one-time purchases: ' + packs + '. You can have up to ' + C.maxQueuedPerMember + ' banners waiting at once.' },
{ id: 'swap', title: 'Changing a banner after posting (one swap)', q: ['Can I change my banner image or link?', 'I posted the wrong link. Can I fix it?', 'Can I remove my banner?', 'Why was my banner taken down?'], tags: ['swap', 'change banner', 'edit', 'wrong link', 'remove', 'taken down'],
re: /((swap|change|edit|replace|update|fix|correct)\b.{0,24}\b(banners?|image|picture|link|url)|wrong (link|image|banner|url|picture)|\btypo\b|(remove|delete|withdraw|take down|pull) (my |a |the )?banners?|banners?.{0,20}taken down)/i,
a: 'Each banner can be swapped one time. On My Banners (' + URL_ + '/my), a banner that is waiting or in the loop has a "Swap image or link" button: put in a new image, a new link, or both (a Banner Spin can swap to another of your own 125x125 or 250x250 spins). The banner keeps its place, its clicks and its progress through the loop, and the new image and link get the same checks as a new post. After that one swap the button is gone. Members cannot withdraw or remove a posted banner, and post credits are not refunded. A banner that breaks the rules can be taken down by the admin; its owner sees the reason on My Banners.' },
{ id: 'post', title: 'Posting a banner', q: ['How do I post a banner?', 'What size is the banner?', 'Can I use a Banner Spin?'], tags: ['post', 'banner', '125x125', 'image', 'link', 'banner spin'],
re: /(post (a |my )?banner|banner size|what size|125 ?x ?125|upload|image|banner spin|my banners)/i,
a: 'On My Banners (' + URL_ + '/my) upload a 125x125 image (100 KB or less) with your link, or post one of your LinkSpin Banner Spins (125x125 or 250x250). It uses one post credit, waits in line, and enters the loop at the front at the next shift. Your link must be a real page that loads.' },
@@ -81,6 +84,7 @@ const FACTS = () => [
'- WHAT IT IS: Viral Banner Blitz (' + URL_ + ') is one public loop of ' + C.loopSize + ' member banners (125x125 tiles). A posted banner waits in line, then enters at the front. Every ' + C.perShift + ' verified visitors shift every banner one place; the banner at the end rides out (has cycled) and its owner earns ' + C.viewsPerCycle + ' network ad views. Cycles are recorded on My Banners now; crediting those views to network advertising is NOT switched on yet.',
'- VERIFIED VISITOR: a real browser keeps the loop page open and visible about ' + C.visitSeconds + ' seconds; once per visitor per 24 hours; bots, crawlers, repeats and more than ' + C.perIpDay + ' browsers per connection per day do not count.',
'- POSTING: one post credit per banner. Network members (InstantAdPay or LinkSpin, checked with the network hub) get 1 free post credit each day they sign in (Central day). Up to ' + C.maxQueuedPerMember + ' banners waiting per member. Image 125x125, 100 KB max, or post a LinkSpin Banner Spin (125x125 or 250x250). The link must answer. SPIN tiles in empty places are LinkSpin Banner Spins: they never shift, cycle or earn.',
'- ONE SWAP PER BANNER: a banner that is waiting or in the loop can swap its image and/or link ONE time from My Banners (a Banner Spin to another of the member\'s own 125x125/250x250 spins). It keeps its id, place, clicks and loop progress; the new image and link get the same checks as a new post. No second swap. Members cannot withdraw or remove a banner and credits are not refunded. The admin can take a banner down (the owner sees the reason; the admin decides whether the post credit comes back); its place stays as a house tile until it would have ridden out, so nobody else moves, and it never cycles or earns.',
'- PACKAGES (one-time, POL at the live price, never a subscription, overpayment returned): ' + packs + '; banner look $' + C.lookUsd + ' per banner (border + hover teaser, on a waiting or in-loop banner, one per banner); tokens (network visits at the InstantAdPay visit rate) coming soon.',
'- SPLIT (VBBShop constants, no owner withdraw): 30% to the member who introduced the buyer (bound once, by a keeper-signed voucher, on the first purchase; none = company), 10% to the weekly prize pot, 60% company, same transaction. Failed sends wait in the contract for their owner to claim.',
'- LEADERBOARDS (Monday to Sunday Central): most verified visitors sent (the member\'s ?ref= link) and most different traffic sources (referring sites). Prize pot = 10% of the week\'s sales, half per board, top three ' + places + ' percent, paid in POL to the winners\' VBB wallets the following Monday at the POL price at payout; ties to whoever got there first. Never state a maximum or a cap.',
+17 -3
View File
@@ -23,10 +23,16 @@ function enter(id) {
}
function cycleOut(id) {
const b = store.banner(id); if (!b) return null;
// taken down by the admin (Marty 2026-11-15): its place rode out on time, but it never cycles and never earns
if (b.down) { b.state = 'ended'; b.endedAt = Date.now(); store.saveBanner(b); return null; }
b.state = 'cycled'; b.cycledAt = Date.now(); store.saveBanner(b);
return recordCycle(b);
}
// the cycle reward: one ledger row (also used when the admin restores a banner whose place rode out while it was taken down)
function recordCycle(b, extra) {
const S = store.state(); S.totals.cycles++; S.totals.views += C().viewsPerCycle; store.bump('cycles');
const m = store.member(b.owner);
const e = store.addLedger({ bannerId: b.id, owner: b.owner, username: (m && m.username) || null, views: C().viewsPerCycle, day: store.ctDay(), status: 'recorded' });
const e = store.addLedger(Object.assign({ bannerId: b.id, owner: b.owner, username: (m && m.username) || null, views: C().viewsPerCycle, day: store.ctDay(), status: 'recorded' }, extra || {}));
if (onCycle) try { onCycle(b, e); } catch (x) {}
return e;
}
@@ -118,7 +124,9 @@ function memberWeek(addr) {
// ---- views for pages ----
// the banner look (bought per banner, SKU 3): a highlighted border and a hover teaser (the member's line, else the link's site)
const hostOf = l => { try { return new URL(l).hostname.replace(/^www\./, ''); } catch (e) { return ''; } };
function tile(b) { const m = store.member(b.owner); const t = { id: b.id, img: b.img, href: '/go/' + b.id, owner: (m && m.username) ? '@' + m.username : null };
// a banner the admin took down keeps its place (nobody else moves) but shows as a house tile: no image, owner, link or id of its own
const houseTile = b => ({ id: 'h' + b.id, house: true, img: '/art/tile-house.svg', href: '/my', owner: null });
function tile(b) { if (b.down) return houseTile(b); const m = store.member(b.owner); const t = { id: b.id, img: b.img, href: '/go/' + b.id, owner: (m && m.username) ? '@' + m.username : null };
if (b.spin) t.spin = true;
if (b.look) { t.look = true; t.teaser = b.teaser || (b.spin && b.spin.name) || hostOf(b.link); } return t; }
function view(queueShow) {
@@ -135,5 +143,11 @@ function placeOf(b) {
if (b.state === 'loop') { const i = S.loop.indexOf(b.id); return { state: 'loop', place: i + 1, of: C().loopSize, shiftsToRideOut: Math.max(1, C().loopSize - i) }; }
return { state: b.state };
}
// a member-facing place: a taken-down banner says so (with the admin's reason), whatever its slot is doing
function memberPlace(b) {
const p = placeOf(b);
if (!b.down) return p;
return { state: 'down', slot: p.state, downAt: b.down.at, downReason: b.down.reason, creditBack: !!b.down.creditBack };
}
module.exports = { hostOf, init, post, shift, verifiedVisit, canCount, rebuildIndex, leaders, memberWeek, view, placeOf, normalize };
module.exports = { hostOf, init, post, shift, verifiedVisit, canCount, rebuildIndex, leaders, memberWeek, view, placeOf, memberPlace, recordCycle, normalize };
+5 -2
View File
@@ -22,7 +22,7 @@
<meta name="theme-color" content="#ffd400">
<link rel="icon" type="image/svg+xml" href="/art/mark.svg"><link rel="icon" type="image/png" href="/art/icon-192.png"><link rel="apple-touch-icon" href="/art/icon-192.png">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,700;12..96,800&family=DM+Sans:wght@400;500;700&family=Space+Mono:wght@400;700&display=swap">
<link rel="stylesheet" href="/assets/vbb.css?v=7">
<link rel="stylesheet" href="/assets/vbb.css?v=8">
</head>
<body>
<main class="wrap">
@@ -31,13 +31,16 @@
<div id="adm" hidden>
<div class="card"><h2>Status</h2><div class="stats" id="aStats"></div><pre class="mono small scroll" id="aRaw" style="white-space:pre-wrap;max-height:320px"></pre></div>
<div class="card" id="pzCard"><h2>Weekly prize payouts</h2><p class="muted small">Each Monday after midnight (Central) the app prepares last week's payout. Nothing is sent until you approve it here, and a week is paid once. Amounts in POL are quoted live and fixed when you approve.</p><div id="pzNow"></div><div id="pzWeeks"></div><div class="row"><button class="btn sec small" id="pzPrep">Prepare last week again</button></div></div>
<div class="card" id="bnCard"><h2>Banners: take down or restore</h2><p class="muted small">Find a banner by #id, wallet or username. A takedown hides it everywhere at once; its loop place stays (a house tile shows there) until it would have ridden out, so nobody else moves. It never cycles, never earns network views and never counts for prizes. The reason is shown to the owner. Every takedown and restore goes in the admin ledger below.</p>
<div class="share"><input id="bnQ" placeholder="#12, 0x... or username" autocomplete="off" aria-label="Find a banner"><button class="btn sec small" id="bnFind">Find</button></div><div id="bnList"></div></div>
<div class="card"><h2>Admin ledger (takedowns and restores)</h2><div class="scroll" id="aActions"></div></div>
<div class="card"><h2>Rewards by member</h2><div class="scroll" id="aMembers"></div></div>
<div class="card"><h2>Ledger (newest first)</h2><div class="scroll" id="aLedger"></div></div>
</div>
<div id="status" class="note" hidden></div>
</main>
<script src="/assets/common.js?v=9"></script>
<script src="/assets/admin.js?v=2"></script>
<script src="/assets/admin.js?v=3"></script>
<script src="/assets/chat.js?v=2" defer></script>
</body>
</html>
+8
View File
@@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 125 125" width="125" height="125">
<rect width="125" height="125" fill="#ffd400"/>
<g fill="#ff2d87" opacity=".18"><circle cx="15" cy="15" r="5"/><circle cx="45" cy="15" r="5"/><circle cx="75" cy="15" r="5"/><circle cx="105" cy="15" r="5"/><circle cx="30" cy="110" r="5"/><circle cx="60" cy="110" r="5"/><circle cx="90" cy="110" r="5"/><circle cx="120" cy="110" r="5"/></g>
<text x="62.5" y="50" fill="#14121f" font-family="sans-serif" font-size="13" font-weight="800" text-anchor="middle">Viral Banner</text>
<text x="62.5" y="66" fill="#14121f" font-family="sans-serif" font-size="13" font-weight="800" text-anchor="middle">Blitz</text>
<rect x="22" y="76" width="81" height="20" rx="10" fill="#ff2d87" stroke="#14121f" stroke-width="2"/>
<text x="62.5" y="90" fill="#fff" font-family="sans-serif" font-size="11" font-weight="700" text-anchor="middle">Post yours</text>
</svg>

After

Width:  |  Height:  |  Size: 944 B

+51 -1
View File
@@ -13,7 +13,7 @@
['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 => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
$('aRaw').textContent = JSON.stringify(s, null, 2);
prizes(); setInterval(prizes, 30000);
prizes(); setInterval(prizes, 30000); actions();
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 ? '<table class="t"><tr><th>Member</th><th class="n">Cycles</th><th class="n">Views</th></tr>' + l.members.map(m => '<tr><td>' + esc(who(m)) + '</td><td class="n">' + m.cycles + '</td><td class="n">' + VBB.n(m.views) + '</td></tr>').join('') + '</table>' : '<p class="muted">No cycles yet.</p>';
@@ -57,6 +57,56 @@
const r = await VBB.getJSON('/api/admin/prizes/prepare', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: '{}' });
VBB.status(r.error || 'Prepared the week of ' + r.week + '.', r.error ? 'err' : 'ok'); prizes();
};
// ---- banner takedown / restore (Marty 2026-11-15): reason required, credit back or none; restore takes a given credit back ----
const send = (u, body) => VBB.getJSON(u, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: JSON.stringify(body) });
const ct = t => t ? new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago' }) + ' CT' : '';
async function actions() {
const a = await get('/api/admin/actions?n=200'); if (a.error) return;
$('aActions').innerHTML = a.actions.length ? '<table class="t"><tr><th>When (CT)</th><th>Action</th><th>Banner</th><th>Owner</th><th>By</th><th>Reason</th><th>Credit</th></tr>'
+ a.actions.map(e => '<tr><td>' + esc(ct(e.at)) + '</td><td>' + esc(e.action) + (e.cycleRecorded ? ' (cycle recorded)' : '') + '</td><td>#' + e.bannerId + '</td><td>' + esc(e.username ? '@' + e.username : VBB.short(e.owner)) + '</td><td>' + esc(e.by) + '</td><td>' + esc(e.reason || '') + '</td><td>' + esc(e.credit) + '</td></tr>').join('') + '</table>'
: '<p class="muted">No takedowns yet.</p>';
}
async function findBanners() {
const q = $('bnQ').value.trim(); if (!q) return;
const d = await get('/api/admin/banners?q=' + encodeURIComponent(q));
if (d.error) { $('bnList').innerHTML = '<p class="note err small">' + esc(d.error) + '</p>'; return; }
$('bnList').innerHTML = '';
for (const b of d.banners) {
const el = document.createElement('div'); el.className = 'adm-b';
const st = b.down ? 'TAKEN DOWN ' + ct(b.down.at) + ' by ' + b.down.by + ': ' + b.down.reason + (b.down.creditBack ? ' (credit given back)' : ' (no credit)') + '. Slot: ' + b.state
: b.state === 'queued' ? 'Waiting #' + b.position + ' of ' + b.of : b.state === 'loop' ? 'In the loop, place ' + b.place + ' of ' + b.of : b.state;
el.innerHTML = '<img alt="Banner #' + b.id + '" width="72" height="72"><div class="s"><b>#' + b.id + '</b> ' + esc(b.username ? '@' + b.username : '') + ' <span class="mono small">' + esc(b.owner) + '</span><br>'
+ esc(st) + '<br>Link: <span class="mono small">' + esc(b.link) + '</span><br><span class="muted small">' + VBB.n(b.clicks) + ' clicks. Posted ' + esc(ct(b.createdAt)) + '.'
+ (b.swaps.length ? ' Swapped ' + esc(ct(b.swaps[0].at)) + ' from ' + esc(b.swaps[0].old.link) + '.' : '') + (b.downs.length ? ' Restored before: ' + b.downs.length + 'x.' : '') + '</span><div class="act"></div></div>';
el.querySelector('img').src = b.img;
const act = el.querySelector('.act');
if (b.down) {
act.innerHTML = '<div class="field"><label>Why restore (optional)</label><input class="rs"></div><button class="btn small">Restore this banner' + (b.down.creditBack ? ' (takes the credit back)' : '') + '</button>';
act.querySelector('button').onclick = async () => {
const r = await send('/api/admin/banners/' + b.id + '/restore', { reason: act.querySelector('.rs').value });
VBB.status(r.error || ('Banner #' + b.id + ' restored.' + (r.creditReversed ? ' The credit was taken back.' : r.creditAlreadyUsed ? ' The owner already used the credit, so it was not taken back.' : '') + (r.cycle ? ' Its place had ridden out, so its cycle is recorded now.' : '')), r.error ? 'err' : 'ok');
findBanners(); actions();
};
} else if (b.state === 'queued' || b.state === 'loop') {
act.innerHTML = '<div class="field"><label>Reason (the owner sees it)</label><textarea class="why" maxlength="300"></textarea></div>'
+ '<div class="row"><label class="small"><input type="radio" name="cr' + b.id + '" value="back"> Credit back</label><label class="small"><input type="radio" name="cr' + b.id + '" value="none"> No credit</label>'
+ '<button class="btn small">Take down</button></div>';
const bt = act.querySelector('button');
bt.onclick = async () => {
const reason = act.querySelector('.why').value.trim(); const c = act.querySelector('input[type=radio]:checked');
if (reason.length < 3) return VBB.status('Write the reason first.', 'err');
if (!c) return VBB.status('Choose credit back or no credit.', 'err');
if (!bt.dataset.armed) { bt.dataset.armed = '1'; bt.textContent = 'Click again to take down #' + b.id; setTimeout(() => { if (bt.isConnected) { delete bt.dataset.armed; bt.textContent = 'Take down'; } }, 8000); return; }
const r = await send('/api/admin/banners/' + b.id + '/takedown', { reason, credit: c.value });
VBB.status(r.error || ('Banner #' + b.id + ' taken down' + (c.value === 'back' ? ', credit given back.' : ', no credit.')), r.error ? 'err' : 'ok');
findBanners(); actions();
};
}
$('bnList').appendChild(el);
}
}
$('bnFind').onclick = findBanners;
$('bnQ').addEventListener('keydown', e => { if (e.key === 'Enter') findBanners(); });
$('tokBtn').onclick = () => { tok = $('tok').value.trim(); open(); };
$('tok').addEventListener('keydown', e => { if (e.key === 'Enter') $('tokBtn').click(); });
if (tok) open();
+61 -6
View File
@@ -68,11 +68,65 @@
};
$('copyBtn').onclick = () => { $('share').select(); try { navigator.clipboard.writeText($('share').value); } catch (e) { document.execCommand('copy'); } VBB.status('Link copied.', 'ok'); };
const where = b => b.state === 'queued' ? '<span class="pill queued">Waiting</span><br>Number ' + b.position + ' of ' + b.of + ' in line'
const when = t => new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT';
const where = b => b.state === 'down' ? '<span class="pill down">Taken down</span><br>Reason: ' + esc(b.downReason) + '<br><span class="muted">'
+ (b.creditBack ? 'Your post credit was given back.' : 'The post credit was not given back.') + ' It no longer shows anywhere.</span>'
: b.state === 'queued' ? '<span class="pill queued">Waiting</span><br>Number ' + b.position + ' of ' + b.of + ' in line'
: b.state === 'loop' ? '<span class="pill loop">In the loop</span><br>Place ' + b.place + ' of ' + b.of + ', rides out in about ' + b.shiftsToRideOut + ' shift' + (b.shiftsToRideOut === 1 ? '' : 's')
: '<span class="pill cycled">Cycled</span><br>' + (b.cycledAt ? new Date(b.cycledAt).toLocaleString() : '');
// banner look (SKU 3): buy it for a banner that is waiting or in the loop; with the look, edit its hover teaser
let buying = false, editing = false;
let buying = false, editing = false, swapping = false;
// one swap per banner (Marty 2026-11-15): new image and/or link, or another of your Banner Spins. Same checks as a new post.
function swapRow(row, b) {
if (b.swapUsed) { row.innerHTML = '<span class="muted small">Swap used' + (b.swappedAt ? ' on ' + esc(when(b.swappedAt)) : '') + '. Each banner can be swapped once.</span>'; return; }
if (!b.canSwap) return;
row.innerHTML = '<button class="btn sec small">Swap image or link</button>';
row.querySelector('button').onclick = () => openSwap(row, b);
}
function openSwap(row, b) {
swapping = true; let up = ''; const item = row.closest('.item'); if (item) item.classList.add('swapping');
row.innerHTML = '<div class="swap-box"><p class="small"><b>Swap banner #' + b.id + '</b> (one time only). It keeps its place, clicks and progress. Leave a field empty to keep what it has'
+ (b.spin ? '; a Banner Spin swaps to another Banner Spin, or to your own image and link together' : '') + '.</p>'
+ '<div class="field"><label>New image address (https), or upload a file</label><input class="sw-img" placeholder="https://your-site.com/banner.png" autocomplete="off"></div>'
+ '<div class="row"><label class="btn sec small">Upload image<input type="file" class="sw-file" accept="image/png,image/jpeg,image/gif" hidden></label><span class="muted small sw-note"></span></div>'
+ '<div class="field"><label>New target link (https)</label><input class="sw-link" placeholder="https://your-site.com/page" autocomplete="off"></div>'
+ '<div class="row"><button class="btn small sw-go">Swap now</button><button class="btn sec small sw-spin">Use another Banner Spin</button><button class="btn quiet small sw-x">Cancel</button></div><div class="sw-pick"></div></div>';
const q = k => row.querySelector(k);
q('.sw-img').addEventListener('input', () => { up = ''; q('.sw-note').textContent = ''; });
q('.sw-file').addEventListener('change', async e => {
const f = e.target.files[0]; if (!f) return;
if (f.size > 100 * 1024) { VBB.status('That file is ' + Math.ceil(f.size / 1024) + ' KB. The limit is 100 KB.', 'err'); return; }
q('.sw-note').textContent = 'Uploading...';
const r = await VBB.getJSON('/api/my/upload', { method: 'POST', headers: { 'Content-Type': 'application/octet-stream' }, body: f });
e.target.value = '';
if (r.error) { q('.sw-note').textContent = ''; VBB.status(r.error, 'err'); return; }
up = r.img; q('.sw-img').value = ''; q('.sw-note').textContent = 'Uploaded: ' + f.name; VBB.status('');
});
const send = async body => {
row.querySelectorAll('button').forEach(x => { x.disabled = true; }); VBB.status('Checking the new image and link...');
const r = await VBB.post('/api/my/banners/' + b.id + '/swap', body);
if (r.error) { VBB.status(r.error, 'err'); row.querySelectorAll('button').forEach(x => { x.disabled = false; }); return; }
swapping = false; VBB.status('Swapped. Banner #' + b.id + ' keeps its place and now shows the new ' + (body.spinId != null ? 'Banner Spin' : 'image and link') + '.', 'ok'); load();
};
q('.sw-go').onclick = () => {
const img = up || q('.sw-img').value.trim(), link = q('.sw-link').value.trim();
if (!img && !link) return VBB.status('Add a new image, a new link, or both.', 'err');
send({ img, link });
};
q('.sw-x').onclick = () => { swapping = false; if (item) item.classList.remove('swapping'); swapRow(row, b); };
q('.sw-spin').onclick = async () => {
const pick = q('.sw-pick'); pick.innerHTML = '<p class="small muted">Looking up your LinkSpin Banner Spins...</p>';
const d = await VBB.getJSON('/api/my/lsspins');
if (d.error) { pick.innerHTML = '<p class="note err small">' + esc(d.error) + '</p>'; return; }
const list = (d.spins || []).filter(sp => sp.banners && !sp.paused);
if (!d.account || !list.length) { pick.innerHTML = '<p class="small">No 125x125 (or 250x250) Banner Spin with images on your LinkSpin account yet.</p>'; return; }
pick.innerHTML = '<p class="small muted">Tap a Banner Spin to swap to it.</p><div class="row"></div>';
for (const sp of list) {
const bt = document.createElement('button'); bt.className = 'btn sec small'; bt.textContent = sp.name + ' (' + sp.size + ')';
bt.onclick = () => send({ spinId: sp.id }); pick.querySelector('.row').appendChild(bt);
}
};
}
function lookRow(row, b) {
if (b.look) {
row.innerHTML = '<span class="pill look">Banner look</span><input maxlength="40" aria-label="Hover teaser for banner #' + b.id + '"><button class="btn sec small">Save teaser</button>';
@@ -97,12 +151,12 @@
}
const shopLive = !!(c.shop && c.shop.live);
async function load() {
if (buying || editing) return;
if (buying || editing || swapping) return;
const d = await VBB.getJSON('/api/my');
if (d.error) return VBB.status(d.error, 'err');
$('dash').hidden = false;
$('me').textContent = d.username ? '@' + d.username + ' (' + VBB.short(d.address) + ')' : d.address;
const live = d.banners.filter(b => b.state !== 'cycled').length, cyc = d.banners.filter(b => b.state === 'cycled').length;
const live = d.banners.filter(b => b.state === 'queued' || b.state === 'loop').length, cyc = d.banners.filter(b => b.state === 'cycled').length;
$('stats').innerHTML = [['Post credits', d.credits], ['Banners waiting or in the loop', live], ['Banners cycled', cyc], ['Network ad views earned', VBB.n(d.rewardViews)]]
.map(x => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
$('creditNote').textContent = !d.netVerified ? 'Free daily credits are for network members. Sign in through InstantAdPay or LinkSpin, or make a free InstantAdPay account with this wallet, and your free credit arrives each day you sign in. You can have up to ' + d.maxQueued + ' banners waiting at once.' : (d.grantedNow ? 'Your free credit for today was just added. ' : d.freeToday ? 'Today\'s free credit is in. ' : '')
@@ -112,10 +166,11 @@
$('mine').innerHTML = d.banners.length ? '' : '<p class="muted">No banners yet. Post your first one above.</p>';
for (const b of d.banners) {
const el = document.createElement('div'); el.className = 'item';
el.innerHTML = '<img alt="Banner #' + b.id + '" width="72" height="72"><div class="s">' + where(b) + '<br><a target="_blank" rel="noopener"></a><br><span class="muted">' + VBB.n(b.clicks) + ' clicks</span><div class="look-row"></div></div>';
el.innerHTML = '<img alt="Banner #' + b.id + '" width="72" height="72"><div class="s">' + where(b) + '<br><a target="_blank" rel="noopener"></a><br><span class="muted">' + VBB.n(b.clicks) + ' clicks</span><div class="look-row"></div><div class="swap-row"></div></div>';
el.querySelector('img').src = b.img; const a = el.querySelector('a'); a.href = b.link; a.textContent = b.link.replace(/^https:\/\//, '').slice(0, 60);
if (b.spin) { a.removeAttribute('href'); a.textContent = 'LinkSpin Banner Spin: ' + b.spin.name; a.insertAdjacentHTML('beforebegin', '<span class="pill spin">Banner Spin</span> '); }
lookRow(el.querySelector('.look-row'), b);
if (b.state === 'down') { el.classList.add('down'); a.removeAttribute('href'); }
else { lookRow(el.querySelector('.look-row'), b); swapRow(el.querySelector('.swap-row'), b); }
$('mine').appendChild(el);
}
$('share').value = d.share;
+12
View File
@@ -185,3 +185,15 @@ footer.foot .netline b{color:#fff} footer.foot .netline .here{color:#fff;font-we
.toast.buy{background:var(--amber-soft)} .toast.prize{background:var(--ok-soft)}
.legal .card h2{font-size:21px} .legal .card p,.legal .card li{max-width:760px} .legal .card ul{padding-left:20px} .legal .card li{margin:6px 0}
#facts th{font:700 11.5px var(--mono);letter-spacing:.06em;text-transform:uppercase;vertical-align:top}
/* one-time swap + admin takedown (2026-11-15) */
.pill.down{background:#14121f;color:#fff}
.mine .item.down{opacity:.7}.mine .item.down img{filter:grayscale(1)}
.mine .item .swap-row{margin-top:6px}
.swap-box{background:var(--panel);border:2px solid var(--ink);border-radius:10px;padding:10px;margin-top:4px}
.swap-box .field input{width:100%}
.swap-box .row{flex-wrap:wrap;gap:6px}
.adm-b{display:flex;gap:12px;align-items:flex-start;border:var(--edge);border-radius:12px;padding:10px;margin:10px 0;background:var(--bg2);flex-wrap:wrap}
.adm-b img{width:72px;height:72px;border:2px solid var(--ink);border-radius:8px;object-fit:cover;flex:none}
.adm-b .s{flex:1;min-width:220px;font-size:13.5px;word-break:break-all}
.adm-b textarea{width:100%;min-height:54px;font:14px var(--body);border:var(--edge);border-radius:8px;padding:8px}
.mine .item.swapping{flex-wrap:wrap;align-items:flex-start}.mine .item.swapping .s{flex:1 1 100%}
+3 -3
View File
@@ -22,7 +22,7 @@
<meta name="theme-color" content="#ffd400">
<link rel="icon" type="image/svg+xml" href="/art/mark.svg"><link rel="icon" type="image/png" href="/art/icon-192.png"><link rel="apple-touch-icon" href="/art/icon-192.png">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,700;12..96,800&family=DM+Sans:wght@400;500;700&family=Space+Mono:wght@400;700&display=swap">
<link rel="stylesheet" href="/assets/vbb.css?v=7">
<link rel="stylesheet" href="/assets/vbb.css?v=8">
</head>
<body>
<main class="wrap">
@@ -65,7 +65,7 @@
</div>
</div>
<div class="card"><h2>Your banners</h2><p class="muted small">Add the banner look to any banner that is waiting or in the loop: a bright border, plus a teaser line that shows when someone points at it. One-time, per banner.</p><div class="mine" id="mine"></div></div>
<div class="card"><h2>Your banners</h2><p class="muted small">Add the banner look to any banner that is waiting or in the loop: a bright border, plus a teaser line that shows when someone points at it. One-time, per banner.</p><p class="muted small">Need to fix a banner? Each banner that is waiting or in the loop can swap its image or link one time. It keeps its place in the loop.</p><div class="mine" id="mine"></div></div>
<div class="card">
<h2>Your link</h2>
@@ -81,7 +81,7 @@
<script src="/assets/common.js?v=9"></script>
<script src="/assets/wallet.js?v=2"></script>
<script src="/assets/buy.js?v=1"></script>
<script src="/assets/my.js?v=3"></script>
<script src="/assets/my.js?v=4"></script>
<script src="/assets/chat.js?v=2" defer></script>
</body>
</html>
+1
View File
@@ -9,6 +9,7 @@
{ "q": "Are the 150 views added to my advertising yet?", "kb": "cycle", "must": ["not switched on yet"] },
{ "q": "How do I win the weekly prize?", "kb": "leaders", "must": ["top three", "following Monday"] },
{ "q": "What are the SPIN tiles?", "kb": "spin-tiles", "must": ["never shift"] },
{ "q": "Can I change the link on my banner?", "kb": "swap", "must": ["one time", "keeps its place"] },
{ "q": "Which wallet should I use?", "kb": "wallet", "must": ["SafePal or any other crypto wallet"] },
{ "q": "Is this a pyramid scheme?", "kb": "safe", "must": ["contract", "not an income opportunity"] }
],
+133
View File
@@ -647,6 +647,139 @@ async function main() {
await browser.close();
}
// ---- 15. one swap per banner (members) + admin takedown / restore (Marty 2026-11-15) ----
console.log('15. one swap per banner + admin takedown and restore');
await sleep(1200); ENV.LOOP_SIZE = '5'; await stop(); await boot();
{
const ADM = (q, body) => anon.json(q, body, { 'x-admin-token': ADMIN });
const ids = v => v.loop.map(t => String(t.id));
const shiftOnce = async () => { const rs = await Promise.all([client(), client(), client()].map(c => visit(c))); return rs.some(x => x.shifted); };
const X = [];
for (let i = 0; i < 7; i++) { const m = await walletMember(); await m.json('/api/my'); const b = await postBanner(m, 20 + i, 'https://swap-member.com/p?i=' + i); m.bid = b.banner && b.banner.id; X.push(m); }
ok(X.every(m => m.bid), 'seven members posted a banner each', X.map(m => m.bid));
let shifted = 0; for (let i = 0; i < 3; i++) if (await shiftOnce()) shifted++;
let st = await ADM('/api/admin/status');
ok(shifted === 3 && st.loop.filled === 5 && st.queue.length >= 2, 'three shifts: loop full of 5, others waiting', { shifted, loop: st.loop.ids, q: st.queue.next });
const own = id => X.find(m => m.bid === id);
const Xa = own(st.loop.ids[2]), Xt = own(st.loop.ids[1]), Xq = own(st.queue.next[1]);
ok(!!(Xa && Xt && Xq), 'the new banners sit at loop places 1 to 3 and in the line', { loop: st.loop.ids, q: st.queue.next });
// -- the swap
let my = await Xa.json('/api/my'); let mb = my.banners.find(b => b.id === Xa.bid);
ok(mb && mb.canSwap === true && mb.swapUsed === false, 'My Banners: a banner in the loop can be swapped', mb);
const before = { place: mb.place, clicks: mb.clicks, img: mb.img, link: mb.link, progress: st.progress };
let r = await Xt.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'https://other-member.com/' }); ok(r._status === 404, 'nobody can swap another member\'s banner', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', {}); ok(r._status === 400 && /new image, a new link/.test(r.error), 'a swap with nothing new is refused', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'http://plain-http.com/' }); ok(r._status === 400 && /https/.test(r.error), 'swap: an http link is refused (same check as a new post)', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'https://bit.ly/abc' }); ok(r._status === 400 && /shortener/.test(r.error), 'swap: a shortener link is refused', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { img: 'http://swap-member.com/x.png' }); ok(r._status === 400 && /https/.test(r.error), 'swap: an http image address is refused', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { img: '/u/00000000-aaaaaaaaaaaa.png' }); ok(r._status === 400, 'swap: someone else\'s (or a missing) upload is refused', r);
my = await Xa.json('/api/my'); mb = my.banners.find(b => b.id === Xa.bid);
ok(mb.canSwap === true && mb.link === before.link && mb.img === before.img, 'refused swaps change nothing and do not use up the swap', mb);
const nu = await upload(Xa, png(125, 125, 7));
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { img: nu.img, link: 'https://swapped-member.com/new' });
ok(r.ok && r.banner.id === Xa.bid && r.banner.img === nu.img && r.banner.link === 'https://swapped-member.com/new' && r.banner.state === 'loop' && r.banner.place === before.place, 'the swap changes image + link and keeps the id and the place', r);
my = await Xa.json('/api/my'); mb = my.banners.find(b => b.id === Xa.bid);
ok(mb.swapUsed === true && mb.canSwap === false && mb.swappedAt > 0 && mb.place === before.place && mb.clicks === before.clicks, 'after the swap: used, no second button, same place and clicks', mb);
st = await ADM('/api/admin/status'); ok(st.progress === before.progress && st.loop.ids[2] === Xa.bid, 'the swap leaves the bar and the loop order alone', { p: [before.progress, st.progress], loop: st.loop.ids });
let sp = await anon.json('/api/splash'); const tA = sp.loop.find(t => t.id === Xa.bid);
ok(tA && tA.img === nu.img, 'the splash shows the new image at once', tA);
r = await anon.req('/go/' + Xa.bid); ok(r.status === 302 && r.headers.get('location') === 'https://swapped-member.com/new', 'clicks go to the new link', r.headers.get('location'));
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'https://third-try.com/' }); ok(r._status === 400 && /already used its one swap/.test(r.error), 'a second swap is refused', r);
let ab = await ADM('/api/admin/banners?q=%23' + Xa.bid);
ok(ab.banners && ab.banners[0].swaps.length === 1 && ab.banners[0].swaps[0].old.link === before.link && ab.banners[0].swaps[0].new.link === 'https://swapped-member.com/new' && ab.banners[0].swaps[0].old.img === before.img && ab.banners[0].swaps[0].at > 0,
'the swap is logged on the banner (old + new link and image, time)', ab.banners && ab.banners[0].swaps);
// a waiting banner can swap its link only, and keeps its number in line
my = await Xq.json('/api/my'); mb = my.banners.find(b => b.id === Xq.bid); const qpos = mb.position;
r = await Xq.json('/api/my/banners/' + Xq.bid + '/swap', { link: 'https://queued-swap.com/' });
my = await Xq.json('/api/my'); mb = my.banners.find(b => b.id === Xq.bid);
ok(r.ok && mb.state === 'queued' && mb.position === qpos && mb.link === 'https://queued-swap.com/' && mb.swapUsed, 'a waiting banner swaps its link only and keeps its number in line', mb);
// a Banner Spin swaps to another of the member's own spins
const SPX = await walletMember(); await SPX.json('/api/my');
LSA.set(SPX.address, { username: 'spinswap', spins: [{ id: 41, name: 'First', code: 'qk7swp01', size: '125x125', paused: false, banners: 1 }, { id: 42, name: 'Second', code: 'qk7swp02', size: '250x250', paused: false, banners: 1 }, { id: 43, name: 'Wide', code: 'qk7swp03', size: '468x60', paused: false, banners: 1 }] });
const spb = await SPX.json('/api/my/banners', { spinId: 41 });
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { spinId: 41 }); ok(r._status === 400 && /already shows/.test(r.error), 'swap to the same Banner Spin is refused', r);
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { spinId: 43 }); ok(r._status === 400 && /125x125/.test(r.error), 'swap to a 468x60 spin is refused', r);
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { link: 'https://half-swap.com/' }); ok(r._status === 400 && /Banner Spin/.test(r.error), 'a Banner Spin cannot swap its link alone', r);
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { spinId: 42 });
my = await SPX.json('/api/my'); mb = my.banners.find(b => b.id === spb.banner.id);
ok(r.ok && mb.img.includes('qk7swp02') && mb.link.includes('/c/qk7swp02') && mb.spin && mb.spin.name === 'Second' && mb.swapUsed, 'a Banner Spin swaps to another of the member\'s own spins', mb);
// -- the takedown (credit back), the place stays
st = await ADM('/api/admin/status'); const loop0 = st.loop.ids.slice(); const T = Xt.bid; const ti = loop0.indexOf(T);
let tl = await ADM('/api/admin/member-lookup?q=%23' + T); const cr0 = tl.credits;
r = await anon.json('/api/admin/banners/' + T + '/takedown', { reason: 'Broken page', credit: 'back' }); ok(r._status === 401, 'takedown needs the admin token', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { credit: 'back' }); ok(r._status === 400 && /reason is required/.test(r.error), 'takedown without a reason is refused', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'Broken landing page' }); ok(r._status === 400 && /credit/.test(r.error), 'takedown without the credit choice is refused', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'Broken landing page', credit: 'back', by: 'marty' });
ok(r.ok && r.banner.down && r.banner.down.creditBack === true && r.ownerCredits === cr0 + 1, 'takedown with credit back: the owner gets the post credit', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'again', credit: 'none' }); ok(r._status === 400 && /already/.test(r.error), 'a banner cannot be taken down twice', r);
sp = await anon.json('/api/splash');
ok(ids(sp)[ti] === 'h' + T && sp.loop[ti].house === true && !sp.loop.some(t => t.id === T) && !JSON.stringify(sp.loop).includes('"/go/' + T + '"'), 'the splash shows a house tile in its place, never the banner', sp.loop[ti]);
ok(JSON.stringify(ids(sp).filter((x, i) => i !== ti)) === JSON.stringify(loop0.filter((x, i) => i !== ti).map(String)), 'every other banner keeps its place', { before: loop0, after: ids(sp) });
ok(!sp.loop[ti].owner && sp.loop[ti].img === '/art/tile-house.svg', 'the house tile carries no owner, image or link of the banner', sp.loop[ti]);
r = await anon.req('/art/tile-house.svg'); ok(r.status === 200, 'the house tile image is served');
r = await anon.req('/go/' + T); ok(r.status === 302 && r.headers.get('location') === '/', 'its click relay goes home, not to the banner link', r.headers.get('location'));
my = await Xt.json('/api/my'); mb = my.banners.find(b => b.id === T);
ok(mb.state === 'down' && mb.downReason === 'Broken landing page' && mb.creditBack === true && mb.canSwap === false && my.credits === cr0 + 1, 'My Banners shows it taken down with the reason and the credit back', mb);
r = await Xt.json('/api/my/banners/' + T + '/swap', { link: 'https://sneaky-swap.com/' }); ok(r._status === 400 && /taken down/.test(r.error), 'a taken-down banner cannot be swapped', r);
r = await Xt.json('/api/my/order', { sku: 3, ref: T }); ok(r._status === 400 && /taken down/.test(r.error), 'a taken-down banner cannot get the banner look', r);
// restore: back in its place, the credit taken back
r = await ADM('/api/admin/banners/' + T + '/restore', { reason: 'page fixed, my mistake' });
ok(r.ok && r.creditReversed === true && r.ownerCredits === cr0 && !r.banner.down, 'restore: the banner is back and the credit given back is taken back', r);
sp = await anon.json('/api/splash'); ok(ids(sp)[ti] === String(T), 'restore: the banner shows in its own place again', ids(sp));
r = await ADM('/api/admin/banners/' + T + '/restore', {}); ok(r._status === 400, 'restoring a banner that is not down is refused', r);
// a waiting banner taken down with no credit: the line keeps its numbers
st = await ADM('/api/admin/status'); const q0 = st.queue.next.slice(); const Q = q0[0];
tl = await ADM('/api/admin/member-lookup?q=%23' + Q); const qc0 = tl.credits;
r = await ADM('/api/admin/banners/' + Q + '/takedown', { reason: 'Adult content', credit: 'none' });
ok(r.ok && r.banner.down.creditBack === false && r.ownerCredits === qc0, 'takedown with no credit: the owner\'s credits do not change', r);
sp = await anon.json('/api/splash');
ok(sp.queue[0].id === 'h' + Q && sp.queue.slice(1).map(t => t.id).join() === q0.slice(1, sp.queue.length).join(), 'the waiting line shows a house tile; nobody behind it moves', sp.queue.map(t => t.id));
// the back banner taken down rides out on time but never cycles or earns
st = await ADM('/api/admin/status'); const L = st.loop.nextOut; const cyc0 = st.totals.cycles; const led0 = (await ADM('/api/admin/ledger?n=2000')).entries.filter(e => e.bannerId === L).length;
r = await ADM('/api/admin/banners/' + L + '/takedown', { reason: 'Malware report', credit: 'none' }); ok(r.ok, 'the next-out banner is taken down', r);
const qBefore = st.queue.next.slice();
ok(await shiftOnce(), 'the loop shifts as usual');
st = await ADM('/api/admin/status'); ab = await ADM('/api/admin/banners?q=%23' + L);
ok(!st.loop.ids.includes(L) && ab.banners[0].state === 'ended' && st.totals.cycles === cyc0, 'its place rode out on time: state ended, no cycle counted', { state: ab.banners[0].state, cyc: [cyc0, st.totals.cycles] });
ok((await ADM('/api/admin/ledger?n=2000')).entries.filter(e => e.bannerId === L).length === led0, 'no network views recorded for it');
ok(st.loop.ids[0] === qBefore[0], 'the next waiting banner (the house tile of #' + qBefore[0] + ' too) entered at the front as usual', { loop: st.loop.ids, q: qBefore });
// restoring after it rode out records the cycle it would have had
r = await ADM('/api/admin/banners/' + L + '/restore', { reason: 'report was wrong' });
ok(r.ok && r.cycle && r.cycle.bannerId === L && r.cycle.note === 'restored' && r.banner.state === 'cycled', 'restore after it rode out: the cycle is recorded then', r);
r = await ADM('/api/admin/banners/' + Q + '/restore', {}); ok(r.ok && r.creditReversed === false && !r.banner.down, 'restore with no credit given: nothing to take back', r);
const acts = await ADM('/api/admin/actions');
const kinds = acts.actions.map(a => a.action + ':' + a.bannerId + ':' + a.credit);
ok(acts.actions.length === 6 && acts.actions.every(a => a.at > 0 && a.by && a.id) && kinds.includes('takedown:' + T + ':back') && kinds.includes('takedown:' + Q + ':none') && kinds.includes('restore:' + T + ':taken back')
&& acts.actions.find(a => a.action === 'takedown' && a.bannerId === T).reason === 'Broken landing page' && acts.actions.find(a => a.bannerId === T && a.action === 'takedown').by === 'marty',
'the admin ledger logs who, when, reason and the credit decision', acts.actions);
ab = await ADM('/api/admin/banners?q=%23' + T); ok(ab.banners[0].downs.length === 1 && ab.banners[0].downs[0].creditReversed === true, 'the banner keeps its takedown history', ab.banners[0].downs);
ab = await ADM('/api/admin/banners?q=' + Xa.address); ok(ab.banners && ab.banners.length === 1 && ab.banners[0].id === Xa.bid, 'admin finds banners by wallet', ab);
r = await ADM('/api/admin/banners?q=nobody-here-zz'); ok(r._status === 404, 'admin: no banner found answers 404');
r = await anon.req('/admin'); const ah2 = await r.text(); ok(/id="bnCard"/.test(ah2) && /id="aActions"/.test(ah2), 'the admin page has the takedown card and the admin ledger');
if (!process.env.SKIP_UI && fs.existsSync(PW)) {
const { chromium } = require(PW); const browser = await chromium.launch(); const errs = [];
const ctx = await browser.newContext({ viewport: { width: 390, height: 900 }, userAgent: 'Mozilla/5.0 (iPhone) AppleWebKit/605.1.15 Mobile Safari SmokeUI-swap' });
const pg = await ctx.newPage(); pg.on('pageerror', e => errs.push(e.message));
await ctx.addCookies([{ name: 'vbb.sid', value: Xt.jar['vbb.sid'], url: BASE }]);
await pg.goto(BASE + '/my', { waitUntil: 'domcontentloaded' }); await pg.waitForSelector('.swap-row button', { timeout: 8000 }).catch(() => {});
ok((await pg.textContent('.swap-row button').catch(() => '')) === 'Swap image or link', 'My Banners (phone): the "Swap image or link" button shows');
await pg.click('.swap-row button'); ok(await pg.isVisible('.swap-box .sw-link'), 'tapping it opens the swap form');
await pg.fill('.swap-box .sw-link', 'https://ui-swapped.com/'); await pg.click('.swap-box .sw-go');
await pg.waitForFunction(() => /Swap used/.test(document.querySelector('#mine').textContent), null, { timeout: 8000 }).catch(() => {});
ok(/Swap used/.test(await pg.textContent('#mine')) && /Swapped\. Banner #/.test(await pg.textContent('#status')), 'the swap goes through and the button turns into "Swap used"');
ok((await pg.evaluate(() => document.documentElement.scrollWidth)) <= 390, 'no sideways scroll on a phone');
await pg.screenshot({ path: path.join(OUT, 'my-swap.png'), fullPage: true });
await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'Adult content', credit: 'none' });
await pg.goto(BASE + '/my', { waitUntil: 'domcontentloaded' }); await pg.waitForSelector('.pill.down', { timeout: 8000 }).catch(() => {});
ok(/Taken down/i.test(await pg.textContent('#mine')) && /Adult content/.test(await pg.textContent('#mine')), 'My Banners shows "Taken down" with the reason');
await pg.screenshot({ path: path.join(OUT, 'my-down.png'), fullPage: true });
ok(errs.length === 0, 'no page errors (swap)', errs);
await browser.close();
}
}
await stop();
console.log('\n' + pass + ' passed, ' + fail + ' failed');
fs.writeFileSync(path.join(OUT, 'smoke.txt'), new Date().toISOString() + ' ' + pass + ' passed, ' + fail + ' failed\n');
+113 -12
View File
@@ -167,7 +167,8 @@ function grantDaily(m) {
function myData(addr) {
const m = store.member(addr);
const banners = store.bannersOf(addr).slice().reverse().map(b => Object.assign({ id: b.id, img: b.img, link: b.link, createdAt: b.createdAt, cycledAt: b.cycledAt || null, clicks: b.clicks || 0,
look: !!b.look, teaser: b.look ? (b.teaser || '') : '', teaserDefault: b.spin ? b.spin.name : loop.hostOf(b.link), spin: b.spin ? { name: b.spin.name, size: b.spin.size } : null }, loop.placeOf(b)));
look: !!b.look, teaser: b.look ? (b.teaser || '') : '', teaserDefault: b.spin ? b.spin.name : loop.hostOf(b.link), spin: b.spin ? { name: b.spin.name, size: b.spin.size } : null,
swapUsed: swapUsed(b), swappedAt: swapUsed(b) ? b.swaps[b.swaps.length - 1].at : null, canSwap: canSwap(b) }, loop.memberPlace(b)));
const rewards = store.ledger().filter(e => e.owner === m.address);
const shareName = m.username || m.address;
return { address: m.address, username: m.username, credits: m.credits, freeCreditCap: C.freeCreditCap, freeToday: m.freeDay === store.ctDay(), netVerified: netVerified(m),
@@ -175,6 +176,11 @@ function myData(addr) {
week: loop.memberWeek(m.address), share: 'https://' + C.site + '/?ref=' + encodeURIComponent(shareName) };
}
// one swap per banner (Marty 2026-11-15: "allow the member to swap it only, and they can only do it one time"): image and/or link,
// while the banner is waiting or in the loop and not taken down. No withdraw, no removal, no refund for members.
const swapUsed = b => Array.isArray(b.swaps) && b.swaps.length > 0;
const canSwap = b => !swapUsed(b) && !b.down && (b.state === 'queued' || b.state === 'loop');
// ---- visit tickets: issued on page load, redeemed after the page has been visible for visitSeconds ----
const tickets = new Map();
const srcHost = raw => { try { const u = new URL(String(raw || '')); if (!/^https?:$/.test(u.protocol)) return ''; const h = u.hostname.toLowerCase().replace(/^www\./, ''); return h === C.site || h.endsWith('.' + C.site) || !h.includes('.') ? '' : h.slice(0, 80); } catch (e) { return ''; } };
@@ -261,7 +267,7 @@ const server = http.createServer(async (req, res) => {
// click relay: /go/<bannerId> counts one click per visitor per banner per hour, then sends the visitor to the banner's link
const gm = /^\/go\/(\d{1,9})$/.exec(p);
if (gm) {
const b = store.banner(gm[1]); if (!b) { res.writeHead(302, { Location: '/' }); return res.end(); }
const b = store.banner(gm[1]); if (!b || b.down) { res.writeHead(302, { Location: '/' }); return res.end(); } // taken down: never sends anyone to it
if (!isBot(req)) {
const k = visitorKey(req) + ':' + b.id; const t = clickSeen.get(k);
if (!t || Date.now() - t > 3600000) { clickSeen.set(k, Date.now()); if (clickSeen.size > 100000) clickSeen.clear(); b.clicks = (b.clicks || 0) + 1; store.saveBanner(b); store.bump('clicks'); }
@@ -390,6 +396,7 @@ const server = http.createServer(async (req, res) => {
if (sku === C.lookSku) {
const bn = store.banner(b.ref);
if (!bn || bn.owner !== me) return json(res, 400, { error: 'That banner is not yours.' });
if (bn.down) return json(res, 400, { error: 'That banner was taken down.' });
if (bn.look) return json(res, 400, { error: 'That banner already has the look.' });
if (bn.state === 'cycled') return json(res, 400, { error: 'That banner has already cycled. Add the look to a banner that is waiting or in the loop.' });
if (qty !== 1) return json(res, 400, { error: 'One look per banner.' });
@@ -409,6 +416,7 @@ const server = http.createServer(async (req, res) => {
const tm = /^\/api\/my\/banners\/(\d{1,9})\/teaser$/.exec(p);
if (tm && req.method === 'POST') {
const bn = store.banner(tm[1]); if (!bn || bn.owner !== me) return json(res, 404, { error: 'Not found' });
if (bn.down) return json(res, 400, { error: 'That banner was taken down.' });
if (!bn.look) return json(res, 400, { error: 'Add the banner look first.' });
const t = String((await readBody(req)).teaser || '').replace(/[\u0000-\u001f\u007f<>]/g, '').replace(/\s+/g, ' ').trim();
if (t.length > 40) return json(res, 400, { error: 'Keep the teaser to 40 characters.' });
@@ -420,6 +428,43 @@ const server = http.createServer(async (req, res) => {
const r = await lsspins.list(me, lsName(me)); if (r.error) return json(res, 502, r);
return json(res, 200, { account: !!r.account, username: r.username || null, spins: (r.spins || []).filter(x => ['125x125', '250x250'].includes(x.size)).map(x => ({ id: x.id, name: x.name, size: x.size || null, paused: !!x.paused, banners: x.banners || 0 })) });
}
// swap the image and/or link of a banner that is waiting or in the loop, once per banner. The banner keeps its id, place, clicks
// and cycle progress. The new image and link get exactly the checks a new post gets. A Banner Spin swap ({ spinId }) takes the
// image + link from LinkSpin's signed answer for another of the member's own 125x125/250x250 spins. Logged on the banner.
const sw = /^\/api\/my\/banners\/(\d{1,9})\/swap$/.exec(p);
if (sw && req.method === 'POST') {
if (limited(req, 'swap', 20, 3600000)) return json(res, 429, { error: 'Too many tries this hour.' });
const bn = store.banner(sw[1]); if (!bn || bn.owner !== me) return json(res, 404, { error: 'Not found' });
if (swapUsed(bn)) return json(res, 400, { error: 'This banner already used its one swap.' });
if (bn.down) return json(res, 400, { error: 'That banner was taken down.' });
if (bn.state !== 'queued' && bn.state !== 'loop') return json(res, 400, { error: 'Only a banner that is waiting or in the loop can be swapped.' });
const b = await readBody(req); let next;
if (b.spinId != null) {
const r = await lsspins.use(me, lsName(me), b.spinId);
if (r.error || !r.use) return json(res, 400, { error: r.error || (r.account === false ? 'No LinkSpin account holds this wallet yet.' : 'Could not use that Banner Spin.') });
if (!['125x125', '250x250'].includes(r.use.size)) return json(res, 400, { error: 'Use a 125x125 (or 250x250) Banner Spin.' });
const ic = safety.checkLink(r.use.img, 'Banner Spin image'); const sl = safety.checkLink(r.use.link, 'Banner Spin link');
if (ic.error || sl.error || new URL(ic.url).hostname !== new URL(sl.url).hostname) return json(res, 400, { error: 'LinkSpin sent a link we cannot use. Try again in a minute.' });
next = { img: ic.url, link: sl.url, spin: { id: Number(r.use.spinId), name: String(r.use.name || '').slice(0, 60), size: r.use.size } };
if (bn.spin && bn.spin.id === next.spin.id) return json(res, 400, { error: 'That is the Banner Spin this banner already shows. Pick another one.' });
} else {
const hasImg = String(b.img || '').trim() !== '', hasLink = String(b.link || '').trim() !== '';
if (!hasImg && !hasLink) return json(res, 400, { error: 'Add a new image, a new link, or both.' });
if (bn.spin && !(hasImg && hasLink)) return json(res, 400, { error: 'A Banner Spin swaps to another Banner Spin, or to your own image and link together.' });
let link = bn.link, img = bn.img;
if (hasLink) { const lk = safety.checkLink(b.link, 'Target link'); if (lk.error) return json(res, 400, lk); link = lk.url; }
if (hasImg) { const im = await checkedImage(me, b.img); if (im.error) return json(res, 400, im); img = im.img; }
if (hasLink && C.linkProbe) { const pr = await safety.probeLink(link); if (pr.error) return json(res, 400, pr); }
if (link === bn.link && img === bn.img) return json(res, 400, { error: 'That is the image and link the banner already has.' });
next = { img, link, spin: null };
}
const cur = store.banner(sw[1]); // re-checked after the awaits (another tab, or the admin, may have acted meanwhile)
if (swapUsed(cur) || !canSwap(cur)) return json(res, 400, { error: swapUsed(cur) ? 'This banner already used its one swap.' : 'This banner can no longer be swapped.' });
cur.swaps = [{ at: Date.now(), old: { img: cur.img, link: cur.link, spin: cur.spin || null }, new: { img: next.img, link: next.link, spin: next.spin } }];
cur.img = next.img; cur.link = next.link; if (next.spin) cur.spin = next.spin; else delete cur.spin;
store.saveBanner(cur);
return json(res, 200, { ok: true, banner: Object.assign({ id: cur.id, img: cur.img, link: cur.link, spin: cur.spin ? { name: cur.spin.name, size: cur.spin.size } : null, swapUsed: true }, loop.placeOf(cur)) });
}
if (p === '/api/my/upload' && req.method === 'POST') {
if (limited(req, 'upload', 40, 3600000)) return json(res, 429, { error: 'Too many uploads this hour.' });
let buf; try { buf = await readRaw(req, safety.MAX_UPLOAD + 1); } catch (e) { return json(res, 400, { error: 'The file is over 100 KB.' }); }
@@ -430,7 +475,7 @@ const server = http.createServer(async (req, res) => {
if (limited(req, 'post', 30, 3600000)) return json(res, 429, { error: 'Too many posts this hour.' });
const b = await readBody(req); const m = store.member(me);
if (m.credits < 1) return json(res, 400, { error: 'You have no post credits. A free credit arrives each day you sign in.' });
const waiting = store.bannersOf(me).filter(x => x.state === 'queued').length;
const waiting = store.bannersOf(me).filter(x => x.state === 'queued' && !x.down).length;
if (waiting >= C.maxQueuedPerMember) return json(res, 400, { error: 'You already have ' + waiting + ' banners waiting. Post again when one enters the loop.' });
// a LinkSpin Banner Spin (2026-11-14): image + link come from LinkSpin's signed answer, never from the browser. The image is the
// spin's rotating image on LinkSpin (not copied: it changes on every view) and the link its click link (clicks count in
@@ -447,14 +492,8 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, { ok: true, banner: Object.assign({ id: nb.id }, loop.placeOf(nb)), credits: m.credits, otherSource: !!r.use.otherSource });
}
const lk = safety.checkLink(b.link, 'Target link'); if (lk.error) return json(res, 400, lk);
let img = String(b.img || '').trim();
if (/^\/u\/[a-z0-9-]+\.(png|jpg|gif)$/.test(img)) {
if (!img.slice(3).startsWith(me.slice(2, 10) + '-') || !fs.existsSync(path.join(UPL, img.slice(3)))) return json(res, 400, { error: 'Upload the image again.' });
} else {
const ic = safety.checkLink(img, 'Image address'); if (ic.error) return json(res, 400, ic);
const f = await safety.fetchImage(ic.url); if (f.error) return json(res, 400, f);
img = saveUpload(me, f.buf, f.info.ext);
}
const im = await checkedImage(me, b.img); if (im.error) return json(res, 400, im);
const img = im.img;
if (C.linkProbe) { const pr = await safety.probeLink(lk.url); if (pr.error) return json(res, 400, pr); }
if (store.member(me).credits < 1) return json(res, 400, { error: 'You have no post credits.' }); // spent meanwhile by another tab
m.credits -= 1;
@@ -502,6 +541,51 @@ const server = http.createServer(async (req, res) => {
const per = {}; for (const e of L) { const k = e.owner; const r = per[k] || (per[k] = { address: k, username: e.username, cycles: 0, views: 0 }); r.cycles++; r.views += e.views; if (e.username) r.username = e.username; }
return json(res, 200, { entries: L.slice(-n).reverse(), members: Object.values(per).sort((a, b) => b.views - a.views), note: 'v1 records rewards only; nothing has been credited to InstantAdPay or LinkSpin.' });
}
// ---- banner takedown (Marty 2026-11-15: "Admin takes down the option to credit back or none") ----
// GET ?q=#<id> | <id> | <wallet> | <username>: the banners with their swap + takedown history
if (p === '/api/admin/banners' && req.method === 'GET') {
const q = String(u.searchParams.get('q') || '').trim(); let list = [];
if (/^#?\d{1,9}$/.test(q)) { const b = store.banner(Number(q.replace('#', ''))); if (b) list = [b]; }
else if (ADDR_RE.test(q)) list = store.bannersOf(q);
else if (NAME_RE.test(q.replace(/^@/, ''))) { const m = store.memberByName(q.replace(/^@/, '')); if (m) list = store.bannersOf(m.address); }
if (!list.length) return json(res, 404, { error: 'No banner found for that.' });
return json(res, 200, { banners: list.slice().reverse().slice(0, 100).map(adminBanner) });
}
const tk = /^\/api\/admin\/banners\/(\d{1,9})\/(takedown|restore)$/.exec(p);
if (tk && req.method === 'POST') {
const bn = store.banner(tk[1]); if (!bn) return json(res, 404, { error: 'No such banner.' });
const b = await readBody(req); const by = String(b.by || 'admin').replace(/[^\w .@-]/g, '').slice(0, 40) || 'admin';
const reason = String(b.reason || '').replace(/[\u0000-\u001f\u007f<>]/g, '').replace(/\s+/g, ' ').trim();
const m = store.member(bn.owner);
if (tk[2] === 'takedown') {
if (bn.down) return json(res, 400, { error: 'That banner is already taken down.' });
if (bn.state !== 'queued' && bn.state !== 'loop') return json(res, 400, { error: 'Only a banner that is waiting or in the loop can be taken down (this one is ' + bn.state + ').' });
if (reason.length < 3 || reason.length > 300) return json(res, 400, { error: 'A reason is required (3 to 300 characters). The owner sees it.' });
if (b.credit !== 'back' && b.credit !== 'none') return json(res, 400, { error: 'Choose credit: "back" (the owner gets the post credit back) or "none".' });
const back = b.credit === 'back' && !!m;
bn.down = { at: Date.now(), by, reason, creditBack: back, slot: bn.state };
if (back) { m.credits += 1; store.save(); }
store.saveBanner(bn);
const e = adminLog({ action: 'takedown', bannerId: bn.id, owner: bn.owner, username: (m && m.username) || null, by, reason, credit: back ? 'back' : 'none', slot: bn.state });
return json(res, 200, { ok: true, banner: adminBanner(bn), log: e, ownerCredits: m ? m.credits : null });
}
// restore a mistaken takedown: the banner shows again; a credit that was given back is taken back
if (!bn.down) return json(res, 400, { error: 'That banner is not taken down.' });
const was = bn.down; let reversed = false, short = false, cycle = null;
if (was.creditBack && m) { if (m.credits >= 1) { m.credits -= 1; reversed = true; store.save(); } else short = true; }
(bn.downs || (bn.downs = [])).push(Object.assign({}, was, { restoredAt: Date.now(), restoredBy: by, restoreReason: reason || null, creditReversed: reversed }));
delete bn.down;
// its place rode out while it was down: it gets the cycle it would have had
if (bn.state === 'ended') { bn.state = 'cycled'; bn.cycledAt = Date.now(); delete bn.endedAt; cycle = loop.recordCycle(bn, { note: 'restored' }); }
store.saveBanner(bn);
const e = adminLog({ action: 'restore', bannerId: bn.id, owner: bn.owner, username: (m && m.username) || null, by, reason: reason || null,
credit: was.creditBack ? (reversed ? 'taken back' : 'already used, not taken back') : 'none given', cycleRecorded: !!cycle });
return json(res, 200, { ok: true, banner: adminBanner(bn), log: e, creditReversed: reversed, creditAlreadyUsed: short, cycle, ownerCredits: m ? m.credits : null });
}
if (p === '/api/admin/actions' && req.method === 'GET') {
const n = Math.min(500, Math.max(1, Number(u.searchParams.get('n')) || 100));
return json(res, 200, { actions: (store.state().adminLog || []).slice(-n).reverse() });
}
// the network hub's member lookup (Marty 2026-11-14, read-only). GET ?q=<wallet> | #<banner id> | <username>. No email lives here.
if (p === '/api/admin/member-lookup' && req.method === 'GET') {
const q = String(u.searchParams.get('q') || '').trim(); let a = null, via = null;
@@ -529,6 +613,23 @@ const server = http.createServer(async (req, res) => {
});
// the network username LinkSpin may look the member up by when no LinkSpin account holds this wallet: network-verified members only
const lsName = addr => { const m = store.member(addr); return m && netVerified(m) && m.username ? m.username : null; };
// admin views of a banner + the admin action ledger (takedowns and restores: who, when, reason, credit decision)
function adminBanner(b) { const m = store.member(b.owner);
return Object.assign({ id: b.id, owner: b.owner, username: (m && m.username) || null, img: b.img, link: b.link, spin: b.spin || null, createdAt: b.createdAt, clicks: b.clicks || 0, look: !!b.look,
swaps: b.swaps || [], down: b.down || null, downs: b.downs || [], cycledAt: b.cycledAt || null, endedAt: b.endedAt || null }, loop.placeOf(b)); }
function adminLog(e) { const S = store.state(); const L = S.adminLog || (S.adminLog = []);
e.id = 'a' + (S.seq.admin = (S.seq.admin || 0) + 1); e.at = Date.now(); L.push(e); if (L.length > 5000) L.splice(0, L.length - 5000); store.save(); return e; }
// a banner image from the browser: one of this member's uploads (/u/...), or an https image address fetched once and checked like an upload
async function checkedImage(me, raw) {
const img = String(raw || '').trim();
if (/^\/u\/[a-z0-9-]+\.(png|jpg|gif)$/.test(img)) {
if (!img.slice(3).startsWith(me.slice(2, 10) + '-') || !fs.existsSync(path.join(UPL, img.slice(3)))) return { error: 'Upload the image again.' };
return { img };
}
const ic = safety.checkLink(img, 'Image address'); if (ic.error) return ic;
const f = await safety.fetchImage(ic.url); if (f.error) return f;
return { img: saveUpload(me, f.buf, f.info.ext) };
}
// tracking macros in a banner link, filled on every click: {clickid} a fresh id, {spot} the banner number, {type} loop or waiting
const MACRO = /\{(clickid|spot|type)\}|%7B(clickid|spot|type)%7D/gi;
function clickLink(b) {
@@ -540,7 +641,7 @@ function clickLink(b) {
// waiting line. Never in the loop list: no shift, no cycle, no reward. Same picks for 2 minutes, so the page does not reshuffle.
let fillCache = { key: '', at: 0, out: { loop: [], queue: [] } };
function splashFill() {
const S = store.state(); const ids = S.loop.concat(S.queue.slice(0, 24)); const bs = ids.map(id => store.banner(id)).filter(Boolean);
const S = store.state(); const ids = S.loop.concat(S.queue.slice(0, 24)); const bs = ids.map(id => store.banner(id)).filter(b => b && !b.down);
const open = Math.max(0, C.loopSize - S.loop.length - 1), queueSlots = S.queue.length ? 0 : 8;
const key = ids.join(',') + '|' + open + '|' + queueSlots + '|' + lsspins.view().fill + '|' + lsspins.view().at;
if (fillCache.key === key && Date.now() - fillCache.at < 120000) return fillCache.out;