Zones: ad slots on members' own sites (LinkSpin campaign > Network Ad Space > house waterfall, viewable-impression credits, /zones screen)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-29 17:20:19 -05:00
parent 53f5d51821
commit e66a38dd74
11 changed files with 218 additions and 2 deletions
+30 -1
View File
@@ -40,7 +40,8 @@ const registry = require('./registry'); // network registry: who is who ac
const carry = require('./carry'); // sponsor carry-over: engine activation, claim window, notices
const rotator = require('./rotator');
const postbacks = require('./postbacks'); // outbound + inbound conversion postbacks on rotator clicks (2026-09-29)
const pages = require('./pages'); // member pages: bridge / review / squeeze, served at /p/<slug> (2026-09-29) // the rotator: rotations, weighted destinations, /r/<code>
const pages = require('./pages'); // member pages: bridge / review / squeeze, served at /p/<slug> (2026-09-29)
const zones = require('./zones'); // ad zones on members' own sites (2026-09-29) // the rotator: rotations, weighted destinations, /r/<code>
const snapshot = require('./snapshot'); // daily growth snapshot -> Telegram payments feed (Marty, 2026-09-15)
const pipeline = require('./pipeline'); // sponsor follow-up board (coming soon until site setting pipelineMode = on) (Marty, 2026-09-15)
const videomaker = require('./videomaker'); // Circuit tool: promo videos with the member's own end card (ffmpeg in the image) // badge-gated promo toolkit + AI Copy Engine (Surge and up) (Marty, 2026-09-14) // referral contest: /leaderboard, Overview card, weekly + monthly winners (Marty, 2026-09-14) // release notes + roadmap: /whats-new, Overview card, Admin > Releases (Marty, 2026-09-14) // blog -> Blotato -> X + Instagram on publish (Marty, 2026-09-13) // admin member card: search, drilldown, edits (Marty, 2026-09-13) // admin-written coaching articles, server-rendered public /blog with SEO metadata (Marty, 2026-09-12)
@@ -390,6 +391,7 @@ async function boot() {
const ownHosts = () => [SITE_HOST].concat(String(siteConfig().linkDomains || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean));
rotator.init({ dataDir: DATA_DIR, geo, ownHosts });
postbacks.init({ dataDir: DATA_DIR, ownHosts, rotator });
zones.init({ dataDir: DATA_DIR, ads, siteHost: SITE_HOST });
pages.init({ dataDir: DATA_DIR, ownHosts, openrouterKey: () => { if (process.env.OPENROUTER_API_KEY) return process.env.OPENROUTER_API_KEY.trim(); try { return fs.readFileSync(path.join(DATA_DIR, 'openrouter.key'), 'utf8').trim(); } catch (e) { return ''; } } });
snapshot.init({ dataDir: DATA_DIR, db, chain, siteConfig, send: async (c, t, th) => { await telegramSend(c, t, th); return true; } });
setInterval(() => snapshot.tick().catch(e => console.error('snapshot', e.message)), 10 * 60 * 1000);
@@ -875,6 +877,19 @@ const server = http.createServer(async (req, res) => {
if (hit && hit.url) { res.writeHead(302, { Location: hit.url, 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer-when-downgrade' }); return res.end(); }
res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end(linkSitePage(reqHost(req), 'gone'));
}
// -- ad zones on members' sites: the tag, the ad, the viewable beacon, the click. Any origin may call these.
if (p === '/z.js') { const zf = path.join(PUBLIC_DIR, 'z.js'); try { const body = fs.readFileSync(zf); res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=300', 'Access-Control-Allow-Origin': '*' }); return res.end(body); } catch (e) {} }
if (p === '/api/zone/serve' && req.method === 'GET') {
const ad = await zones.serve(u.searchParams.get('z'), req, viewerGeo(req));
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', 'Access-Control-Allow-Origin': '*' }); return res.end(JSON.stringify({ ad }));
}
if (p === '/z/nas' && req.method === 'GET') { // the frame a Network Ad Space fallback renders in
const html = zones.nasFrame(String(u.searchParams.get('s') || ''));
if (!html) { res.writeHead(404); return res.end(); }
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'Content-Security-Policy': "default-src 'none'; script-src https://www.networkadspace.com https://networkadspace.com 'unsafe-inline'; img-src https: http: data:; style-src 'unsafe-inline'; frame-src https: http:; frame-ancestors *; base-uri 'none'", 'Referrer-Policy': 'no-referrer' }); return res.end(html);
}
if (p === '/api/zone/seen' && (req.method === 'GET' || req.method === 'POST')) { await zones.seen(u.searchParams.get('i'), req); res.writeHead(204, { 'Access-Control-Allow-Origin': '*' }); return res.end(); }
{ const zm = /^\/api\/zone\/click\/([a-f0-9]{12})$/.exec(p); if (zm && req.method === 'GET') { const target = await zones.click(zm[1]); res.writeHead(302, { Location: target || '/', 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer-when-downgrade' }); return res.end(); } }
// -- member pages: /p/<slug> on the app host and on every link domain; the lead form and the hit beacon live beside it
let pm = /^\/p\/([a-z0-9-]{3,60})$/i.exec(p);
if (pm && (req.method === 'GET' || req.method === 'HEAD')) {
@@ -1831,6 +1846,19 @@ const server = http.createServer(async (req, res) => {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const r = await rotator.stats(s.email, m[1]); return r ? json(res, 200, r, { 'Cache-Control': 'no-store' }) : json(res, 404, { error: 'No such rotation.' });
}
if (p === '/api/my/zones' && req.method === 'GET') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
return json(res, 200, { zones: await zones.list(s.email), host: SITE_HOST, sizes: Object.keys(zones.SIZES), rates: zones.settings() }, { 'Cache-Control': 'no-store' });
}
if (p === '/api/my/zones' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const r = await zones.create(s.email, await readBody(req)); return json(res, r.error ? 400 : 200, r);
}
m = /^\/api\/my\/zones\/(ls-[a-f0-9]{6})$/.exec(p);
if (m && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const r = await zones.update(s.email, m[1], await readBody(req)); return json(res, r.error ? 400 : 200, r);
}
if (p === '/api/my/pages' && req.method === 'GET') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const hosts = String(siteConfig().linkDomains || '').split(',').map(x => x.trim()).filter(x => x && !x.startsWith('www.'));
@@ -2896,6 +2924,7 @@ const server = http.createServer(async (req, res) => {
if (p === '/links') return sendFile(res, path.join(PUBLIC_DIR, 'links.html')); // Control Room: the links workspace, first screen of the new front end (2026-09-29)
if (p === '/reports') return sendFile(res, path.join(PUBLIC_DIR, 'reports.html'));
if (p === '/pages') return sendFile(res, path.join(PUBLIC_DIR, 'pages.html'));
if (p === '/zones') return sendFile(res, path.join(PUBLIC_DIR, 'zones.html'));
if (p === '/team') return sendFile(res, path.join(PUBLIC_DIR, 'team.html'));
if (p === '/wallet') return sendFile(res, path.join(PUBLIC_DIR, 'wallet.html'));
if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html'));