diff --git a/catalog/traffic-sources.json b/catalog/traffic-sources.json index 3ef0aaa..ea2b09a 100644 --- a/catalog/traffic-sources.json +++ b/catalog/traffic-sources.json @@ -1,4 +1,34 @@ [ + { + "key": "viralbannerblitz", + "name": "Viral Banner Blitz", + "site": "viralbannerblitz.com", + "costModel": "CPM", + "params": [ + { + "key": "clickid", + "token": "{clickid}", + "label": "Click id", + "role": "externalId" + }, + { + "key": "placement", + "token": "{spot}", + "label": "Banner number", + "role": "param" + }, + { + "key": "s1", + "token": "{type}", + "label": "Click type (loop or waiting)", + "role": "param" + } + ], + "postbackUrl": "", + "notes": "Crypto Team Build Network banner loop (125x125). Post a 125x125 Banner Spin in Viral Banner Blitz > My Banners: every click fills {clickid}, {spot} (the banner number) and {type}.", + "verified": true, + "source": "network" + }, { "key": "downlinebanners", "name": "Downline Banners", diff --git a/qa/partner-spins.test.mjs b/qa/partner-spins.test.mjs new file mode 100644 index 0000000..32ff8aa --- /dev/null +++ b/qa/partner-spins.test.mjs @@ -0,0 +1,56 @@ +// Banner Spins partner endpoint (/api/partner/bl/spins) for Downline Banners and Viral Banner Blitz (2026-11-14). +// Boots server.js on its own port with a throwaway seeded data dir (JSON store, no DB, no mail key, no chain keys) and checks: +// the NETWORK_SSO_SECRET signature, Downline Banners' 468x60 answer unchanged, { site: 'vbb' } = 125x125 + 250x250 spins with a +// "Viral Banner Blitz" source, the network-username fallback for vbb only, and the host in the answer. +// node qa/partner-spins.test.mjs (from the site dir; PORT default 8971) +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import crypto from 'node:crypto'; +import { spawn } from 'node:child_process'; + +const PORT = Number(process.env.PORT || 8971); const BASE = 'http://127.0.0.1:' + PORT; const SEC = crypto.randomBytes(32).toString('hex'); +let pass = 0, fail = 0; const ok = (c, what, x) => { if (c) { pass++; console.log(' ok ' + what); } else { fail++; console.log(' FAIL ' + what + (x !== undefined ? ' -> ' + JSON.stringify(x).slice(0, 400) : '')); } }; +const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'ps-qa-')); +const W1 = '0x' + '1'.repeat(40), W2 = '0x' + '2'.repeat(40), now = Date.now(); +const acct = (email, username, memberId, address) => Object.assign({ email, username, code: username.slice(0, 7), memberId, created: now - 86400000, sponsorRef: '' }, address ? { address } : {}); +const accounts = { v: 2, byEmail: { 'one@ps.test': acct('one@ps.test', 'psone', 910001, W1), 'two@ps.test': acct('two@ps.test', 'pstwo', 910002) }, byAddress: { [W1]: 'one@ps.test' }, byCode: {}, joins: 2, positions: {} }; +for (const a of Object.values(accounts.byEmail)) accounts.byCode[a.code] = a.email; +fs.writeFileSync(path.join(DATA, 'accounts.json'), JSON.stringify(accounts)); +const spin = (id, owner, size, code, extra) => Object.assign({ id, owner, name: 'Spin ' + id, code, size, mode: 'weight', fallback: '', fallbackImage: '', banners: [{ id: 1, image: '/x.png', link: 'https://t.example.org/', active: true, weight: 10 }], nextBanner: 2, paused: false, created: now }, extra || {}); +fs.writeFileSync(path.join(DATA, 'bannerspin.json'), JSON.stringify({ spins: [spin(1, 'one@ps.test', '468x60', 'qwhone'), spin(2, 'one@ps.test', '125x125', 'qwhtwo'), spin(3, 'one@ps.test', '250x250', 'qwhthr'), + spin(4, 'one@ps.test', '300x250', 'qwhfou'), spin(5, 'one@ps.test', '125x125', 'qwhfiv', { adminOff: true }), spin(6, 'two@ps.test', '125x125', 'qwhsix')], clicks: [], conv: [] })); +fs.writeFileSync(path.join(DATA, 'site.json'), JSON.stringify({ linkDomains: 'spin-links.test.org' })); +const env = Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, NETWORK_SSO_SECRET: SEC, ADMIN_PASSWORD: 'x'.repeat(16), ADMIN_EMAIL: 'admin@ps.test' }); +for (const k of ['NODE_ENV', 'DATABASE_URL', 'ENGINE_KEY', 'LS_SYNC_SECRET', 'OUTBOUND', 'LS_TESTERS', 'CURTAIN', 'HUB_ENABLED', 'HUB_URL']) delete env[k]; +const site = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..'); +const srv = spawn(process.execPath, ['server.js'], { cwd: site, env, stdio: ['ignore', 'ignore', 'ignore'] }); +const sleep = ms => new Promise(r => setTimeout(r, ms)); +async function call(body, o = {}) { + const raw = JSON.stringify(body); const ts = String(o.ts || Date.now()); const sig = crypto.createHmac('sha256', o.sec || SEC).update('net.v1.' + ts + '\n' + raw).digest('hex'); + const r = await fetch(BASE + '/api/partner/bl/spins', { method: 'POST', body: raw, headers: { 'Content-Type': 'application/json', 'X-Net-Ts': ts, 'X-Net-Sig': sig } }); + return Object.assign({ _status: r.status }, await r.json().catch(() => ({}))); +} +try { + for (let i = 0; i < 60; i++) { try { if ((await fetch(BASE + '/api/config')).ok) break; } catch (e) {} await sleep(500); } + let r = await call({ wallet: W1 }, { sec: 'y'.repeat(64) }); ok(r._status === 401, 'a wrong signature is refused'); + r = await call({ wallet: W1 }, { ts: Date.now() - 600000 }); ok(r._status === 401, 'an old timestamp is refused'); + r = await call({ wallet: W1 }); + ok(r.account && r.spins.length === 1 && r.spins[0].id === 1 && r.spins[0].size === '468x60' && r.username === 'psone', 'Downline Banners (no site): the 468x60 spins only, as before', r); + ok(r.host === 'spin-links.test.org', 'the answer names the link host', r.host); + r = await call({ wallet: W1, spinId: 1 }); + ok(r.use && r.use.img === 'https://spin-links.test.org/i/qwhone.gif' && /\/c\/qwhone\?clickid=\{clickid\}&placement=\{spot\}&s1=\{type\}$/.test(r.use.link), 'Downline Banners use: image + click link with the macros', r.use); + r = await call({ site: 'vbb', wallet: W1 }); + ok(r.account && r.spins.map(x => x.id).join(',') === '2,3' && r.spins.every(x => ['125x125', '250x250'].includes(x.size)), 'vbb: 125x125 + 250x250 spins only (no 468x60, 300x250 or admin-off)', r.spins); + r = await call({ site: 'vbb', wallet: W1, spinId: 1 }); ok(r._status === 404 && /125x125/.test(r.error), 'vbb: a 468x60 spin cannot be used', r); + r = await call({ site: 'vbb', wallet: W1, spinId: 3 }); + ok(r.use && r.use.size === '250x250' && r.use.img === 'https://spin-links.test.org/i/qwhthr.gif' && r.use.tagged === true && r.use.sourceId, 'vbb use: the spin, tagged with a new source', r.use); + const src = JSON.parse(fs.readFileSync(path.join(DATA, 'sources.json'), 'utf8')); const mineSrc = (src.sources || src.items || Object.values(src).flat()).filter(x => x && x.owner === 'one@ps.test'); + ok(mineSrc.some(x => x.template === 'viralbannerblitz' && x.name === 'Viral Banner Blitz') && mineSrc.some(x => x.template === 'downlinebanners'), 'the account has a Viral Banner Blitz source (and its Downline Banners one)', mineSrc.map(x => x.template)); + r = await call({ site: 'vbb', wallet: W1, spinId: 3 }); ok(r.use && r.use.tagged === false && !r.use.otherSource, 'a second use reuses the source (no second tag)', r.use); + r = await call({ site: 'vbb', wallet: W2, username: 'pstwo' }); ok(r.account && r.username === 'pstwo' && r.spins.length === 1 && r.spins[0].id === 6, 'vbb: no account holds the wallet, found by network username', r); + r = await call({ wallet: W2, username: 'pstwo' }); ok(r.account === false, 'Downline Banners: wallet only (no username fallback)', r); + r = await call({ site: 'vbb', wallet: W2 }); ok(r.account === false, 'vbb without a username: account false', r); +} catch (e) { fail++; console.error(e); } +finally { srv.kill(); await sleep(300); try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {} } +console.log('\n' + pass + ' passed, ' + fail + ' failed'); process.exit(fail ? 1 : 0); diff --git a/server.js b/server.js index eb319b7..b345c0e 100644 --- a/server.js +++ b/server.js @@ -3074,6 +3074,8 @@ const server = http.createServer(async (req, res) => { // { wallet } lists the 468x60 Banner Spins of the LinkSpin account holding that wallet. { wallet, spinId } also makes sure the // account has a "Downline Banners" source (catalog template), tags the spin with it when the spin has no source yet, and // answers the image + click URLs with the board's macros. Nothing else about the account is read or changed. + // Viral Banner Blitz (Marty 2026-11-14) calls the same endpoint with { site: 'vbb' }: 125x125 and 250x250 spins, its own + // "Viral Banner Blitz" source, and { username } (its network username) when no account holds the wallet. if (p === '/api/partner/bl/spins' && req.method === 'POST') { let raw = ''; try { raw = await new Promise((ok, no) => { let d = ''; req.on('data', c => { d += c; if (d.length > 4096) { req.destroy(); no(new Error('too big')); } }); req.on('end', () => ok(d)); req.on('error', no); }); } catch (e) { return json(res, 400, { error: 'bad body' }); } const sec = String(process.env.NETWORK_SSO_SECRET || '').trim(); const ts = String(req.headers['x-net-ts'] || ''); const sig = String(req.headers['x-net-sig'] || ''); @@ -3082,18 +3084,21 @@ const server = http.createServer(async (req, res) => { if (sig.length !== want.length || !crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want))) return json(res, 401, { error: 'unauthorized' }); let b; try { b = JSON.parse(raw || '{}'); } catch (e) { return json(res, 400, { error: 'bad json' }); } const w = String(b.wallet || '').trim().toLowerCase(); if (!/^0x[0-9a-f]{40}$/.test(w)) return json(res, 400, { error: 'wallet' }); - const a = await accounts.byAddress(w).catch(() => null); + const vbb = b.site === 'vbb'; const P = vbb ? { sizes: ['125x125', '250x250'], tpl: 'viralbannerblitz', name: 'Viral Banner Blitz', site: 'https://viralbannerblitz.com', what: '125x125 (or 250x250)' } + : { sizes: ['468x60'], tpl: 'downlinebanners', name: 'Downline Banners', site: 'https://downlinebanners.com', what: '468x60' }; + let a = await accounts.byAddress(w).catch(() => null); + if ((!a || !a.email) && vbb && b.username) a = await accounts.byUsername(String(b.username)).catch(() => null); if (!a || !a.email) return json(res, 200, { account: false }); - const spins = (await bannerspin.list(a.email)).filter(x => x.size === '468x60' && !x.adminOff); + const spins = (await bannerspin.list(a.email)).filter(x => P.sizes.includes(x.size) && !x.adminOff); const hs = domains.hosts(); const host = (hs[0] && hs[0].host) || SITE_HOST; - const out = { account: true, username: a.username || null, spins: spins.map(x => ({ id: x.id, name: x.name, code: x.code, paused: !!x.paused, banners: (x.banners || []).length, sourceId: x.sourceId || null })) }; + const out = { account: true, username: a.username || null, host, spins: spins.map(x => ({ id: x.id, name: x.name, code: x.code, size: x.size, paused: !!x.paused, banners: (x.banners || []).length, sourceId: x.sourceId || null })) }; if (b.spinId != null) { - const sp = spins.find(x => x.id === Number(b.spinId)); if (!sp) return json(res, 404, { error: 'No such 468x60 Banner Spin on this LinkSpin account.' }); - let src = ((await sources.list(a.email)).sources || []).find(x => x.template === 'downlinebanners'); - if (!src) { const r = await sources.create(a.email, { template: 'downlinebanners', name: 'Downline Banners', site: 'https://downlinebanners.com' }); if (r.error) return json(res, 400, { error: r.error }); src = r.source || ((await sources.list(a.email)).sources || []).find(x => x.template === 'downlinebanners'); } + const sp = spins.find(x => x.id === Number(b.spinId)); if (!sp) return json(res, 404, { error: 'No such ' + P.what + ' Banner Spin on this LinkSpin account.' }); + let src = ((await sources.list(a.email)).sources || []).find(x => x.template === P.tpl); + if (!src) { const r = await sources.create(a.email, { template: P.tpl, name: P.name, site: P.site }); if (r.error) return json(res, 400, { error: r.error }); src = r.source || ((await sources.list(a.email)).sources || []).find(x => x.template === P.tpl); } let tagged = false; if (src && !sp.sourceId) { const r = await bannerspin.update(a.email, sp.id, { sourceId: src.id }); tagged = !r.error; } - out.use = { spinId: sp.id, name: sp.name, img: 'https://' + host + '/i/' + sp.code + '.gif', link: 'https://' + host + '/c/' + sp.code + '?clickid={clickid}&placement={spot}&s1={type}', + out.use = { spinId: sp.id, name: sp.name, size: sp.size, img: 'https://' + host + '/i/' + sp.code + '.gif', link: 'https://' + host + '/c/' + sp.code + '?clickid={clickid}&placement={spot}&s1={type}', sourceId: src ? src.id : null, tagged, otherSource: !!(sp.sourceId && src && sp.sourceId !== src.id) }; } return json(res, 200, out, { 'Cache-Control': 'no-store' });