Banner Spin engine (phase 1): /i/ image with no-store + fresh ETag, /c/ click matching (visitor key + placement host note, 15 min) with fallback, /s/ exact-match script embed, impression counters flushed every 5 s (read-add-write), banner clicks with lsid conversions + source postbacks, tiers ($25 own package; Starter 2x5, Builder 5x15, Leader 10x25), member + admin API, admin kill switch per Banner Spin / per banner / global, Banner Spins in admin Member content

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-18 10:58:44 -05:00
parent e0e0bde1f9
commit 406113bc03
6 changed files with 507 additions and 11 deletions
+20 -2
View File
@@ -11,11 +11,11 @@
const fs = require('fs');
const path = require('path');
let R = null; // { dataDir, uploadsDir, accounts, pages, rotator, sources, zones, ads, postbacks, audiences, messages, videomaker, reports, domains, adminEmail, houseOwner, linkHost(), pagesHost(), siteHost }
let R = null; // { dataDir, uploadsDir, accounts, pages, rotator, bannerspin, sources, zones, ads, postbacks, audiences, messages, videomaker, reports, domains, adminEmail, houseOwner, linkHost(), pagesHost(), siteHost }
function init(refs) { R = refs; }
const TYPES = [
{ key: 'page', label: 'Pages' }, { key: 'link', label: 'Links' }, { key: 'source', label: 'Sources' }, { key: 'zone', label: 'Zones' },
{ key: 'page', label: 'Pages' }, { key: 'link', label: 'Links' }, { key: 'bannerspin', label: 'Banner Spins' }, { key: 'source', label: 'Sources' }, { key: 'zone', label: 'Zones' },
{ key: 'ad', label: 'Ads' }, { key: 'postback', label: 'Postbacks' }, { key: 'upload', label: 'Uploads' }, { key: 'profile', label: 'Profiles' },
{ key: 'message', label: 'Broadcasts' }, { key: 'audience', label: 'Audiences' }, { key: 'video', label: 'Videos' }
];
@@ -81,6 +81,23 @@ async function collect(fresh) {
search: [r.code].concat(r.destinations.map(d => d.url + ' ' + (d.label || '')), r.fallback) });
}
// Banner Spins (2026-10-18): one image URL + one click URL rotating the member's banners; admin can take a banner or the whole thing offline
if (R.bannerspin) for (const b of R.bannerspin.adminAll()) {
const flags = [];
if (b.adminOff) flags.push({ k: 'off', t: 'Taken offline by admin' + (b.adminNote ? ': ' + b.adminNote : '') });
const offB = b.banners.filter(x => x.adminOff); if (offB.length) flags.push({ k: 'off', t: offB.length + ' banner' + (offB.length > 1 ? 's' : '') + ' taken offline by admin' });
const live = !b.adminOff && !b.paused && b.banners.some(x => x.active && !x.adminOff);
const stamp = 'Taken offline from Member content ' + ctDay(Date.now());
const actions = [b.adminOff ? { label: 'Put Banner Spin back online', path: '/api/admin/bannerspins/' + b.id, body: { off: false, note: '' } } : { label: 'Take Banner Spin offline', path: '/api/admin/bannerspins/' + b.id, body: { off: true, note: stamp }, warn: 'Take this Banner Spin offline? Every placement shows a blank image and clicks go to its fallback.' }]
.concat(b.banners.map(x => x.adminOff ? { label: 'Banner ' + x.id + ' back online', path: '/api/admin/bannerspins/' + b.id, body: { bannerId: x.id, off: false, note: '' } } : { label: 'Banner ' + x.id + ' offline', path: '/api/admin/bannerspins/' + b.id, body: { bannerId: x.id, off: true, note: stamp }, warn: 'Take banner ' + x.id + ' offline? The Banner Spin keeps rotating the others.' }));
add({ type: 'bannerspin', id: String(b.id), ownerEmail: b.owner, title: b.name, created: b.created, status: b.adminOff ? 'offline' : b.paused ? 'paused' : live ? 'live' : 'empty', live,
url: 'https://' + linkHost + '/i/' + b.code + '.gif', open: null,
detail: { code: b.code, size: b.size, mode: b.mode, image: 'https://' + linkHost + '/i/' + b.code + '.gif', click: 'https://' + linkHost + '/c/' + b.code, fallback: b.fallback, fallbackImage: b.fallbackImage, dayparted: b.dayparted, sourceId: b.sourceId,
banners: b.banners.map(x => ({ id: x.id, label: x.label, image: x.image, target: x.target, link: x.link, weight: x.weight, active: x.active, adminOff: x.adminOff })) },
counts: { imps: b.imps, clicks: b.clicks, conversions: b.conversions }, hosts: b.banners.map(x => hostOf(x.target)).concat(hostOf(b.fallback), b.banners.map(x => hostOf(x.image))), flags, actions,
search: [b.code, b.size, b.fallback].concat(b.banners.map(x => x.image + ' ' + x.target + ' ' + (x.label || ''))) });
}
// traffic sources
for (const s of R.sources.adminAll()) add({ type: 'source', id: s.id, ownerEmail: s.owner, title: s.name, created: s.created, status: s.enabled ? 'live' : 'off', live: !!s.enabled, url: s.site ? 'https://' + s.site : '', open: null,
detail: { template: s.template, site: s.site, costModel: s.costModel, postbackUrl: s.postbackUrl, method: s.method, events: s.events, params: (s.params || []).length, lastStatus: s.lastStatus },
@@ -133,6 +150,7 @@ async function collect(fresh) {
const camps = await R.ads.adminList(1000000);
for (const c of camps) { if (c.house) continue; const blob = JSON.stringify([c.imageUrl, c.body]); let m; UP_RE.lastIndex = 0; while ((m = UP_RE.exec(blob))) ref(m[1], c.owner, 'campaign #' + c.id + ' (' + c.type + ')'); }
} catch (e) {}
try { if (R.bannerspin) for (const [f, x] of Object.entries(R.bannerspin.imageRefs())) if (x.where) ref(f, x.email, x.where); } catch (e) {}
const idx = readIdx();
let files = []; try { files = fs.readdirSync(R.uploadsDir).filter(f => /^[a-z0-9]{24}\.(png|jpg|webp|gif|mp4|webm)$/i.test(f)); } catch (e) {}
const seenUp = new Set();