Spot edits: unlimited, full link check on every one, every one logged; admin takedown and restore (Marty 2026-11-16)
Edits (POST /api/my/spot/<id>, /api/my/default, uploads): still any number of times. Every change now gets the full check:
checkLink, then (LINK_PROBE on) the link must answer (safety.probeLink, up to 3 redirects each checked) and an image address must
download as a real 468x60 image of 150 KB or less (safety.probeImage; the address is kept, a Banner Spin image rotates). The
Banner Spin image + click link LinkSpin just handed the member are not fetched (that would count a LinkSpin click). safety.js gains
privateIp + safeLookup with the Node 20 fix VBB/ViralAdBlitz needed (honors opts.all, answers an array). Every real change is
logged on the spot (or the default): old and new link and image, time, via edit/upload; the owner sees the newest 10. 120 changes
an hour per connection (each one fetches the link).
Admin takedown (the Viral Banner Blitz way, 8e6d2f9): /admin (new page) finds a spot by #number, wallet or network username;
POST /api/admin/spots/<id>/takedown {reason (required, the owner sees it), credit}. Hidden everywhere at once: the board shows a
house tile in its place (nobody else moves), the gate gives its step to a house site, /go/<id> goes home, its Network Ad Space
banner is paused (approved = 0) and no new one is placed. No views or clicks count while down. My Spots shows "Taken down" with
the reason and no edit controls. Restore (POST .../restore) reverses it (NAS resumed). Admin ledger: GET /api/admin/actions (who,
when, reason, credit decision). The contract is never touched.
CREDIT BACK IS NOT BUILT: a spot is a $5 on-chain purchase and this site has no free replacement spot or post credit, so
credit: "back" is refused with a note until Marty decides what it means here; takedowns are "no credit".
Chatbot: CANNED takedown + banner answer (unlimited checked, logged edits) + FACTS EDITS/TAKEDOWN lines, KNOWLEDGE_DATE 2026-11-16.
line.css?v=9, my.js?v=z3.
Tests: smoke section 10 (the lookup shape, edit log, unlimited edits, refusals: unreachable, 404, private address, http redirect,
shortener, bad image size/404/unreachable; redirect followed; same link logs nothing; upload logged; default checked + logged;
takedown: token, reason, credit choice, credit back refused, held house tile, image nowhere, /go home, gate, no views, owner view,
no edits while down, ledger, restore, /admin) against a stand-in internet preloaded into the app (qa/out/probe-stub.cjs, nothing
leaves the machine), plus phone renders of My Spots taken down and /admin: 193/193 with UI. chatbot.test 181/181.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -222,10 +222,12 @@ async function visitStep(role, ref, img, link, title) {
|
||||
async function makeGate(req) {
|
||||
const vk = visitorKey(req); const steps = [];
|
||||
const sp = sponsorOf(req); const sSpot = sp && board.newestOf(sp);
|
||||
if (sSpot) { const cr = board.creative(sSpot); steps.push(await visitStep('sponsor', sSpot.id, cr.img, cr.link, 'Your sponsor\'s newest spot')); }
|
||||
// a spot the admin took down (2026-11-16) keeps its step, but the step shows a house site (never the spot's own banner or link)
|
||||
const stepOf = async (role, s, title) => { const cr = board.creative(s); return cr.from === 'down' ? visitStep(role, 'h-' + cr.key, cr.img, cr.link, cr.title) : visitStep(role, s.id, cr.img, cr.link, title); };
|
||||
if (sSpot) steps.push(await stepOf('sponsor', sSpot, 'Your sponsor\'s newest spot'));
|
||||
steps.push({ type: 'board', tiles: board.pick(), seconds: C.gateBoardSeconds });
|
||||
const nw = board.newest(3, sSpot ? [sSpot.id] : []);
|
||||
for (const s of nw) { const cr = board.creative(s); steps.push(await visitStep('newest', s.id, cr.img, cr.link, 'Spot #' + s.id)); }
|
||||
for (const s of nw) steps.push(await stepOf('newest', s, 'Spot #' + s.id));
|
||||
const house = cfgMod.house().filter(h => h.link.startsWith('https://')); let hi = 0;
|
||||
while (steps.filter(x => x.role === 'newest' || x.role === 'house').length < 3 && house.length) { const h = house[hi++ % house.length]; steps.push(await visitStep('house', 'h-' + h.key, h.img, h.link, h.title)); if (hi > 6) break; }
|
||||
const gid = crypto.randomBytes(12).toString('hex');
|
||||
@@ -244,7 +246,44 @@ function spotView(s) {
|
||||
const left = Math.max(0, C.spotDays - Math.floor((now - s.boughtAt) / 86400000));
|
||||
return { id: s.id, kind: s.kind, boughtAt: s.boughtAt, tx: s.tx, valueWei: s.valueWei, views: v.total, gateViews: v.gate, owed: C.viewsOwed,
|
||||
clicks: store.clicks(s.id), daysLeft: left, delivering: s.kind !== 3 && left > 0 && v.total < C.viewsOwed,
|
||||
img: m.img || '', link: m.link || '', showing: cr };
|
||||
img: m.img || '', link: m.link || '', showing: cr,
|
||||
down: (dn => dn ? { at: dn.at, reason: dn.reason } : null)(store.spotDown(s.id)), // taken down by the admin: the owner sees the reason
|
||||
edits: store.spotEdits(s.id).slice(-10).reverse() };
|
||||
}
|
||||
|
||||
// ---- spot edits (Marty 2026-11-16): unlimited, every one gets the full check and is logged on the spot ----
|
||||
// checkLink first; then (LINK_PROBE on) the link must answer (safety.probeLink, up to 3 checked redirects) and an image address
|
||||
// must download as a real 468x60 image (safety.probeImage). The one exception: the Banner Spin image + click link LinkSpin's signed
|
||||
// answer just handed this member (/api/my/lsspins/use) are not fetched (fetching the click link would count a click on LinkSpin).
|
||||
const lsVouched = new Map(); // wallet -> { link, img, at }
|
||||
async function checkEdit(me, b, linkLabel) {
|
||||
const out = {};
|
||||
if (b.link !== undefined) { if (b.link === '') out.link = ''; else { const r = safety.checkLink(b.link, linkLabel); if (r.error) return r; out.link = r.url; } }
|
||||
if (b.img !== undefined && !String(b.img).startsWith('/art/u/')) { if (b.img === '') out.img = ''; else { const r = safety.checkLink(b.img, 'Image URL'); if (r.error) return r; out.img = r.url; } }
|
||||
if (C.linkProbe) {
|
||||
const v = lsVouched.get(me); const vouched = x => !!v && Date.now() - v.at < 30 * 60000 && (x === v.link || x === v.img);
|
||||
if (out.link && !vouched(out.link)) { const pr = await safety.probeLink(out.link.replace(/\{(clickid|spot|type)\}/g, 'x')); if (pr.error) return pr; }
|
||||
if (out.img && !vouched(out.img)) { const pr = await safety.probeImage(out.img); if (pr.error) return pr; }
|
||||
}
|
||||
return { ok: true, out };
|
||||
}
|
||||
// one log row per real change: old and new link and image, when, how (edit, upload)
|
||||
function logChange(kind, key, before, patch, via) {
|
||||
const o = { img: (before && before.img) || '', link: (before && before.link) || '' }; const n = Object.assign({}, o, patch);
|
||||
const what = ['link', 'img'].filter(k => o[k] !== n[k]); if (!what.length) return null;
|
||||
const row = { what: what.length === 2 ? 'both' : what[0], old: o, new: { img: n.img, link: n.link }, via };
|
||||
return kind === 'spot' ? store.logSpotEdit(key, row) : store.logDefaultEdit(key, row);
|
||||
}
|
||||
const DOWN_EDIT = 'This spot was taken down, so it cannot be changed. The reason is shown on the spot.';
|
||||
// "credit back" has no meaning on Downline Banners yet (2026-11-16): a spot is a $5 on-chain purchase (POL cannot be refunded) and
|
||||
// the site has no free replacement spot or post credit. Marty decides; until then a takedown is "no credit" only.
|
||||
const CREDIT_BACK_PENDING = 'Credit back is not available on Downline Banners yet: a spot is a $5 on-chain purchase and this site has no free replacement spot or post credit. Marty decides what credit back means; until then choose credit: "none".';
|
||||
// the admin view of a spot: what it shows, its views, every edit, and its takedown history
|
||||
async function adminSpot(s) {
|
||||
const m = store.spotMeta(s.id) || {}; const v0 = store.views(s.id);
|
||||
return { id: s.id, owner: s.owner, username: await nameOf(s.owner).catch(() => null), kind: s.kind, boughtAt: s.boughtAt, tx: s.tx,
|
||||
img: m.img || '', link: m.link || '', showing: board.creative(s), views: v0.total + dlbnas.spotServed(s.id), owed: C.viewsOwed, clicks: store.clicks(s.id),
|
||||
down: store.spotDown(s.id), downs: store.spotDowns(s.id), edits: store.spotEdits(s.id).slice(-50).reverse(), defaultEdits: store.defaultEdits(s.owner).slice(-10).reverse() };
|
||||
}
|
||||
async function myData(addr) {
|
||||
const a = addr.toLowerCase();
|
||||
@@ -297,13 +336,13 @@ const server = http.createServer(async (req, res) => {
|
||||
const net = old && OR[old]; res.writeHead(301, { Location: net ? '/?ref=' + encodeURIComponent(net) : '/', 'Cache-Control': 'no-store' }); return res.end();
|
||||
}
|
||||
const PAGES = { '/': 'index.html', '/board': 'board.html', '/join': 'join.html', '/my': 'my.html', '/how': 'how.html', '/ledger': 'ledger.html', '/contract': 'contract.html',
|
||||
'/terms': 'terms.html', '/disclaimer': 'disclaimer.html', '/privacy': 'privacy.html' }; // legal pages: trust pack 2026-11-14
|
||||
'/terms': 'terms.html', '/disclaimer': 'disclaimer.html', '/privacy': 'privacy.html', '/admin': 'admin.html' }; // legal pages: trust pack 2026-11-14; /admin 2026-11-16
|
||||
if (PAGES[p]) {
|
||||
const set = [];
|
||||
if (setVid) set.push(setVid);
|
||||
if (u.searchParams.get('ref')) { const a = await resolveRef(u.searchParams.get('ref')); if (a) set.push(cookie('bl.ref', a, 90 * 86400, false)); }
|
||||
const ex = set.length ? { 'Set-Cookie': set } : {};
|
||||
if (p === '/my') ex['X-Frame-Options'] = 'DENY'; // member board: never framed (public pages stay frameable for traffic exchanges)
|
||||
if (p === '/my' || p === '/admin') ex['X-Frame-Options'] = 'DENY'; // member board + admin: never framed (public pages stay frameable for traffic exchanges)
|
||||
return sendFile(res, path.join(PUB, PAGES[p]), ex);
|
||||
}
|
||||
if (/^\/r\/[^/]+$/.test(p)) { res.writeHead(302, { Location: '/?ref=' + encodeURIComponent(decodeURIComponent(p.slice(3))) }); return res.end(); }
|
||||
@@ -482,32 +521,40 @@ const server = http.createServer(async (req, res) => {
|
||||
const me = s.address;
|
||||
if (p === '/api/my' && req.method === 'GET') return json(res, 200, await myData(me));
|
||||
if (p === '/api/my/lsspins' && req.method === 'GET') { const r = await lsSpins({ wallet: me }); return json(res, r.error ? 502 : 200, r); }
|
||||
if (p === '/api/my/lsspins/use' && req.method === 'POST') { const b = await readBody(req); const r = await lsSpins({ wallet: me, spinId: Number(b.spinId) || 0 }); return json(res, r.error ? 400 : 200, r); }
|
||||
if (p === '/api/my/lsspins/use' && req.method === 'POST') { const b = await readBody(req); const r = await lsSpins({ wallet: me, spinId: Number(b.spinId) || 0 });
|
||||
if (!r.error && r.use) { const lk = safety.checkLink(r.use.link, 'link'), im = safety.checkLink(r.use.img, 'img'); if (lk.ok && im.ok) lsVouched.set(me, { link: lk.url, img: im.url, at: Date.now() }); if (lsVouched.size > 20000) lsVouched.clear(); }
|
||||
return json(res, r.error ? 400 : 200, r); }
|
||||
let m = /^\/api\/my\/spot\/(\d+)$/.exec(p);
|
||||
if (m && req.method === 'POST') {
|
||||
const sp = chain.spot(m[1]); if (!sp || sp.owner !== me) return json(res, 403, { error: 'That spot is not yours.' });
|
||||
const b = await readBody(req); const out = {};
|
||||
if (b.link !== undefined) { if (b.link === '') out.link = ''; else { const r = safety.checkLink(b.link, 'Target link'); if (r.error) return json(res, 400, r); out.link = r.url; } }
|
||||
if (b.img !== undefined && !String(b.img).startsWith('/art/u/')) { if (b.img === '') out.img = ''; else { const r = safety.checkLink(b.img, 'Image URL'); if (r.error) return json(res, 400, r); out.img = r.url; } }
|
||||
return json(res, 200, { ok: true, meta: store.setSpotMeta(sp.id, out) });
|
||||
if (store.spotDown(sp.id)) return json(res, 400, { error: DOWN_EDIT });
|
||||
if (limited(req, 'edit', 120, 3600000)) return json(res, 429, { error: 'Too many changes this hour. Try again in a while.' }); // each change fetches the link
|
||||
const b = await readBody(req); const ck = await checkEdit(me, b, 'Target link'); if (ck.error) return json(res, 400, ck);
|
||||
if (store.spotDown(sp.id)) return json(res, 400, { error: DOWN_EDIT }); // re-checked after the fetches
|
||||
const before = Object.assign({}, store.spotMeta(sp.id) || {});
|
||||
const meta = store.setSpotMeta(sp.id, ck.out); const edit = logChange('spot', sp.id, before, ck.out, 'edit');
|
||||
return json(res, 200, { ok: true, meta, edit });
|
||||
}
|
||||
if (p === '/api/my/default' && req.method === 'POST') {
|
||||
const b = await readBody(req); const out = {};
|
||||
if (b.link !== undefined) { if (b.link === '') out.link = ''; else { const r = safety.checkLink(b.link, 'Default link'); if (r.error) return json(res, 400, r); out.link = r.url; } }
|
||||
if (b.img !== undefined && !String(b.img).startsWith('/art/u/')) { if (b.img === '') out.img = ''; else { const r = safety.checkLink(b.img, 'Image URL'); if (r.error) return json(res, 400, r); out.img = r.url; } }
|
||||
return json(res, 200, { ok: true, defaults: store.setMemberDefault(me, out) });
|
||||
if (limited(req, 'edit', 120, 3600000)) return json(res, 429, { error: 'Too many changes this hour. Try again in a while.' });
|
||||
const b = await readBody(req); const ck = await checkEdit(me, b, 'Default link'); if (ck.error) return json(res, 400, ck);
|
||||
const before = Object.assign({}, store.memberDefault(me) || {});
|
||||
const defaults = store.setMemberDefault(me, ck.out); const edit = logChange('default', me, before, ck.out, 'edit');
|
||||
return json(res, 200, { ok: true, defaults, edit });
|
||||
}
|
||||
if (p === '/api/my/upload' && req.method === 'POST') {
|
||||
if (limited(req, 'upload', 40, 3600000)) return json(res, 429, { error: 'Too many uploads this hour.' });
|
||||
const target = u.searchParams.get('for') || '';
|
||||
let sp = null;
|
||||
if (target !== 'default') { sp = chain.spot(target); if (!sp || sp.owner !== me) return json(res, 403, { error: 'That spot is not yours.' }); }
|
||||
if (target !== 'default') { sp = chain.spot(target); if (!sp || sp.owner !== me) return json(res, 403, { error: 'That spot is not yours.' }); if (store.spotDown(sp.id)) return json(res, 400, { error: DOWN_EDIT }); }
|
||||
let buf; try { buf = await readRaw(req, safety.MAX_UPLOAD + 1); } catch (e) { return json(res, 400, { error: 'The file is over 150 KB.' }); }
|
||||
const r = safety.checkImage(buf); if (r.error) return json(res, 400, r);
|
||||
const name = (sp ? 's' + sp.id : 'd' + me.slice(2, 10)) + '-' + crypto.randomBytes(5).toString('hex') + r.info.ext;
|
||||
fs.writeFileSync(path.join(C.dataDir, 'art', name), buf);
|
||||
const img = '/art/u/' + name;
|
||||
const before = Object.assign({}, (sp ? store.spotMeta(sp.id) : store.memberDefault(me)) || {});
|
||||
if (sp) store.setSpotMeta(sp.id, { img }); else store.setMemberDefault(me, { img });
|
||||
logChange(sp ? 'spot' : 'default', sp ? sp.id : me, before, { img }, 'upload');
|
||||
return json(res, 200, { ok: true, img });
|
||||
}
|
||||
return json(res, 404, { error: 'Not found' });
|
||||
@@ -569,6 +616,51 @@ const server = http.createServer(async (req, res) => {
|
||||
gifted: chain.fundBuys().filter(f => f.giftee === a), contract: C.contract, explorer: C.explorer }));
|
||||
}
|
||||
|
||||
// -- admin: spot takedown and restore (Marty 2026-11-16, the Viral Banner Blitz way). The spot is a $5 on-chain purchase: the
|
||||
// contract is never touched; only what this site shows and counts changes. Taken down = hidden everywhere at once (board, gate,
|
||||
// /go, Network Ad Space), its place held by a house tile so nobody else moves, no views or clicks counted while down; the owner
|
||||
// sees "Taken down" with the reason; one admin ledger row per takedown and restore.
|
||||
if (p === '/api/admin/spots' || p === '/api/admin/actions' || /^\/api\/admin\/spots\/\d{1,9}\/(takedown|restore)$/.test(p)) {
|
||||
const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' });
|
||||
if (p === '/api/admin/actions' && req.method === 'GET') return json(res, 200, { actions: store.adminLogs(Math.min(500, Math.max(1, Number(u.searchParams.get('n')) || 100))) });
|
||||
// GET ?q=#<id> | <id> | <wallet> | <username>
|
||||
if (p === '/api/admin/spots' && req.method === 'GET') {
|
||||
const q = String(u.searchParams.get('q') || '').trim(); let list = [];
|
||||
if (/^#?\d{1,9}$/.test(q)) { const sp = chain.spot(Number(q.replace('#', ''))); if (sp) list = [sp]; }
|
||||
else if (ADDR_RE.test(q)) list = chain.spotsOf(q.toLowerCase());
|
||||
else if (/^@?[a-zA-Z0-9_]{1,20}$/.test(q)) {
|
||||
const name = q.replace(/^@/, '').toLowerCase(); const al = Object.entries(aliases()).find(([, v]) => v && String(v.username || '').toLowerCase() === name);
|
||||
const a = al ? al[0] : await resolveRef(name).catch(() => null); if (a) list = chain.spotsOf(a);
|
||||
}
|
||||
if (!list.length) return json(res, 404, { error: 'No spot found for that.' });
|
||||
return json(res, 200, { spots: await Promise.all(list.slice(0, 100).map(adminSpot)) });
|
||||
}
|
||||
const tk = /^\/api\/admin\/spots\/(\d{1,9})\/(takedown|restore)$/.exec(p);
|
||||
if (tk && req.method === 'POST') {
|
||||
const sp = chain.spot(Number(tk[1])); if (!sp) return json(res, 404, { error: 'No such spot.' });
|
||||
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 username = await nameOf(sp.owner).catch(() => null);
|
||||
if (tk[2] === 'takedown') {
|
||||
if (store.spotDown(sp.id)) return json(res, 400, { error: 'That spot is already taken down.' });
|
||||
if (sp.kind === 3) return json(res, 400, { error: 'A fund-kept spot never shows, so there is nothing to take down.' });
|
||||
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') return json(res, 400, { error: CREDIT_BACK_PENDING });
|
||||
if (b.credit !== 'none') return json(res, 400, { error: 'Choose credit: "none". (Credit back is not available on Downline Banners yet.)' });
|
||||
const rec = store.setSpotDown(sp.id, { at: Date.now(), by, reason, credit: 'none', views: store.views(sp.id).total });
|
||||
const nas = await dlbnas.pause(sp.id).catch(e => 'error: ' + String(e.message).slice(0, 80));
|
||||
const e = store.adminLog({ action: 'takedown', spotId: sp.id, owner: sp.owner, username, by, reason, credit: 'none', nas });
|
||||
return json(res, 200, { ok: true, spot: await adminSpot(sp), down: rec, log: e });
|
||||
}
|
||||
const was = store.spotDown(sp.id); if (!was) return json(res, 400, { error: 'That spot is not taken down.' });
|
||||
store.clearSpotDown(sp.id, { restoredAt: Date.now(), restoredBy: by, restoreReason: reason || null });
|
||||
const nas = await dlbnas.resume(sp.id).catch(e => 'error: ' + String(e.message).slice(0, 80));
|
||||
const e = store.adminLog({ action: 'restore', spotId: sp.id, owner: sp.owner, username, by, reason: reason || null, credit: 'none given', nas });
|
||||
return json(res, 200, { ok: true, spot: await adminSpot(sp), log: e });
|
||||
}
|
||||
return json(res, 404, { error: 'Not found' });
|
||||
}
|
||||
|
||||
if (p.startsWith('/api/')) return json(res, 404, { error: 'Not found' });
|
||||
res.writeHead(404, headers({ 'Content-Type': 'text/html; charset=utf-8' }));
|
||||
return res.end('<!doctype html><title>Not found</title><body style="background:#09080f;color:#f3f1fa;font-family:sans-serif;text-align:center;padding:40px 16px"><p>Not found. <a style="color:#c6f432" href="/">Downline Banners home</a></p>'
|
||||
@@ -603,7 +695,7 @@ function weekLine() {
|
||||
hubreport.init({ dataDir: C.dataDir, members: () => chain.allMembers() });
|
||||
refuelspots.init({ lock: () => keeper.busy() }); keeper.setOtherBusy(() => refuelspots.busy());
|
||||
keeper.init();
|
||||
dlbnas.init({ spots: () => chain.spots(), views: id => store.views(id).total, creative: board.creative });
|
||||
dlbnas.init({ spots: () => chain.spots(), views: id => store.views(id).total, creative: board.creative, isDown: id => !!store.spotDown(id) });
|
||||
// members' LinkSpin Banner Spins for empty board slots: one active 468x60 spin per member, refreshed every 10 minutes
|
||||
const refreshSpins = async () => {
|
||||
const out = [];
|
||||
|
||||
Reference in New Issue
Block a user