Files
martbost a428075330 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>
2026-11-16 05:23:54 -06:00

100 lines
6.3 KiB
JavaScript

// Board rotation, creatives, and the frame check for gate visits.
// A spot is owed cfg.viewsOwed views (300) inside cfg.spotDays (30) from purchase. Newest spots sit on top;
// the 3 newest are always shown, the rest of the slots go to the spots furthest behind on delivery
// (views still owed per hour left), and any empty slot is filled with member Banner Spins, then house ads.
const cfgMod = require('./config');
const chain = require('./chain');
const store = require('./store');
const DAY = 86400000;
function creative(spot) {
// taken down by the admin (2026-11-16): the spot keeps its place but shows a house banner, nothing of its own
if (store.spotDown(spot.id)) { const h = houseFor(spot.id); return { img: h.img, link: h.link, from: 'down', key: h.key, title: h.title }; }
const m = store.spotMeta(spot.id);
if (m && m.img && m.link) return { img: m.img, link: m.link, from: 'spot' };
const d = store.memberDefault(spot.owner);
if (d && d.img && d.link) return { img: d.img, link: (m && m.link) || d.link, from: 'default' };
if ((m && m.link) || (d && d.link)) return { img: (m && m.img) || (d && d.img) || houseFor(spot.id).img, link: (m && m.link) || d.link, from: 'link-only' };
const h = houseFor(spot.id); return { img: h.img, link: h.link, from: 'house' };
}
function houseFor(n) { const h = cfgMod.house(); return h[Math.abs(Number(n) || 0) % h.length]; }
function eligible(now) {
const c = cfgMod.get(); now = now || Date.now();
return chain.spots().filter(s => s.kind !== 3 && now - s.boughtAt < c.spotDays * DAY && store.views(s.id).total < c.viewsOwed);
}
// Member LinkSpin Banner Spins fill empty slots before house ads (SPEC "house fill", built 2026-11-13). server.js refreshes the
// list every 10 minutes through LinkSpin's /api/partner/bl/spins (one active 468x60 spin per Downline Banners member); each board
// gets them in a fresh random order. [{ img, link, title }]
let SPINS = [];
function setMemberSpins(list) { SPINS = Array.isArray(list) ? list : []; }
function memberSpins() { const a = SPINS.slice(); for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; }
// a spot the admin took down holds its place on the board with a house tile: no image, owner, link or number of its own, and
// t 'house' so no view or click is ever counted for it
function heldTile(s) { const h = houseFor(s.id); return { t: 'house', key: h.key, img: h.img, href: '/go/h-' + h.key, title: h.title, note: h.note || '', held: true }; }
function spotTile(s) {
if (store.spotDown(s.id)) return heldTile(s);
const c = cfgMod.get(); const cr = creative(s); const v = store.views(s.id);
return { t: 'spot', id: s.id, owner: s.owner, img: cr.img, href: '/go/' + s.id, views: v.total, owed: c.viewsOwed, kind: s.kind };
}
function pick(n) {
n = n || cfgMod.get().boardSlots; const now = Date.now(); const c = cfgMod.get();
const el = eligible(now); // newest first
const chosen = el.slice(0, Math.min(3, n));
const rest = el.slice(chosen.length).map(s => {
const left = Math.max(1, c.spotDays * DAY - (now - s.boughtAt)) / 3600000;
return { s, u: (c.viewsOwed - store.views(s.id).total) / left + Math.random() * 1e-6 };
}).sort((a, b) => b.u - a.u).slice(0, n - chosen.length).map(x => x.s);
const tiles = chosen.concat(rest).sort((a, b) => b.id - a.id).map(spotTile);
// no repeats on one board (Marty 2026-11-13: the same banner showed twice): a member whose spot is already here gets no fill
// tile, and no image or Banner Spin appears twice
const code = u => (String(u || '').match(/\/[ic]\/([a-z0-9]+)/i) || [])[1] || String(u || '');
const owners = new Set(tiles.map(t => t.owner).filter(Boolean)); const used = new Set(tiles.map(t => code(t.img)));
for (const sp of memberSpins()) {
if (tiles.length >= n) break;
if ((sp.owner && owners.has(sp.owner)) || used.has(code(sp.img))) continue;
used.add(code(sp.img)); if (sp.owner) owners.add(sp.owner);
tiles.push({ t: 'spin', img: sp.img, href: sp.link, title: sp.title });
}
const house = cfgMod.house(); let i = Math.floor(Math.random() * house.length);
const stop = Math.min(n, tiles.length + house.length); // each house entry at most once per board
while (tiles.length < stop) { const h = house[i++ % house.length]; tiles.push({ t: 'house', key: h.key, img: h.img, href: '/go/h-' + h.key, title: h.title, note: h.note || '' }); }
return tiles;
}
// newest spot of an address (gate step 1), any kind except fund-kept
function newestOf(addr) { const a = String(addr || '').toLowerCase(); return chain.spots().find(s => s.owner === a && s.kind !== 3) || null; }
function newest(k, exclude) { const ex = new Set(exclude || []); return chain.spots().filter(s => s.kind !== 3 && !ex.has(s.id)).slice(0, k); }
// ---- frame check (IAP login-gate pattern): a site that refuses framing opens in a new tab instead ----
const frameCache = new Map();
async function frameable(url) {
if (!/^https:\/\//i.test(url || '')) return url && url.startsWith('/');
const hit = frameCache.get(url); if (hit && Date.now() - hit.at < 6 * 3600000) return hit.ok;
let ok = false;
try {
const ac = new AbortController(); const t = setTimeout(() => ac.abort(), 4000);
const r = await fetch(url, { method: 'GET', redirect: 'follow', signal: ac.signal, headers: { 'User-Agent': 'Mozilla/5.0 (compatible; BannerLineFrameCheck/1.0)' } });
clearTimeout(t);
const xfo = String(r.headers.get('x-frame-options') || '').toLowerCase();
const csp = String(r.headers.get('content-security-policy') || '').toLowerCase();
const fa = /frame-ancestors([^;]*)/.exec(csp);
ok = !xfo && !(fa && !/\*|https:/.test(fa[1]));
try { r.body && r.body.cancel && r.body.cancel(); } catch (e) {}
} catch (e) { ok = false; }
frameCache.set(url, { at: Date.now(), ok });
if (frameCache.size > 5000) frameCache.clear();
return ok;
}
function target(ref) {
if (/^h-/.test(ref)) { const h = cfgMod.house().find(x => 'h-' + x.key === ref); return h ? { link: h.link, spotId: null } : null; }
const s = chain.spot(Number(ref)); if (!s || s.kind === 3 || store.spotDown(s.id)) return null; // taken down: /go/<id> goes home
return { link: creative(s).link, spotId: s.id };
}
module.exports = { creative, eligible, pick, newestOf, newest, frameable, target, memberSpins, setMemberSpins, houseFor };