From d049c529aca3aa0ed3ce061f96b175a410af49ab Mon Sep 17 00:00:00 2001 From: martbost Date: Sat, 14 Nov 2026 10:07:41 -0600 Subject: [PATCH] LinkSpin Banner Spins in Viral Banner Blitz (Marty 2026-11-14: "make sure Viral Banner Blitz incorporates banner spins that could be pulled in just like downline banners"), the Downline Banners pattern. lsspins.js calls LinkSpin's /api/partner/bl/spins with { site: 'vbb' }, signed with NETWORK_SSO_SECRET (by wallet; the network username too for network-verified members). My Banners: "Use my LinkSpin Banner Spin" lists the member's 125x125 / 250x250 spins (GET /api/my/lsspins) and one tap posts one (POST /api/my/banners { spinId }): one credit, same credit + waiting rules, image + link from LinkSpin's signed answer only (https, same host), the image is the spin's rotating image and the link its click link, so clicks count in LinkSpin Reports under a Viral Banner Blitz source. /go/ fills {clickid}, {spot} (banner number) and {type} (loop or waiting). Splash: the loop's open places (one stays "post yours") and the empty waiting line show members' Banner Spins (SPIN tiles, refreshed every 10 minutes, one per member, none for a member with a banner on the page, no image twice, same picks for 2 minutes); they are never in the loop list, never shift it, cycle or earn, and a note says so. Admin status: lsSpins. LS_PARTNER_URL for the smoke stand-in. common.js?v=4, splash.js?v=3, my.js?v=3, vbb.css?v=5. Smoke 227/227 (35 new, stand-in LinkSpin), chain 29/29. Needs LinkSpin 5d630ec. Co-Authored-By: Claude Opus 5.5 --- config.js | 1 + loop.js | 8 +-- lsspins.js | 74 ++++++++++++++++++++++++++ public/admin.html | 4 +- public/assets/common.js | 5 +- public/assets/my.js | 29 ++++++++++- public/assets/splash.js | 10 +++- public/assets/vbb.css | 6 +++ public/how.html | 4 +- public/index.html | 7 +-- public/leaders.html | 4 +- public/my.html | 11 ++-- public/packages.html | 4 +- public/promote.html | 4 +- qa/smoke.mjs | 112 +++++++++++++++++++++++++++++++++++++++- server.js | 52 +++++++++++++++++-- 16 files changed, 306 insertions(+), 29 deletions(-) create mode 100644 lsspins.js diff --git a/config.js b/config.js index 89ee015..e2a54a2 100644 --- a/config.js +++ b/config.js @@ -54,6 +54,7 @@ function get() { linkProbe: e.LINK_PROBE !== '0', // check the target link answers and allows frames (off in the local smoke test) iapBase: String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, ''), lsBase: String(e.LS_URL || 'https://linkspin.app').replace(/\/+$/, ''), + lsPartnerBase: String(e.LS_PARTNER_URL || e.LS_URL || 'https://linkspin.app').replace(/\/+$/, ''), // Banner Spins partner API (a stand-in in the smoke test) // network usernames: ?u= / ?a= -> {address, username}. '' turns the lookup off (local prototype). networkLookupUrl: e.NETWORK_LOOKUP_URL !== undefined ? String(e.NETWORK_LOOKUP_URL).trim() : String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, '') + '/api/network/member' diff --git a/loop.js b/loop.js index adbebb4..8fe13d8 100644 --- a/loop.js +++ b/loop.js @@ -42,9 +42,10 @@ function shift() { } // a new banner (already checked and paid for with a credit) -function post(owner, img, link, via) { +// spin: a LinkSpin Banner Spin { id, name, size } when the banner is one (the image rotates on LinkSpin, the link is its click link) +function post(owner, img, link, via, spin) { const S = store.state(); - const b = store.addBanner({ owner: String(owner).toLowerCase(), img, link, via: via || 'credit', state: 'queued', clicks: 0 }); + const b = store.addBanner(Object.assign({ owner: String(owner).toLowerCase(), img, link, via: via || 'credit', state: 'queued', clicks: 0 }, spin ? { spin } : {})); S.totals.posts++; store.bump('posts'); if (!S.queue.length && S.loop.length < C().loopSize) enter(b.id); else { S.queue.push(b.id); if (S.progress >= C().perShift) { S.progress = 0; shift(); } } @@ -118,7 +119,8 @@ function memberWeek(addr) { // the banner look (bought per banner, SKU 3): a highlighted border and a hover teaser (the member's line, else the link's site) const hostOf = l => { try { return new URL(l).hostname.replace(/^www\./, ''); } catch (e) { return ''; } }; function tile(b) { const m = store.member(b.owner); const t = { id: b.id, img: b.img, href: '/go/' + b.id, owner: (m && m.username) ? '@' + m.username : null }; - if (b.look) { t.look = true; t.teaser = b.teaser || hostOf(b.link); } return t; } + if (b.spin) t.spin = true; + if (b.look) { t.look = true; t.teaser = b.teaser || (b.spin && b.spin.name) || hostOf(b.link); } return t; } function view(queueShow) { const S = store.state(); return { loopSize: C().loopSize, perShift: C().perShift, progress: S.progress, waiting: S.queue.length, diff --git a/lsspins.js b/lsspins.js new file mode 100644 index 0000000..0ccb0f8 --- /dev/null +++ b/lsspins.js @@ -0,0 +1,74 @@ +// LinkSpin Banner Spins in Viral Banner Blitz (Marty 2026-11-14: "make sure Viral Banner Blitz incorporates banner spins that could +// be pulled in just like downline banners"). The Downline Banners pattern: +// 1. My Banners: "Use my LinkSpin Banner Spin" lists the member's 125x125 (or 250x250) Banner Spins and posts one as a banner (one +// credit, like any post). The banner's image is the spin's rotating image on LinkSpin and its link is the spin's click link, +// so clicks count in LinkSpin Reports under the member's "Viral Banner Blitz" source. +// 2. Fill: the splash shows members' Banner Spins in the loop's open places, and in the waiting line while nobody waits. Fill tiles +// are never loop banners: they are not in the loop list, never shift it, never cycle and never earn. One spin per member, no +// member who already has a banner on the page, no image twice (the board dedupe from Downline Banners). +// LinkSpin's partner endpoint /api/partner/bl/spins, called with { site: 'vbb' }, signed with NETWORK_SSO_SECRET: +// X-Net-Ts + X-Net-Sig = hex HMAC-SHA256('net.v1.' + ts + newline + raw body). LinkSpin answers for the account holding the wallet +// (else the account with the member's network username) only. +'use strict'; +const crypto = require('crypto'); + +let base = () => 'https://linkspin.app'; +let members = () => []; +const HOST_RE = /^[a-z0-9.-]+\.[a-z]{2,}$/i; + +async function call(body) { + const sec = String(process.env.NETWORK_SSO_SECRET || '').trim(); if (sec.length < 32) return { error: 'The LinkSpin link is not set up yet.' }; + const raw = JSON.stringify(Object.assign({ site: 'vbb' }, body)); const ts = String(Date.now()); + const sig = crypto.createHmac('sha256', sec).update('net.v1.' + ts + '\n' + raw).digest('hex'); + const ac = new AbortController(); const t = setTimeout(() => ac.abort(), 8000); + try { + const r = await fetch(base() + '/api/partner/bl/spins', { method: 'POST', body: raw, signal: ac.signal, headers: { 'Content-Type': 'application/json', 'X-Net-Ts': ts, 'X-Net-Sig': sig } }); + const j = await r.json().catch(() => ({})); return r.ok ? j : { error: j.error || 'LinkSpin did not answer. Try again in a minute.' }; + } catch (e) { return { error: 'LinkSpin did not answer. Try again in a minute.' }; } finally { clearTimeout(t); } +} +// a member's spins: { account, username, host, spins: [{ id, name, code, size, paused, banners }] } or { error } +function list(addr, username) { return call({ wallet: String(addr).toLowerCase(), username: username || undefined }); } +// connect one spin: { use: { spinId, name, size, img, link, otherSource } } or { error } +function use(addr, username, spinId) { return call({ wallet: String(addr).toLowerCase(), username: username || undefined, spinId: Number(spinId) || 0 }); } +const showable = sp => !sp.paused && sp.banners > 0; +const imgUrl = (host, code) => 'https://' + host + '/i/' + code + '.gif'; + +// ---- fill: one showable spin per member, refreshed every 10 minutes ---- +let SPINS = []; let lastRefresh = null; +async function refresh() { + const out = []; + for (const m of members()) { + const r = await list(m.address, m.username).catch(() => null); + if (!r || !r.account || !HOST_RE.test(String(r.host || ''))) continue; + const sp = (r.spins || []).find(showable); if (!sp || !/^[a-z0-9]+$/i.test(sp.code)) continue; + out.push({ owner: m.address, code: sp.code, img: imgUrl(r.host, sp.code), link: 'https://' + r.host + '/c/' + sp.code + '?placement=fill&s1=fill', + owner_name: r.username || m.username || null, title: sp.name }); + } + SPINS = out; lastRefresh = { at: Date.now(), spins: out.length }; + return out.length; +} +function set(list) { SPINS = Array.isArray(list) ? list : []; } +const codeOf = u => (String(u || '').match(/\/[ic]\/([a-z0-9]+)/i) || [])[1] || String(u || ''); +function shuffled() { 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; } +// fill tiles for one splash view. pageOwners: addresses with a banner on the page (loop or waiting line); pageImgs: their images. +// -> { loop: tiles for the open loop places, queue: tiles for the empty waiting line } +function fill(o) { + const owners = new Set(o.pageOwners || []); const used = new Set((o.pageImgs || []).map(codeOf)); + const pick = []; const want = Math.max(0, o.openPlaces || 0) + Math.max(0, o.queueSlots || 0); + for (const sp of shuffled()) { + if (pick.length >= want) break; + if ((sp.owner && owners.has(sp.owner)) || used.has(codeOf(sp.img))) continue; + used.add(codeOf(sp.img)); if (sp.owner) owners.add(sp.owner); + pick.push({ t: 'spin', img: sp.img, href: sp.link, owner: sp.owner_name ? '@' + sp.owner_name : null, title: sp.title || 'LinkSpin Banner Spin' }); + } + const nLoop = Math.min(pick.length, Math.max(0, o.openPlaces || 0)); + return { loop: pick.slice(0, nLoop), queue: pick.slice(nLoop) }; +} +function init(o) { + base = o.base || base; members = o.members || members; + const first = Number(process.env.LS_SPINS_FIRST_MS || 20000), every = Number(process.env.LS_SPINS_EVERY_MS || 10 * 60000); + setTimeout(() => refresh().catch(() => {}), first).unref(); setInterval(() => refresh().catch(() => {}), every).unref(); +} +function view() { return { fill: SPINS.length, at: lastRefresh ? lastRefresh.at : 0, lastRefresh }; } + +module.exports = { init, list, use, refresh, set, fill, codeOf, showable, view }; diff --git a/public/admin.html b/public/admin.html index 52dfdfe..60bd5ab 100644 --- a/public/admin.html +++ b/public/admin.html @@ -22,7 +22,7 @@ - +
@@ -36,7 +36,7 @@
- + diff --git a/public/assets/common.js b/public/assets/common.js index 2fdf4f9..42b5598 100644 --- a/public/assets/common.js +++ b/public/assets/common.js @@ -72,9 +72,10 @@ window.VBB = (function () { tick(); setInterval(tick, 25000); } function tile(t, extra) { - const a = document.createElement('a'); a.className = 'tile' + (t.look ? ' look' : '') + (extra && extra.cls ? ' ' + extra.cls : ''); + const a = document.createElement('a'); a.className = 'tile' + (t.look ? ' look' : '') + (t.t === 'spin' ? ' fill' : '') + (extra && extra.cls ? ' ' + extra.cls : ''); + if (t.t === 'spin') a.title = (t.owner ? t.owner + ': ' : '') + 'LinkSpin Banner Spin (fills an open place, not in the loop)'; a.href = t.href; a.target = '_blank'; a.rel = 'noopener'; - a.innerHTML = '' + esc(t.owner ? 'Banner by ' + t.owner : 'Member banner #' + t.id) + '' + a.innerHTML = '' + esc(t.t === 'spin' ? 'LinkSpin Banner Spin' + (t.owner ? ' by ' + t.owner : '') : t.owner ? 'Banner by ' + t.owner : 'Member banner #' + t.id) + '' + (extra && extra.pos ? '' + esc(extra.pos) + '' : '') + (t.owner ? '' + esc(t.owner) + '' : ''); if (t.look && t.teaser) { const s = document.createElement('span'); s.className = 'teaser'; s.textContent = t.teaser; a.appendChild(s); a.title = t.teaser; } const img = a.querySelector('img'); img.src = t.img; img.onerror = () => { img.onerror = null; img.src = '/art/tile-fallback.svg'; }; diff --git a/public/assets/my.js b/public/assets/my.js index abb9e9a..cea9355 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -40,6 +40,32 @@ VBB.status(r.banner.state === 'loop' ? 'Posted. Your banner went straight into the loop.' : 'Posted. Your banner is number ' + r.banner.position + ' in line.', 'ok'); load(); }; + // LinkSpin Banner Spin (2026-11-14, the Downline Banners pattern): pick one of your 125x125 (or 250x250) spins and it posts + $('lsBtn').onclick = async () => { + const pick = $('lsPick'); pick.hidden = false; pick.innerHTML = '

Looking up your LinkSpin Banner Spins...

'; + const d = await VBB.getJSON('/api/my/lsspins'); + if (d.error) { pick.innerHTML = '

' + esc(d.error) + '

'; return; } + const make = 'make one on LinkSpin'; + if (!d.account) { pick.innerHTML = '

No LinkSpin account holds this wallet yet. Join LinkSpin (free) with the same email as InstantAdPay, link this wallet there, then ' + make + ' (size 125x125).

'; return; } + if (!d.spins.length) { pick.innerHTML = '

You have no 125x125 Banner Spin yet: ' + make + ' (pick size 125x125), then tap the button again.

'; return; } + pick.innerHTML = '

Tap a Banner Spin to post it to the loop (one credit).

'; + const row = pick.querySelector('.row'); + for (const sp of d.spins) { + const bt = document.createElement('button'); bt.className = 'btn sec small'; bt.dataset.spin = sp.id; + bt.textContent = sp.name + ' (' + sp.size + ', ' + sp.banners + ' image' + (sp.banners === 1 ? '' : 's') + (sp.paused ? ', paused' : '') + ')'; + bt.disabled = !sp.banners || sp.paused; if (bt.disabled) bt.title = sp.paused ? 'Unpause it on LinkSpin first.' : 'Add an image to it on LinkSpin first.'; + bt.onclick = async () => { + row.querySelectorAll('button').forEach(x => { x.disabled = true; }); VBB.status('Posting your Banner Spin...'); + const r = await VBB.post('/api/my/banners', { spinId: sp.id }); + if (r.error) { VBB.status(r.error, 'err'); row.querySelectorAll('button').forEach(x => { x.disabled = false; }); return; } + pick.hidden = true; pick.innerHTML = ''; + VBB.status((r.banner.state === 'loop' ? 'Posted. Your Banner Spin went straight into the loop.' : 'Posted. Your Banner Spin is number ' + r.banner.position + ' in line.') + + (r.otherSource ? ' It already reports under another LinkSpin source, so its clicks stay there.' : ''), 'ok'); + load(); + }; + row.appendChild(bt); + } + }; $('copyBtn').onclick = () => { $('share').select(); try { navigator.clipboard.writeText($('share').value); } catch (e) { document.execCommand('copy'); } VBB.status('Link copied.', 'ok'); }; const where = b => b.state === 'queued' ? 'Waiting
Number ' + b.position + ' of ' + b.of + ' in line' @@ -81,13 +107,14 @@ .map(x => '
' + esc(x[1]) + '' + esc(x[0]) + '
').join(''); $('creditNote').textContent = !d.netVerified ? 'Free daily credits are for network members. Sign in through InstantAdPay or LinkSpin, or make a free InstantAdPay account with this wallet, and your free credit arrives each day you sign in. You can have up to ' + d.maxQueued + ' banners waiting at once.' : (d.grantedNow ? 'Your free credit for today was just added. ' : d.freeToday ? 'Today\'s free credit is in. ' : '') + 'One free credit arrives each day you sign in (they bank up to ' + d.freeCreditCap + '). You can have up to ' + d.maxQueued + ' banners waiting at once.'; - $('postBtn').disabled = d.credits < 1; + $('postBtn').disabled = d.credits < 1; $('lsBtn').disabled = d.credits < 1; if (d.credits < 1) $('creditNote').textContent += (shopLive ? ' Out of credits: get a pack on the Packages page, or come back tomorrow for a free one.' : ''); $('mine').innerHTML = d.banners.length ? '' : '

No banners yet. Post your first one above.

'; for (const b of d.banners) { const el = document.createElement('div'); el.className = 'item'; el.innerHTML = 'Banner #' + b.id + '
' + where(b) + '

' + VBB.n(b.clicks) + ' clicks
'; el.querySelector('img').src = b.img; const a = el.querySelector('a'); a.href = b.link; a.textContent = b.link.replace(/^https:\/\//, '').slice(0, 60); + if (b.spin) { a.removeAttribute('href'); a.textContent = 'LinkSpin Banner Spin: ' + b.spin.name; a.insertAdjacentHTML('beforebegin', 'Banner Spin '); } lookRow(el.querySelector('.look-row'), b); $('mine').appendChild(el); } diff --git a/public/assets/splash.js b/public/assets/splash.js index 898556d..98398f8 100644 --- a/public/assets/splash.js +++ b/public/assets/splash.js @@ -15,7 +15,8 @@ const t = d.today || {}; $('today').textContent = VBB.n(t.shifts) + ' shifts and ' + VBB.n(t.cycles) + ' cycles today'; // the loop - const ids = d.loop.map(x => x.id + (x.look ? '*' + x.teaser : '')).join(','); // a new banner look repaints too + const fill = d.fill || { loop: [], queue: [] }; + const ids = d.loop.map(x => x.id + (x.look ? '*' + x.teaser : '')).join(',') + '|' + fill.loop.map(x => x.img).join(','); // a new banner look or fill repaints too if (ids !== lastLoop) { lastLoop = ids; const g = $('loop'); g.innerHTML = ''; const full = d.loop.length >= d.loopSize; @@ -24,16 +25,21 @@ const el = VBB.tile(t, { pos: last ? 'NEXT OUT' : String(i + 1), cls: (last ? 'next' : '') + (!firstPaint && !known.has(t.id) ? ' fresh' : '') }); g.appendChild(el); known.add(t.id); }); - for (let i = d.loop.length; i < d.loopSize; i++) { + // open places: the first stays "post yours", the next ones show members' LinkSpin Banner Spins (never part of the loop) + for (let i = d.loop.length, k = 0; i < d.loopSize; i++) { + const sp = i > d.loop.length ? fill.loop[k] : null; + if (sp) { k++; g.appendChild(VBB.tile(sp, { pos: 'SPIN' })); continue; } const a = document.createElement('a'); a.className = 'tile open'; a.href = '/my'; a.innerHTML = '+Open place
post yours'; g.appendChild(a); } firstPaint = false; } $('loopInfo').textContent = d.loop.length + ' of ' + d.loopSize + ' places filled'; + $('fillNote').hidden = !(fill.loop.length || (!d.waiting && fill.queue.length)); // the queue const q = $('queue'); q.innerHTML = ''; d.queue.forEach((t, i) => q.appendChild(VBB.tile(t, { pos: '#' + (i + 1) }))); + if (!d.waiting) fill.queue.forEach(t => q.appendChild(VBB.tile(t, { pos: 'SPIN' }))); $('queueEmpty').hidden = d.waiting > 0; $('queueInfo').textContent = d.waiting ? VBB.n(d.waiting) + ' waiting' + (d.waiting > d.queue.length ? ', first ' + d.queue.length + ' shown' : '') : ''; } diff --git a/public/assets/vbb.css b/public/assets/vbb.css index 019c97e..69d9536 100644 --- a/public/assets/vbb.css +++ b/public/assets/vbb.css @@ -172,3 +172,9 @@ footer.foot a{color:var(--amber)} footer.foot p{margin:6px 0} .mine .item .look-row input{flex:1;min-width:120px;background:var(--panel);border:2px solid var(--ink);border-radius:8px;padding:6px 8px;font:13px var(--body)} .pill.look{background:var(--hot);color:#fff} .past{display:grid;gap:12px}.past .wk{background:var(--bg2);border:var(--edge);border-radius:14px;padding:12px 14px} +/* LinkSpin Banner Spins (2026-11-14): fill tiles in open places / the empty waiting line, never loop banners */ +.tile.fill{border-style:dashed;box-shadow:none;opacity:.92} +.tile.fill .pos{background:var(--sky-soft);color:var(--ink)} +.fill-note{margin-top:6px} +.ls-box{margin-top:16px;padding-top:12px;border-top:1.5px dashed var(--muted)} +.pill.spin{background:var(--sky-soft);color:var(--ink)} diff --git a/public/how.html b/public/how.html index fe40d84..1d0ba2c 100644 --- a/public/how.html +++ b/public/how.html @@ -22,7 +22,7 @@ - +
@@ -55,7 +55,7 @@
- + diff --git a/public/index.html b/public/index.html index 47659e1..0868fe0 100644 --- a/public/index.html +++ b/public/index.html @@ -23,7 +23,7 @@ - +
@@ -47,6 +47,7 @@

Waiting to enter

+

Send visitors, move up the leaderboard

@@ -55,7 +56,7 @@
- - + + diff --git a/public/leaders.html b/public/leaders.html index 72304f4..263c4ef 100644 --- a/public/leaders.html +++ b/public/leaders.html @@ -22,7 +22,7 @@ - +
@@ -33,7 +33,7 @@
- + diff --git a/public/my.html b/public/my.html index c5a0340..88579ea 100644 --- a/public/my.html +++ b/public/my.html @@ -22,7 +22,7 @@ - +
@@ -58,6 +58,11 @@ +
+

Have a LinkSpin Banner Spin? Post it instead: its images rotate in your tile and every click goes through your spin, so it shows in LinkSpin Reports under a Viral Banner Blitz source. 125x125 (or 250x250) spins. One post uses one credit.

+ + +

Your banners

Add the banner look to any banner that is waiting or in the loop: a bright border, plus a teaser line that shows when someone points at it. One-time, per banner.

@@ -73,9 +78,9 @@
- + - + diff --git a/public/packages.html b/public/packages.html index 95d949d..05100d3 100644 --- a/public/packages.html +++ b/public/packages.html @@ -22,7 +22,7 @@ - +
@@ -43,7 +43,7 @@

Every network member (InstantAdPay or LinkSpin) also gets one free post credit each day they sign in.

Use my free credit
- + diff --git a/public/promote.html b/public/promote.html index d626c63..35f86ad 100644 --- a/public/promote.html +++ b/public/promote.html @@ -22,7 +22,7 @@ - + @@ -34,7 +34,7 @@

Loading the kit...

- + diff --git a/qa/smoke.mjs b/qa/smoke.mjs index a952349..5167313 100644 --- a/qa/smoke.mjs +++ b/qa/smoke.mjs @@ -63,9 +63,29 @@ require('node:http').createServer(async (q, r) => { let b = ''; for await (const else if (j.email && HUBMAIL.has(j.email)) return r.end(JSON.stringify({ person: { id: 'h_' + '9'.repeat(16), username: HUBMAIL.get(j.email), wallet: null, sponsor: null, blocked: false } })); return r.end(JSON.stringify({ person: hubPerson(w) })); } HUB.got.push({ route: q.url, body: JSON.parse(b) }); r.end(JSON.stringify({ id: 'p' + HUB.got.length })); }).listen(HUB_PORT, '127.0.0.1').unref(); +// stand-in LinkSpin partner API (/api/partner/bl/spins, the Banner Spins call): checks the NETWORK_SSO_SECRET signature and +// site 'vbb', answers like LinkSpin (account by wallet, else by network username; 125x125 + 250x250 spins only). LSA: wallet -> +// { username, spins: [{ id, name, code, size, paused, banners }] }; LS.tamper(use) may change a "use" answer (bad size, bad host). +const LS = { calls: [], badSig: 0, tamper: null }; const LSA = new Map(); const LS_PORT = PORT + 4, LS_HOST = 'rubav-standin.com'; +require('node:http').createServer(async (q, r) => { let b = ''; for await (const c of q) b += c; + r.setHeader('Content-Type', 'application/json'); + const ts = String(q.headers['x-net-ts'] || ''), want = crypto.createHmac('sha256', SSO_SECRET).update('net.v1.' + ts + '\n' + b).digest('hex'); + if (q.url !== '/api/partner/bl/spins' || q.headers['x-net-sig'] !== want || Math.abs(Date.now() - Number(ts)) > 300000) { LS.badSig++; r.statusCode = 401; return r.end('{"error":"unauthorized"}'); } + const j = JSON.parse(b || '{}'); LS.calls.push(j); + let a = LSA.get(j.wallet); if (a && a.byName) a = null; + if (!a && j.username) a = [...LSA.values()].find(x => x.byName && x.username === j.username); + if (!a) return r.end('{"account":false}'); + const sp = a.spins.filter(x => j.site === 'vbb' ? ['125x125', '250x250'].includes(x.size) : x.size === '468x60'); + const out = { account: true, username: a.username, host: LS_HOST, spins: sp }; + if (j.spinId != null) { + const x = sp.find(y => y.id === j.spinId); if (!x) { r.statusCode = 404; return r.end('{"error":"No such 125x125 (or 250x250) Banner Spin on this LinkSpin account."}'); } + out.use = { spinId: x.id, name: x.name, size: x.size, img: 'https://' + LS_HOST + '/i/' + x.code + '.gif', link: 'https://' + LS_HOST + '/c/' + x.code + '?clickid={clickid}&placement={spot}&s1={type}', otherSource: !!x.otherSource }; + if (LS.tamper) LS.tamper(out.use); + } + r.end(JSON.stringify(out)); }).listen(LS_PORT, '127.0.0.1').unref(); const ENV = Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, ADMIN_TOKEN: ADMIN, NODE_ENV: 'development', DOCSTORE_URL: '', LOOP_SIZE: '5', VISITORS_PER_SHIFT: '3', VIEWS_PER_CYCLE: '150', VISIT_SECONDS: '2', VISITS_PER_IP_DAY: '2', LINK_PROBE: '0', NETWORK_LOOKUP_URL: 'http://127.0.0.1:' + (PORT + 1) + '/api/network/member', - NETWORK_SSO_SECRET: SSO_SECRET, IAP_URL: 'https://iap.invalid', LS_URL: 'https://ls.invalid', + NETWORK_SSO_SECRET: SSO_SECRET, IAP_URL: 'https://iap.invalid', LS_URL: 'https://ls.invalid', LS_PARTNER_URL: 'http://127.0.0.1:' + LS_PORT, LS_SPINS_FIRST_MS: '300', LS_SPINS_EVERY_MS: '700', CONTRACT_ADDRESS: SHOP, CHAIN_RPC: 'http://127.0.0.1:' + CHAIN_PORT, KEEPER_KEY: KEEPER_PK, SHOP_START_BLOCK: '1', SHOP_CONFIRMATIONS: '0', SHOP_POLL_MS: '200', HUB_ENABLED: '1', HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'vbb', HUB_TICK_MS: '300', HUB_DOWN_MS: '400' }); const sleep = ms => new Promise(r => setTimeout(r, ms)); @@ -507,6 +527,96 @@ async function main() { await browser.close(); } else console.log('13. page renders skipped (SKIP_UI or no Playwright at ' + PW + ')'); + // ---- 14. LinkSpin Banner Spins: post one as a banner, and members' spins fill empty space (never loop banners) ---- + console.log('14. LinkSpin Banner Spins (stand-in LinkSpin)'); + { // unit: the fill picks (Downline Banners dedupe: one per member, no member already on the page, no image twice) + const lsu = require(path.join(APP, 'lsspins.js')); + lsu.set([{ owner: '0xa', img: 'https://h.com/i/aaa.gif', link: 'https://h.com/c/aaa', owner_name: 'a' }, { owner: '0xb', img: 'https://h.com/i/bbb.gif', link: 'https://h.com/c/bbb' }, + { owner: '0xc', img: 'https://h.com/i/bbb.gif', link: 'https://h.com/c/bbb' }, { owner: '0xd', img: 'https://h.com/i/ddd.gif', link: 'https://h.com/c/ddd' }, { owner: '0xe', img: 'https://h.com/i/eee.gif', link: 'https://h.com/c/eee' }]); + let f = lsu.fill({ openPlaces: 2, queueSlots: 8, pageOwners: ['0xa'], pageImgs: ['https://h.com/i/eee.gif'] }); const all = f.loop.concat(f.queue); + ok(f.loop.length === 2 && all.length === 2 && all.every(t => t.t === 'spin') && !all.some(t => /aaa|eee/.test(t.img)) && new Set(all.map(t => t.img)).size === all.length, + 'fill: a member on the page and an image on the page are left out, the same image never twice', all.map(t => t.img)); + f = lsu.fill({ openPlaces: 1, queueSlots: 8, pageOwners: [], pageImgs: [] }); + ok(f.loop.length === 1 && f.queue.length === 3, 'fill: open places first, the rest into the empty waiting line (4 different images)', [f.loop.length, f.queue.length]); + ok(lsu.fill({ openPlaces: 0, queueSlots: 0, pageOwners: [], pageImgs: [] }).loop.length === 0, 'fill: no gap, no fill'); + } + const SP1 = await walletMember(); await SP1.json('/api/my'); + LSA.set(SP1.address, { username: 'spinner1', spins: [{ id: 11, name: 'Main spin', code: 'qk7spin1', size: '125x125', paused: false, banners: 2 }, { id: 12, name: 'Sharp spin', code: 'qk7spin2', size: '250x250', paused: false, banners: 1 }, + { id: 13, name: 'Wide spin', code: 'qk7wide1', size: '468x60', paused: false, banners: 3 }, { id: 14, name: 'Resting', code: 'qk7rest1', size: '125x125', paused: true, banners: 1 }] }); + let ls = await SP1.json('/api/my/lsspins'); + ok(ls._status === 200 && ls.account && ls.spins.length === 3 && ls.spins.every(x => ['125x125', '250x250'].includes(x.size)) && !JSON.stringify(ls).includes('qk7'), 'My Banners lists the 125x125 + 250x250 spins only (no codes sent to the browser)', ls); + ok(LS.badSig === 0 && LS.calls.length > 0 && LS.calls.every(c => c.site === 'vbb'), 'LinkSpin calls are signed with NETWORK_SSO_SECRET and say site vbb', { bad: LS.badSig, n: LS.calls.length }); + const anonLs = await anon.json('/api/my/lsspins'); ok(anonLs._status === 401, 'the spin list needs a sign-in'); + const NOLS = await walletMember(); await NOLS.json('/api/my'); ls = await NOLS.json('/api/my/lsspins'); + ok(ls._status === 200 && ls.account === false, 'no LinkSpin account for this wallet: account false', ls); + const nc = LS.calls.filter(c => c.wallet === NOLS.address).slice(-1)[0] || {}; ok(nc.username && /^net[0-9a-f]{8}$/.test(nc.username), 'a network-verified member is also looked up by network username', nc); + // username fallback: LinkSpin knows this member by network username, not by this wallet + const UN = await walletMember(); await UN.json('/api/my'); LSA.set('0x' + 'f'.repeat(40), { username: 'net' + UN.address.slice(2, 10), byName: true, spins: [{ id: 31, name: 'By name', code: 'qk7name1', size: '125x125', paused: false, banners: 0 }] }); + ls = await UN.json('/api/my/lsspins'); ok(ls.account === true && ls.spins.length === 1, 'LinkSpin finds the account by network username when no account holds the wallet', ls); + const STR = await walletMember({ stranger: true }); await STR.json('/api/my'); await STR.json('/api/my/lsspins'); + const sc = LS.calls.filter(c => c.wallet === STR.address); ok(sc.length > 0 && sc.every(c => !c.username), 'a member the network does not know is looked up by wallet only', sc.slice(-1)); + // posting a spin: one credit, image + link from LinkSpin, straight into the loop / the line like any banner + let cr0 = (await SP1.json('/api/my')).credits; + let ps = await SP1.json('/api/my/banners', { spinId: 13 }); ok(ps._status === 400 && /125x125/.test(ps.error), 'a 468x60 spin cannot be posted', ps); + ps = await SP1.json('/api/my/banners', { spinId: 99 }); ok(ps._status === 400 && /No such/.test(ps.error), 'an unknown spin is refused with LinkSpin\'s reason', ps); + LS.tamper = u => { u.size = '468x60'; }; ps = await SP1.json('/api/my/banners', { spinId: 11 }); ok(ps._status === 400 && /125x125/.test(ps.error), 'a wrong size in LinkSpin\'s answer is refused', ps); + LS.tamper = u => { u.img = 'https://elsewhere-images.com/x.gif'; }; ps = await SP1.json('/api/my/banners', { spinId: 11 }); ok(ps._status === 400, 'an image on another host than the spin link is refused', ps); + LS.tamper = u => { u.link = 'http://' + LS_HOST + '/c/x'; }; ps = await SP1.json('/api/my/banners', { spinId: 11 }); ok(ps._status === 400, 'a plain http spin link is refused', ps); + LS.tamper = null; + ok((await SP1.json('/api/my')).credits === cr0, 'refused spin posts use no credit', cr0); + ps = await SP1.json('/api/my/banners', { spinId: 11, img: 'https://evil-images.com/x.png', link: 'https://evil-target.com/' }); + ok(ps.ok && ps.credits === cr0 - 1, 'posting a spin uses one credit', ps); + my = await SP1.json('/api/my'); const sb = my.banners.find(x => x.id === ps.banner.id); + ok(sb && sb.img === 'https://' + LS_HOST + '/i/qk7spin1.gif' && sb.link.startsWith('https://' + LS_HOST + '/c/qk7spin1?') && sb.spin && sb.spin.name === 'Main spin', 'the banner is the spin: its rotating image + click link (never what the browser sent)', sb); + ps = await SP1.json('/api/my/banners', { spinId: 12 }); ok(ps._status === 400 && /no post credits/i.test(ps.error), 'no credits left: a spin post is refused too', ps); + r = await anon.req('/go/' + sb.id); const gl = new URL(r.headers.get('location') || 'https://x/'); + ok(r.status === 302 && gl.hostname === LS_HOST && /^[0-9a-f]{16}$/.test(gl.searchParams.get('clickid') || '') && gl.searchParams.get('placement') === String(sb.id) && ['loop', 'waiting'].includes(gl.searchParams.get('s1')), + 'a click goes through the spin link with {clickid}, {spot} and {type} filled (counts in LinkSpin Reports)', r.headers.get('location')); + // fill: a bigger loop (restart with 40 places) leaves open places and nobody waiting + const SP2 = await walletMember(), SP3 = await walletMember(), SP4 = await walletMember(), SP5 = await walletMember(); + for (const m of [SP2, SP3, SP4, SP5]) await m.json('/api/my'); + LSA.set(SP2.address, { username: 'spinner2', spins: [{ id: 21, name: 'Two', code: 'qk7fill2', size: '125x125', paused: false, banners: 1 }] }); + LSA.set(SP3.address, { username: 'spinner3', spins: [{ id: 22, name: 'Three', code: 'qk7fill2', size: '125x125', paused: false, banners: 1 }] }); // same image as SP2 + LSA.set(SP4.address, { username: 'spinner4', spins: [{ id: 23, name: 'Four', code: 'qk7fill4', size: '250x250', paused: false, banners: 2 }] }); + LSA.set(SP5.address, { username: 'spinner5', spins: [{ id: 24, name: 'Paused', code: 'qk7fill5', size: '125x125', paused: true, banners: 1 }] }); + const loopBefore = (await anon.json('/api/admin/status', undefined, { 'x-admin-token': ADMIN })); + await sleep(1200); ENV.LOOP_SIZE = '40'; await stop(); await boot(); await sleep(1600); + sp = await anon.json('/api/splash'); const fl = (sp.fill || { loop: [], queue: [] }); const fall = fl.loop.concat(fl.queue); + ok(sp.loop.length < 39 && sp.waiting === 0, 'restart with 40 places: open places, nobody waiting', { loop: sp.loop.length, waiting: sp.waiting }); + ok(fall.length === 2 && fall.every(t => t.t === 'spin' && t.img.includes(LS_HOST)) && fall.some(t => t.img.includes('qk7fill4')) && fall.some(t => t.img.includes('qk7fill2')), + 'the gaps show members\' spins: one per image (SP2 and SP3 share one), none paused, none for a member with a banner on the page', fall.map(t => t.img + ' ' + t.owner)); + ok(!fall.some(t => t.img.includes('qk7spin1')), 'SP1 has a banner in the loop, so no fill tile for SP1'); + ok(fl.loop.length === 2 && fl.queue.length === 0, 'open loop places are filled first', [fl.loop.length, fl.queue.length]); + ok(fall.every(t => /\/c\/qk7fill\d\?placement=fill&s1=fill$/.test(t.href)), 'a fill tile clicks straight through the spin link (placement=fill)', fall.map(t => t.href)); + ok(!sp.loop.some(t => fall.some(f => f.img === t.img)), 'fill tiles are not in the loop list'); + let st0 = await anon.json('/api/admin/status', undefined, { 'x-admin-token': ADMIN }); + ok(st0.loop.filled === sp.loop.length && st0.totals.cycles === loopBefore.totals.cycles && st0.lsSpins && st0.lsSpins.fill >= 2, 'fill never changes the loop, its size or the cycles; admin status counts the fill spins', { filled: st0.loop.filled, cyc: [loopBefore.totals.cycles, st0.totals.cycles], ls: st0.lsSpins }); + const sp2 = await anon.json('/api/splash'); ok(JSON.stringify(sp2.fill) === JSON.stringify(sp.fill), 'the same fill on the next poll (no reshuffle every 8 seconds)'); + if (!process.env.SKIP_UI && fs.existsSync(PW)) { + const { chromium } = require(PW); const browser = await chromium.launch(); const errs = []; + const ctx = await browser.newContext({ viewport: { width: 1280, height: 900 }, userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/130.0 Safari/537.36 SmokeUI-spin' }); + await ctx.route('https://' + LS_HOST + '/**', rt => rt.fulfill({ status: 200, contentType: 'image/png', body: png(125, 125, 4) })); // nothing leaves this machine + const pg = await ctx.newPage(); pg.on('pageerror', e => errs.push(e.message)); + await pg.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); await pg.waitForSelector('#loop .tile.fill', { timeout: 8000 }).catch(() => {}); + const ft = await pg.$$eval('#loop .tile.fill', els => els.map(e => [e.querySelector('.pos') && e.querySelector('.pos').textContent, e.getAttribute('href')])); + ok(ft.length === 2 && ft.every(x => x[0] === 'SPIN' && x[1].includes(LS_HOST)), 'splash: open places show SPIN tiles', ft); + ok(await pg.isVisible('#fillNote') && /never shift it, never cycle and never earn/.test(await pg.textContent('#fillNote')), 'splash: the note says spins are not loop banners'); + ok((await pg.$$eval('#loop .tile.open', els => els.length)) >= 1 && (await pg.textContent('#loop .tile.open')).includes('post yours'), 'splash: an open place still says "post yours"'); + await pg.screenshot({ path: path.join(OUT, 'splash-spins.png'), fullPage: true }); + await ctx.addCookies([{ name: 'vbb.sid', value: SP4.jar['vbb.sid'], url: BASE }]); + await pg.goto(BASE + '/my', { waitUntil: 'domcontentloaded' }); await pg.waitForSelector('#dash:not([hidden])', { timeout: 8000 }); + await pg.click('#lsBtn'); await pg.waitForSelector('#lsPick button[data-spin]', { timeout: 8000 }).catch(() => {}); + const bts = await pg.$$eval('#lsPick button[data-spin]', els => els.map(e => e.textContent)); + ok(bts.length === 1 && /Four \(250x250, 2 images\)/.test(bts[0]), 'My Banners: "Use my LinkSpin Banner Spin" lists the spin', bts); + await pg.screenshot({ path: path.join(OUT, 'my-spins.png'), fullPage: true }); + await pg.click('#lsPick button[data-spin]'); await pg.waitForFunction(() => /Posted\. Your Banner Spin/.test(document.body.textContent), null, { timeout: 8000 }).catch(() => {}); + ok(/Posted\. Your Banner Spin went straight into the loop/.test(await pg.textContent('body')), 'My Banners: one tap posts the spin into the loop'); + await pg.waitForSelector('.pill.spin', { timeout: 8000 }).catch(() => {}); + ok(/LinkSpin Banner Spin: Four/.test(await pg.textContent('#mine')), 'My Banners: the banner shows as a Banner Spin'); + ok(errs.length === 0, 'no page errors (spins)', errs); + await browser.close(); + } + await stop(); console.log('\n' + pass + ' passed, ' + fail + ' failed'); fs.writeFileSync(path.join(OUT, 'smoke.txt'), new Date().toISOString() + ' ' + pass + ' passed, ' + fail + ' failed\n'); diff --git a/server.js b/server.js index 3d53f20..9ae2de5 100644 --- a/server.js +++ b/server.js @@ -23,6 +23,7 @@ const shop = require('./shop'); const promokit = require('./promokit'); // promo kit feed /api/promo-kit + the /promote page (2026-11-14) const hubreport = require('./hubreport'); // network hub report by wallet (off unless HUB_ENABLED) const prize = require('./prize'); +const lsspins = require('./lsspins'); // LinkSpin Banner Spins: post one as a banner, and fill the splash's open places (2026-11-14) const PUB = path.join(__dirname, 'public'); const UPL = path.join(C.dataDir, 'uploads'); @@ -163,7 +164,7 @@ function grantDaily(m) { function myData(addr) { const m = store.member(addr); const banners = store.bannersOf(addr).slice().reverse().map(b => Object.assign({ id: b.id, img: b.img, link: b.link, createdAt: b.createdAt, cycledAt: b.cycledAt || null, clicks: b.clicks || 0, - look: !!b.look, teaser: b.look ? (b.teaser || '') : '', teaserDefault: loop.hostOf(b.link) }, loop.placeOf(b))); + look: !!b.look, teaser: b.look ? (b.teaser || '') : '', teaserDefault: b.spin ? b.spin.name : loop.hostOf(b.link), spin: b.spin ? { name: b.spin.name, size: b.spin.size } : null }, loop.placeOf(b))); const rewards = store.ledger().filter(e => e.owner === m.address); const shareName = m.username || m.address; return { address: m.address, username: m.username, credits: m.credits, freeCreditCap: C.freeCreditCap, freeToday: m.freeDay === store.ctDay(), netVerified: netVerified(m), @@ -260,7 +261,7 @@ const server = http.createServer(async (req, res) => { const k = visitorKey(req) + ':' + b.id; const t = clickSeen.get(k); if (!t || Date.now() - t > 3600000) { clickSeen.set(k, Date.now()); if (clickSeen.size > 100000) clickSeen.clear(); b.clicks = (b.clicks || 0) + 1; store.saveBanner(b); store.bump('clicks'); } } - res.writeHead(302, { Location: b.link, 'Cache-Control': 'no-store', 'Referrer-Policy': 'origin' }); return res.end(); + res.writeHead(302, { Location: clickLink(b), 'Cache-Control': 'no-store', 'Referrer-Policy': 'origin' }); return res.end(); } } @@ -288,7 +289,7 @@ const server = http.createServer(async (req, res) => { } // past weeks' prize winners with their transactions (paid weeks only) if (p === '/api/prizes' && req.method === 'GET') return json(res, 200, { current: prizes(), week: store.ctWeek(), past: prize.history(12), explorer: C.explorer }, { 'Cache-Control': 'public, max-age=30' }); - if (p === '/api/splash' && req.method === 'GET') return json(res, 200, loop.view(24), { 'Cache-Control': 'no-store' }); + if (p === '/api/splash' && req.method === 'GET') { const v = loop.view(24); v.fill = splashFill(); return json(res, 200, v, { 'Cache-Control': 'no-store' }); } if (p === '/api/leaders' && req.method === 'GET') { const out = loop.leaders(null, 10); const fmt = r => ({ name: r.username ? '@' + r.username : r.address.slice(0, 6) + '...' + r.address.slice(-4), visitors: r.visitors, sources: r.sources }); @@ -404,6 +405,12 @@ const server = http.createServer(async (req, res) => { if (t.length > 40) return json(res, 400, { error: 'Keep the teaser to 40 characters.' }); bn.teaser = t; store.saveBanner(bn); return json(res, 200, { ok: true, teaser: t || loop.hostOf(bn.link) }); } + // the member's LinkSpin Banner Spins in a size the loop shows (125x125, or 250x250 for sharp screens) + if (p === '/api/my/lsspins' && req.method === 'GET') { + if (limited(req, 'lsspins', 120, 3600000)) return json(res, 429, { error: 'Too many requests this hour.' }); + const r = await lsspins.list(me, lsName(me)); if (r.error) return json(res, 502, r); + return json(res, 200, { account: !!r.account, username: r.username || null, spins: (r.spins || []).filter(x => ['125x125', '250x250'].includes(x.size)).map(x => ({ id: x.id, name: x.name, size: x.size || null, paused: !!x.paused, banners: x.banners || 0 })) }); + } if (p === '/api/my/upload' && req.method === 'POST') { if (limited(req, 'upload', 40, 3600000)) return json(res, 429, { error: 'Too many uploads this hour.' }); let buf; try { buf = await readRaw(req, safety.MAX_UPLOAD + 1); } catch (e) { return json(res, 400, { error: 'The file is over 100 KB.' }); } @@ -416,6 +423,20 @@ const server = http.createServer(async (req, res) => { if (m.credits < 1) return json(res, 400, { error: 'You have no post credits. A free credit arrives each day you sign in.' }); const waiting = store.bannersOf(me).filter(x => x.state === 'queued').length; if (waiting >= C.maxQueuedPerMember) return json(res, 400, { error: 'You already have ' + waiting + ' banners waiting. Post again when one enters the loop.' }); + // a LinkSpin Banner Spin (2026-11-14): image + link come from LinkSpin's signed answer, never from the browser. The image is the + // spin's rotating image on LinkSpin (not copied: it changes on every view) and the link its click link (clicks count in + // LinkSpin Reports); LinkSpin checked the spin's images and links, so the frame probe (it would count a click) is skipped. + if (b.spinId != null) { + const r = await lsspins.use(me, lsName(me), b.spinId); + if (r.error || !r.use) return json(res, 400, { error: r.error || (r.account === false ? 'No LinkSpin account holds this wallet yet.' : 'Could not use that Banner Spin.') }); + if (!['125x125', '250x250'].includes(r.use.size)) return json(res, 400, { error: 'Use a 125x125 (or 250x250) Banner Spin.' }); + const ic = safety.checkLink(r.use.img, 'Banner Spin image'); const sl = safety.checkLink(r.use.link, 'Banner Spin link'); + if (ic.error || sl.error || new URL(ic.url).hostname !== new URL(sl.url).hostname) return json(res, 400, { error: 'LinkSpin sent a link we cannot use. Try again in a minute.' }); + if (store.member(me).credits < 1) return json(res, 400, { error: 'You have no post credits.' }); + m.credits -= 1; + const nb = loop.post(me, ic.url, sl.url, 'credit', { id: Number(r.use.spinId), name: String(r.use.name || '').slice(0, 60), size: r.use.size }); + return json(res, 200, { ok: true, banner: Object.assign({ id: nb.id }, loop.placeOf(nb)), credits: m.credits, otherSource: !!r.use.otherSource }); + } const lk = safety.checkLink(b.link, 'Target link'); if (lk.error) return json(res, 400, lk); let img = String(b.img || '').trim(); if (/^\/u\/[a-z0-9-]+\.(png|jpg|gif)$/.test(img)) { @@ -445,7 +466,7 @@ const server = http.createServer(async (req, res) => { queue: { length: S.queue.length, next: S.queue.slice(0, 20) }, progress: S.progress, held: S.progress >= C.perShift && !S.queue.length, today: { visits: t.visits || 0, shifts: t.shifts || 0, cycles: t.cycles || 0, posts: t.posts || 0, clicks: t.clicks || 0 }, totals: S.totals, ledger: { entries: L.length, views: L.reduce((x, e) => x + e.views, 0), viewsByStatus: byStatus, credited: 0 }, - members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), prize: prize.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length }); + members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), prize: prize.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), lsSpins: lsspins.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length }); } // old username -> network username map for the old-link redirects: { oldrefs: { old: network } } replaces the whole map if (p === '/api/admin/oldrefs' && req.method === 'POST') { @@ -484,6 +505,26 @@ const server = http.createServer(async (req, res) => { if (!res.headersSent) json(res, 500, { error: 'Server error' }); } }); +// the network username LinkSpin may look the member up by when no LinkSpin account holds this wallet: network-verified members only +const lsName = addr => { const m = store.member(addr); return m && netVerified(m) && m.username ? m.username : null; }; +// tracking macros in a banner link, filled on every click: {clickid} a fresh id, {spot} the banner number, {type} loop or waiting +const MACRO = /\{(clickid|spot|type)\}|%7B(clickid|spot|type)%7D/gi; +function clickLink(b) { + const l = String(b.link || ''); if (!l.match(MACRO)) return l; + const v = { clickid: crypto.randomBytes(8).toString('hex'), spot: String(b.id), type: b.state === 'queued' ? 'waiting' : 'loop' }; + return l.replace(MACRO, (x, a, c) => v[(a || c).toLowerCase()]); +} +// members' Banner Spins on the splash: the loop's open places (one place always stays "post yours") and, while nobody waits, the +// waiting line. Never in the loop list: no shift, no cycle, no reward. Same picks for 2 minutes, so the page does not reshuffle. +let fillCache = { key: '', at: 0, out: { loop: [], queue: [] } }; +function splashFill() { + const S = store.state(); const ids = S.loop.concat(S.queue.slice(0, 24)); const bs = ids.map(id => store.banner(id)).filter(Boolean); + const open = Math.max(0, C.loopSize - S.loop.length - 1), queueSlots = S.queue.length ? 0 : 8; + const key = ids.join(',') + '|' + open + '|' + queueSlots + '|' + lsspins.view().fill + '|' + lsspins.view().at; + if (fillCache.key === key && Date.now() - fillCache.at < 120000) return fillCache.out; + const out = lsspins.fill({ openPlaces: open, queueSlots, pageOwners: bs.map(b => b.owner), pageImgs: bs.map(b => b.img) }); + fillCache = { key, at: Date.now(), out }; return out; +} const validSku = sku => sku === C.lookSku || C.packs.some(x => x.sku === sku); const skuUsd = sku => sku === C.lookSku ? C.lookUsd : (C.packs.find(x => x.sku === sku) || {}).usd || 0; function saveUpload(owner, buf, ext) { @@ -501,6 +542,9 @@ function saveUpload(owner, buf, ext) { hubreport.init({ dataDir: C.dataDir, purchases: () => Object.entries((store.state() || {}).purchases || {}).map(([key, x]) => Object.assign({ key }, x)) }); shop.init(C); // inert without CONTRACT_ADDRESS + CHAIN_RPC (watcher) / KEEPER_KEY (vouchers) prize.init(C); // prepares last week's payout plan; pays only on an admin's approval (PRIZE_KEY) + // fill spins: members seen in the last 60 days (most recent 400), one LinkSpin call each every 10 minutes + lsspins.init({ base: () => C.lsPartnerBase, members: () => store.members().filter(m => Date.now() - (m.lastSeen || m.joinedAt || 0) < 60 * 86400000) + .sort((a, b) => (b.lastSeen || 0) - (a.lastSeen || 0)).slice(0, 400) }); setInterval(() => { if (store.pruneVisits()) loop.rebuildIndex(); }, 3600000).unref(); server.listen(C.port, () => console.log('Viral Banner Blitz on :' + C.port + ' loop ' + C.loopSize + ', ' + C.perShift + ' visitors per shift, store: ' + (docstore.isOn() ? 'MySQL documents' : 'files (prototype mode)'))); })().catch(e => { console.error('start failed:', e.message); process.exit(1); });