From e545343fe0c4057bb71b52ed9f5cb1a9c8273800 Mon Sep 17 00:00:00 2001 From: martbost Date: Sat, 14 Nov 2026 11:59:38 -0600 Subject: [PATCH] Michael Camire fixes + hub shells in the tank (Marty 2026-11-14, LinkSpin Support) 1. Top-up across positions: an ad burns from ONE position, and topUpCampaign only looked at the ad's own position (or the main one when the list row had no memberId), so credits bought on a linked position could never top up the ad. Ported from InstantAdPay 2026-09-27 (Jim Watts): the ad's real member id is read from the campaign row; when it cannot cover, the refusal names where the free credits are and offers switchOptions; with the member's yes (switchTo, only a position on the account) moveFunding settles what the ad already ran up on the OLD position, moves the ad, then tops up. Ads screen asks in-page (own dialog) and retries. Create already had the largest-position guard. 2. Toasts: errors stay until closed (close button, role=alert), other notes 3.5 to 9 s by length. 3. Banner Spin per-banner clicks: his 3 clicks were all unmatched (no view on record for that browser), so they landed on the fallback row and every banner said 0. Click matching now also tries the same connection (daily-salted IP-only hash) when the browser key finds nothing (mail/exchange app view, click opened in the phone browser), view notes last 60 min instead of 15, and the stats split 'Fallback shown' from 'Clicks not tied to a banner' so the rows add up to the total. History is not backfilled: views were never stored per visitor, so old clicks cannot be tied reliably. 4. Holding tank: hub-made waiting accounts with no sponsor are in the tank (waiting, rescue, readyTick read listAll with { shells: true }; 'hub-shell' no longer holds anyone back). Locked / sponsored / unknown, grace, 2-adoption cap unchanged; readyTick still never switches a shell on; accounts.listAll default unchanged (mailings skip shells). Assets: cr.css, cr-shell.js, ads-screen.js ?v=20261114tu, banner-spin.js ?v=20261114bc. QA: walk member 0 bugs (36 ok), netconv 57/57, networksso ALL PASSED, tank-hold all passed (new hub shell part), profile policy 16/16, new topup-positions 8/8, new bannerspin-attrib 7/7, bannerspin e2e 75/75, hubsync 15 checks, tank-cap 15/15, sponsorfollow 30/30. Co-Authored-By: Claude Opus 5.5 --- ads.js | Bin 129207 -> 133431 bytes bannerspin.js | 18 +++++-- public/admin.html | 2 +- public/ads.html | 6 +-- public/assets/ads-screen.js | 21 ++++++++- public/assets/banner-spin.js | 7 +-- public/assets/cr-shell.js | 13 +++++- public/assets/cr.css | 4 ++ public/conversions.html | 4 +- public/credits.html | 4 +- public/help.html | 4 +- public/links.html | 6 +-- public/my.html | 4 +- public/pages.html | 4 +- public/reports.html | 4 +- public/sources.html | 4 +- public/team.html | 4 +- public/traffic-guide.html | 4 +- public/wallet.html | 4 +- public/zones.html | 4 +- qa/bannerspin-attrib.test.cjs | 72 ++++++++++++++++++++++++++++ qa/hubsync.test.cjs | 3 +- qa/run.sh | 2 + qa/tank-hold.test.mjs | 23 +++++++++ qa/topup-positions.test.cjs | 85 ++++++++++++++++++++++++++++++++++ server.js | 5 +- tank.js | 18 ++++--- 27 files changed, 282 insertions(+), 47 deletions(-) create mode 100644 qa/bannerspin-attrib.test.cjs create mode 100644 qa/topup-positions.test.cjs diff --git a/ads.js b/ads.js index 47999964e42198c46557b7ea833fed1451e8dbee..c7332c911632c6b29d4627b378e4391945c1e9bf 100644 GIT binary patch delta 3319 zcmb7HO^h7H8C5$X7$?DY2w-7@zOaJnW@j6(6OpjP7_AIQi@ZPJbpTn5Q`22DQ*r;% z-LvD7y&mNhDRvU%mS~Yfa*q%~;;=&Ef`}sJ5OUxU<-n0+kdY$gNZwb~-7|K`fy>NJ zch&dvzV}|$?tgjr{>_8${X8{cTih&ojQ5ysil)oFP-{H=MWJRomJ7L zbBT&pXkB?jAp<%y6`@L{S-QNuwEW{Xd8zbOo>4Cz4Td?z5e-#F0rnzGotM0L6!;X$ zUDTFJ;SKewTwcye_>OB5o*9aCATv`rmN&aafIa?%(y54Ol#oCTnauM5Da1f1w4pa` zo_%h%sjt#3Z&McQSCJf}HXsrO6O&EXl86cLi&NTFa-5Oq=O~bo3xP71C9+B6>0d7Z zxmNtIJjgzgD!b)sDrHe9rDVTzOe2)RL6BX#kDsUjd77D&y0I6}ZEjFLRuPFFGl`oY4=2SN=N~JNd}yBI~SE-9{tpMXr6)J(Nx%RoC_y+%3t1V9lLqy_|3n5yIlL3^@H<)1ePHF znonI~S<>T=>+ecX2*@hLi$-CN!%t?4<6kwHYD|n{O@J!Wx zpr9EHx}jE^LLZJZhF@JQ#KeK{T!xi zCRxYD6agG!jxsnRrx?T6jfDFtv|Nt^Ax9zzCTxnPmbl+%6N|NLX*LMoWU8=7IcWyS z+zUJ0b3GH~^TP|S>#|v%leul*rlR7v+b5UZ{HPXr#8^NIJrRh=lNm2;o8!vqXiu`u;)GGe4mXjhLu!hci7R%63XHYt z;|@w6WkdT)GfK#|89AG$l>EeOTh!qUe6Z<7k|K@p#~u>zX*jBw8BR*u7H#S|+;q=H zoT;QG68x8R=CMl@wAa1eJLp-eBK1||+c5`;o3f}oLr%k7TMj6?LeVG)OngRBM+e-( zpZfGnm-x4-febzpUtb!D2y06LX9XiDL(DS~R9 z4XWhz#tu)g$=OWvg5ko>Y^2F3#T_C8&RyQ(_GFef1K|htKup5&*0#0mZ&lY8T4-TT zmDCrhMTmsYMIh6Jt>@_AajQ{>mI@9Zm$qS>g0c`?f;vRVX79FWul)HglxWDN6^0J~ zCuog=S=Q(K4u-9De=+e9GkR$D#1jKo5yEkPXy)VcdR4R zIt%++m<_PHYWZ1eZC7?+E-ZX`o5Z8Ev7tK=st<-5C?vPJyLogpfTm?oahaw_(*pNe zS<5WrUfh+N3e?&&7>30z2KpLzt6w%f<5cGs zsvV(7%nVwZEOSDeCk*2dSJL6<++xdde-W$5p0?U#I-k{4<>!f4J_c3mYH$+c6yVDN zE>PO6ao{cCz|;0`2#Z}fw`P*(jC@(eJpj~OsY^G_YW!&|4^)u#->64HWQu=p^jj%hu1o9eQrIt|JHeH>094# V14re*ps#u+;r_?3TL1pze*wh|J*ofz delta 179 zcmdl!iDUam_6^rFH(TbWDo?i06`RZ-Ahr45 String(e || '').trim().toLowerCase(); const CT_FMT = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Chicago', year: 'numeric', month: '2-digit', day: '2-digit' }); @@ -92,6 +92,12 @@ const ipOf = req => String(req.headers['x-forwarded-for'] || (req.socket && req. const vkey = (req, ts) => crypto.createHash('sha256').update(new Date(ts || Date.now()).toISOString().slice(0, 10) + '|' + ipOf(req) + '|' + String(req.headers['user-agent'] || '')).digest('hex').slice(0, 16); // keys to try for a click: today's, and yesterday's for the first 15 minutes after UTC midnight (a note made at 23:59 still matches) function vkeys(req) { const now = Date.now(); const k = [vkey(req, now)]; if (now % DAY < NOTE_TTL) k.push(vkey(req, now - DAY)); return k; } +// Second chance for a click (Michael Camire 2026-11-14: 3 clicks on his Banner Spin, every one unmatched, so no banner got +// credit): the same daily-salted hash WITHOUT the browser. A mail app or a traffic-exchange app shows the image in its own +// viewer and opens the click in the phone's or PC's browser: same IP, different user agent, so the full key never matches. +// Only used when the full key finds nothing; the most recent view of this Banner Spin from that IP wins. +const ipkey = (req, ts) => 'i' + crypto.createHash('sha256').update(new Date(ts || Date.now()).toISOString().slice(0, 10) + '|ip|' + ipOf(req)).digest('hex').slice(0, 15); +function ipkeys(req) { if (!ipOf(req)) return []; const now = Date.now(); const k = [ipkey(req, now)]; if (now % DAY < NOTE_TTL) k.push(ipkey(req, now - DAY)); return k; } const isBot = req => { const ua = String(req.headers['user-agent'] || ''); return !ua || BOT.test(ua); }; const isPrefetch = req => /prefetch|prerender|preview/i.test([req.headers.purpose, req.headers['sec-purpose'], req.headers['x-purpose'], req.headers['x-moz']].filter(Boolean).join(' ')); // a server fetching the image, not a browser (phase 3, 2026-10-20): mail image proxies and plain HTTP libraries. Kept out of @@ -279,7 +285,7 @@ function choose(s, req, opts) { const kind = loaderKind(req); rawLoad(String(s.id), hostOf(req), v, kind); if (!kind) { const bid = b ? b.id : 0; const host = hostOf(req); - note(v, s.id, host, bid); + note(v, s.id, host, bid); if (ipOf(req)) note(ipkey(req), s.id, host, bid); const k = v + '|' + s.id + '|' + bid; const last = SEEN.get(k); if (!last || Date.now() - last >= DEDUPE_MS) { SEEN.set(k, Date.now()); bump(String(s.id), bid, host, v); } } @@ -313,7 +319,7 @@ async function click(code, req, reqHost) { let b = null, m = 'none'; if (!live() || s.adminOff) m = 'off'; else if (xs != null && /^\d{1,4}$/.test(xs)) { b = Number(xs) ? s.banners.find(q => q.id === Number(xs) && !q.adminOff) || null : null; m = 'exact'; } - else { const n = findNote(keys, s.id, h); if (n) { b = n.b ? s.banners.find(q => q.id === n.b && !q.adminOff) || null : null; m = 'note'; } } + else { let n = findNote(keys, s.id, h), how = 'note'; if (!n) { n = findNote(ipkeys(req), s.id, h); how = 'ip'; } if (n) { b = n.b ? s.banners.find(q => q.id === n.b && !q.adminOff) || null : null; m = how; } } // where to: the banner's target (its spin link, on the same link domain), else the fallback let url = null; if (b) { if (b.link) { const r = rotator && rotator.rawRotations ? rotator.rawRotations().find(x => x.id === b.link && x.owner === s.owner) : null; url = r ? 'https://' + (reqHost || 'linkspin.app') + '/r/' + r.code : null; } else url = b.target; } @@ -383,7 +389,7 @@ function agg(spins, sinceTs) { if (!ids.has(c.s) || (sinceTs && c.ts < sinceTs)) continue; const dd = at(days, ctDay(c.ts)); if (c.bot) { T.botClicks++; dd.botClicks++; continue; } - const ok = c.m === 'exact' || c.m === 'note'; + const ok = c.m === 'exact' || c.m === 'note' || c.m === 'ip'; for (const o of [at(per, c.s + ':' + c.b), at(hosts, c.h || '(none)'), dd, T]) { o.clicks++; if (ok) o.matched++; else if (c.m === 'none') o.unmatched++; } const k = c.c || '(none)'; country[k] = (country[k] || 0) + 1; const dv = c.dv || '(none)'; device[dv] = (device[dv] || 0) + 1; } @@ -419,7 +425,9 @@ async function stats(owner, id) { const win = winnerOf(banners.filter(b => b.active)); for (const b of banners) b.winner = b.id === win; const fb = A.per[s.id + ':0'] || z; return { spin: pub(s), totals: { imps: A.T.imps, clicks: A.T.clicks, ctr: ctrOf(A.T), matchRate: mrOf(A.T), matched: A.T.matched, unmatched: A.T.unmatched, uniquesSampled: A.T.uniq, conversions: A.T.conv, bots: A.T.botClicks, botLoads: A.T.bots, serverLoads: A.T.srv }, - banners, winner: win, winMin: WIN_MIN, fallback: { imps: fb.imps, clicks: fb.clicks, ctr: ctrOf(fb) }, + // fallback = the fallback was SHOWN (views + the clicks matched to those views); unmatched = clicks we could not tie to any view, + // listed on their own row so the banner rows + these two add up to the Banner Spin's totals + banners, winner: win, winMin: WIN_MIN, fallback: { imps: fb.imps, clicks: fb.clicks - fb.unmatched, ctr: ctrOf({ imps: fb.imps, clicks: fb.clicks - fb.unmatched }) }, unmatched: { clicks: fb.unmatched }, placements: placementRows(A.hosts), days: dayRows(A.days, ctDay(Date.now() - 30 * DAY)), country: listOf(A.country), device: listOf(A.device), conversions: Object.entries(A.convBy).sort((a, b) => b[1] - a[1]).map(([k, n]) => ({ k, n })) }; } diff --git a/public/admin.html b/public/admin.html index d7fe09b..f100e83 100644 --- a/public/admin.html +++ b/public/admin.html @@ -7,7 +7,7 @@ - + diff --git a/public/ads.html b/public/ads.html index 5bc9065..21342ca 100644 --- a/public/ads.html +++ b/public/ads.html @@ -7,7 +7,7 @@ Ads · LinkSpin - + @@ -1016,7 +1016,7 @@ - + diff --git a/public/pages.html b/public/pages.html index cd16dc9..5a0f518 100644 --- a/public/pages.html +++ b/public/pages.html @@ -7,7 +7,7 @@ Pages · LinkSpin - +