Admin route: house Banner Spins on the admin's own account, logged (Marty 2026-11-16)
POST /api/admin/house-spins creates or updates Banner Spins on a house account (ADMIN_EMAIL or NETWORK_LINKS_OWNER) for house ads such as the Network Ad Space rows, through the same bannerspin.js calls the member Links screen uses (create, update, addBanner, updateBanner). Admin auth only (portal session or the admin key); no member session is read or minted. Every call, denied ones too, goes to the new admin action log (adminaudit.js: MySQL table admin_audit, JSONL without a database) with who, what and when; GET /api/admin/house-spins/log reads it. qa/housespins.test.mjs (in run.sh netsrc) covers auth, house-account only, member checks, idempotent repeat, prune, serving + click attribution, the log and no session minted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,8 @@ const kit = require('./kit');
|
||||
const engine = require('./engine'); // the Engine Room (same file as InstantAdPay), 2026-10-24
|
||||
const kitspin = require('./kitspin'); // Refuel Kit -> Banner Spin loader // the Refuel Kit: monthly members-only LinkSpin banner sets, personalized per member (2026-10-24) // Monthly Refuel streak, LinkSpin side: reports $25+ packages to InstantAdPay (the source of truth), applies its grants (2026-10-24) // refill notices: low / out / idle, one message per owner, conversions tracked (2026-10-24)
|
||||
const bannerspin = require('./bannerspin'); // Banner Spin: one image URL + one click URL rotating up to 25 banners (2026-10-18)
|
||||
const housespins = require('./housespins'); // admin: house Banner Spins on the admin's own account, no member sign-in (2026-11-16)
|
||||
const adminaudit = require('./adminaudit'); // admin action log: who, what, when (2026-11-16)
|
||||
const sources = require('./sources'); // traffic sources: network macros, campaign URLs, per-source postbacks, Reports dimension (2026-10-12)
|
||||
const pages = require('./pages'); // member pages: bridge / review / squeeze, served at /p/<slug> (2026-09-29)
|
||||
const domains = require('./domains'); // link-domain pool by channel + six-hourly safety checks; burned domains leave the pool (2026-10-10)
|
||||
@@ -759,6 +761,9 @@ async function boot() {
|
||||
setInterval(() => { try { rotator.sweepDemos(); } catch (e) {} }, 60 * 60 * 1000); // unclaimed home-page demo spins expire after 24 h
|
||||
postbacks.init({ dataDir: DATA_DIR, ownHosts, rotator, sources });
|
||||
bannerspin.init({ dataDir: DATA_DIR, uploadsDir: UPLOADS_DIR, rotator, geo, sources, ownHosts, adminEmail: ADMIN_EMAIL, facts: bannerFacts, wantsClickId: (owner, url) => { if (convtrack.goalsOf(owner).length > 0) return true; try { return networkHosts().includes(new URL(url).hostname.toLowerCase().replace(/^www\./, '')); } catch (e) { return false; } }, withClickId: convtrack.withClickId });
|
||||
adminaudit.init({ dataDir: DATA_DIR });
|
||||
housespins.init({ bannerspin, houseAccounts: () => [ADMIN_EMAIL, String(process.env.NETWORK_LINKS_OWNER || '').trim().toLowerCase()].filter(Boolean),
|
||||
host: want => { const hs = domains.hosts().map(d => d.host); const w = String(want || '').trim().toLowerCase(); return hs.includes(w) ? w : (hs[0] || SITE_HOST); } });
|
||||
rotator.setExternalConvert((lsid, ev, facts) => /^[ai]/.test(String(lsid)) ? netconv.fromLinkSpin(lsid, ev, facts) : bannerspin.convert(lsid, ev, facts)); // Banner Spin click ids convert like spin-link clicks; ad clicks through the ledger
|
||||
netconv.init({ dataDir: DATA_DIR, convtrack, rotator, bannerspin, postbacks, marks });
|
||||
sources.init({ dataDir: DATA_DIR, postbacks, rotator, catalogFile: path.join(ROOT, 'catalog', 'traffic-sources.json'), linkHost: () => { const hs = String(siteConfig().linkDomains || '').split(',').map(x => x.trim()).filter(Boolean); return hs[0] || SITE_HOST; } });
|
||||
@@ -2846,6 +2851,28 @@ const server = http.createServer(async (req, res) => {
|
||||
else r = await bannerspin.update(s.email, m[1], b);
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
// House Banner Spins (Marty 2026-11-16): create or update Banner Spins on the admin's own account for house ads (the Network Ad
|
||||
// Space rows), through the same bannerspin.js calls as the member Links screen. Admin auth only (portal session or the admin key);
|
||||
// no member session is read or minted. Every call, denied ones too, goes to the admin action log (adminaudit.js) with who, what
|
||||
// and when. GET /api/admin/house-spins/log reads that log (?limit=, newest first). Body: housespins.js.
|
||||
if (p === '/api/admin/house-spins' && req.method === 'POST') {
|
||||
const adm = adminFromRequest(req); const ok = isAdmin(req);
|
||||
const actor = String(req.headers['x-admin-actor'] || '').replace(/[^\w .:@-]/g, '').slice(0, 60);
|
||||
const who = adm ? adm.email : ok ? 'admin key' + (actor ? ' (' + actor + ')' : '') : 'denied' + (actor ? ' (' + actor + ')' : '');
|
||||
let b = {}; try { b = await readBody(req, 256 * 1024); } catch (e) { b = null; }
|
||||
if (!ok) { await adminaudit.record({ who, action: 'house-spins', target: String((b && b.email) || '').slice(0, 190), ok: false, ip: clientIp(req), detail: { error: 'not admin' } }); return json(res, 401, { error: 'Admin only.' }); }
|
||||
if (!b) { await adminaudit.record({ who, action: 'house-spins', ok: false, ip: clientIp(req), detail: { error: 'bad body' } }); return json(res, 400, { error: 'Send JSON.' }); }
|
||||
const r = await housespins.apply(b);
|
||||
const summary = r.error ? { error: r.error } : { host: r.host, spins: r.spins.map(x => ({ id: x.id, code: x.code, name: x.name, size: x.size, sourceId: x.sourceId, created: x.created, added: x.added, updated: x.updated, removed: x.removed, banners: x.banners, errors: x.errors })),
|
||||
asked: (b.spins || []).map(x => ({ id: x.id, name: x.name, size: x.size, sourceId: x.sourceId, fallback: x.fallback, banners: (x.banners || []).map(y => ({ label: y.label, image: y.image, target: y.target })) })) };
|
||||
await adminaudit.record({ who, action: 'house-spins', target: String(b.email || '').trim().toLowerCase(), ok: !r.error && r.ok, ip: clientIp(req), detail: summary });
|
||||
if (!r.error) content.invalidate();
|
||||
return json(res, r.error ? 400 : 200, r, { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
if (p === '/api/admin/house-spins/log' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'Admin only.' });
|
||||
return json(res, 200, { entries: await adminaudit.list(u.searchParams.get('limit')) }, { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
// admin: every Banner Spin; the feature switch + tier grants (POST /api/admin/bannerspins { off } | { email, grant }); one Banner Spin or one banner off / on
|
||||
if (p === '/api/admin/bannerspins' && (req.method === 'GET' || req.method === 'POST')) {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'Admin only.' });
|
||||
|
||||
Reference in New Issue
Block a user