diff --git a/chatbot.js b/chatbot.js index d82b590..d8ffd41 100644 --- a/chatbot.js +++ b/chatbot.js @@ -6,7 +6,7 @@ // (/api/my/ad: network members only, https link, no shorteners, the link must answer; /api/my/order), shop.js + ../contracts // (VABShop: LEVELS 5, LEVEL_BPS 1000, MAX_DEPTH 20, MAX_QTY 10, no owner withdraw, undeliverable shares wait to be claimed), // wire.js (verified views and clicks), vabnas.js (Network Ad Space finishes a Boost after 30 days), lstrack.js (LinkSpin -// tracked link, default on), hubline.js (the 5 people above with a live ad, up to 20 places), promokit.js, public/*.html. +// tracked link, default on; "Use one of my spin links": the member's own LinkSpin spin link as the ad link, 2026-11-15), hubline.js (the 5 people above with a live ad, up to 20 places), promokit.js, public/*.html. // HOUSE RULE: when a feature changes, update CANNED and FACTS in the same commit and bump KNOWLEDGE_DATE. // Plain words, no em dashes, never a promise of income, "SafePal or any other crypto wallet", never RM Circle. 'use strict'; @@ -26,6 +26,9 @@ const CANNED = [ { id: 'refund', title: 'Refunds', q: ['Can I get a refund?', 'Can you cancel my Boost?'], tags: ['refund', 'cancel'], re: /\brefund|cancel (my |a |the )?boost|money back|reverse (my |a |the )?(payment|transaction)/i, handoff: true, a: 'Boosts are paid on Polygon and are final once confirmed, so they cannot be reversed or refunded. If your ad is removed for breaking the terms, the views left on its Boosts are not delivered or refunded. If something went wrong with a purchase, open network support at ' + SUPPORT + ' with the transaction link.' }, + { id: 'spin-link', title: 'Use one of my LinkSpin spin links as my ad link', q: ['Can I use my LinkSpin spin link in my text ad?', 'Can my ad rotate between all my pages?'], tags: ['linkspin', 'spin link', 'rotator', 'ad link'], + re: /(spin ?links?|\brotator\b|rotat\w* .{0,30}\b(links|pages|offers|sites)\b|linkspin link (in|for|as) (my )?(text )?ad)/i, + a: 'Yes. On My page (' + URL_ + '/my), in the ad form, tap "Use one of my spin links" and pick one of your own LinkSpin spin links as your ad link. Each click then goes to the next page on that spin link, so one free ad sends traffic to every page you promote. A spin link is already tracked on LinkSpin, so "Track with LinkSpin" is switched off for it and the clicks show in your LinkSpin Reports. Only your own spin links are accepted: ViralAdBlitz checks with LinkSpin that the link is yours, and a paused spin link or one with no active pages cannot be used. Make or edit spin links at https://linkspin.app.' }, { id: 'about', title: 'What is ViralAdBlitz?', q: ['What is ViralAdBlitz?', 'How does ViralAdBlitz work?', 'What is VAB?'], tags: ['viraladblitz', 'vab', 'text ads', 'overview'], re: /(what('s| is) (viral ?ad ?blitz|vab|this (site|place))|how does (viral ?ad ?blitz|vab|this site|it) work|explain (viral ?ad ?blitz|this))/i, a: 'ViralAdBlitz is the network\'s home for text ads. Network members post one free text ad (a headline, two lines and a link). Your page at ' + URL_ + '/your-name shows your ad plus the ads of the five people above you in your sponsor line, so your ad also shows on the pages of the people you bring in, five levels down. A $' + B.usd + ' Boost adds ' + B.views + ' guaranteed views. See ' + URL_ + '/how' }, @@ -58,7 +61,7 @@ const CANNED = [ a: 'A click counts as verified once per visitor per ad per 24 hours, never your own. Top ads this week on the front page ranks ads by verified clicks. Raw clicks are counted too, apart from the verified ones.' }, { id: 'linkspin-track', title: 'Track with LinkSpin', q: ['What is Track with LinkSpin?', 'Where do I see my ad clicks?'], tags: ['linkspin', 'tracked link', 'clicks'], re: /(track(ed|ing)? (with |by |link)|linkspin (link|track|click)|track with linkspin|see my (ad )?clicks|my (ad )?clicks)/i, - a: 'When you save your ad with "Track with LinkSpin" on (the default), your link goes out as a tracked link on your own LinkSpin account and My page shows its LinkSpin clicks. Visitors still land on your link. You can turn it off on the ad form; links with {clickid} or {placement} are not tracked.' }, + a: 'When you save your ad with "Track with LinkSpin" on (the default), your link goes out as a tracked link on your own LinkSpin account and My page shows its LinkSpin clicks. Visitors still land on your link. You can turn it off on the ad form; links with {clickid} or {placement} are not tracked. If your ad link is one of your own LinkSpin spin links, it is already tracked, so the box is switched off for it.' }, { id: 'line', title: 'Your sponsor line', q: ['Who is my sponsor?', 'Can my sponsor line change?', 'Where does my line come from?'], tags: ['sponsor', 'line', 'hub', 'upline'], re: /(sponsor|upline|my line|change (my )?line|who invited|wrong sponsor)/i, a: 'Your sponsor line comes from the network hub: the same sponsor you have across InstantAdPay, LinkSpin and the other network sites. On your first Boost the site signs your line and the contract records it. After that it never changes, so every later Boost pays the same people. People in the line without a wallet in the network are left out of the recorded line.' }, @@ -87,7 +90,7 @@ const FAQ = [ const FACTS = () => [ '- WHAT IT IS: ViralAdBlitz (' + URL_ + ') is the network\'s text-ad home. One free text ad per network member (an InstantAdPay or LinkSpin account, checked with the network hub). Sign in on ' + URL_ + '/my through InstantAdPay or LinkSpin (network sign-in) or with a wallet signature (free, cannot move funds).', - '- THE AD: headline 3 to ' + C.ad.headline + ' characters, line 1 3 to ' + C.ad.line + ', line 2 optional up to ' + C.ad.line + ', an https link to a real public page that answers, no link shorteners. One ad per member, editable any time, a Boost follows the ad when it is edited. "Track with LinkSpin" (default on) sends the link through the member\'s own LinkSpin tracked link; My page shows those clicks; {clickid}/{placement} links are not tracked.', + '- THE AD: headline 3 to ' + C.ad.headline + ' characters, line 1 3 to ' + C.ad.line + ', line 2 optional up to ' + C.ad.line + ', an https link to a real public page that answers, no link shorteners (except the member\'s OWN LinkSpin spin link: "Use one of my spin links" on the ad form lists them, the server accepts a LinkSpin /r/ link only when LinkSpin confirms it belongs to the signed-in member, never someone else\'s, never a paused one or one with no active pages; it rotates the ad\'s clicks across the member\'s pages and is already tracked, so "Track with LinkSpin" is off for it). One ad per member, editable any time, a Boost follows the ad when it is edited. "Track with LinkSpin" (default on) sends the link through the member\'s own LinkSpin tracked link; My page shows those clicks; {clickid}/{placement} links are not tracked.', '- MEMBER PAGE ' + URL_ + '/: the owner\'s ad on top, then the ads of the first 5 people above them in the hub sponsor line who have a live ad (labelled LEVEL 1 to LEVEL 5 in the order shown; the site walks up to ' + C.lineSearch + ' places), then ' + C.boostSlots + ' Boosted places, then "Join free under @owner" (InstantAdPay\'s join page). Front page: a live ticker of the newest ads (Boosted ones starred), "Top ads this week" by verified clicks, today\'s numbers, the live ledger and contract proof.', '- VERIFIED VIEWS: a real browser keeps the page open and visible for ' + C.visitSeconds + ' seconds; the server decides which ads were shown; one view per visitor per ad per 24 hours; never the owner\'s own; bots, early sends and more than ' + C.perIpDay + ' browsers per connection per day are refused. Verified clicks: once per visitor per ad per 24 hours, never the owner\'s own; raw clicks are counted apart.', '- BOOST: one-time $' + B.usd + ' (never a subscription) = ' + B.views + ' guaranteed network views + a gold star on the ticker while delivering + the Boosted places on member pages (furthest-behind first). 1 to ' + B.maxQty + ' per purchase, each adds ' + B.views + ' views. A member must have a live text ad first. Paid in POL on Polygon at the live Chainlink POL/USD price the contract reads; any overpayment comes back in the same transaction. Not delivered on-site within ' + C.deliverDays + ' days: finished through Network Ad Space as a text ad for exactly the views owed. ' + NOT_INCOME, diff --git a/lstrack.js b/lstrack.js index 3dc7092..615b55d 100644 --- a/lstrack.js +++ b/lstrack.js @@ -11,6 +11,12 @@ // ensureAd(ad) -> updates ad.ls { code, link, url, at } or ad.lsErr / ad.lsTry; saves through the store // clicks(username) -> { : { hits, hits30, unique30 } } | null (cached 5 minutes per member) // dest(ad) -> the tracked link when it is current, else null +// "Use one of my spin links" (Marty 2026-11-15): the same endpoint with { username, op: 'spins' } lists the member's own LinkSpin spin +// links (never another account's, never the tracked links made for ads). An ad whose link is the member's own spin link (ad.spin = +// its code) is already tracked on LinkSpin, so it never gets the tracked-link wrapper. A LinkSpin /r/ link is accepted as an +// ad link ONLY when LinkSpin confirms it belongs to the signed-in member (checkSpin); the network's own fixed links stay allowed. +// spins(username) -> { account, host, hosts, spins: [{ code, name, url, destinations, paused }] } | { error } +// checkSpin(url, username) -> { spin: false } (not a LinkSpin spin link) | { spin: true, code } | { error } 'use strict'; const crypto = require('crypto'); @@ -18,7 +24,17 @@ let C = null, store = null; const st = { ensured: 0, failed: 0, noAccount: 0, la const cache = new Map(); const MACRO = /\{(clickid|placement)\}|%7B(clickid|placement)%7D/i; const SITE = 'vab'; +const NET_CODES = new Set(Object.values(require('./netsites').CODES)); // the network's fixed LinkSpin links (admin account), not member spin links +const lsHosts = new Set(['linkspin.app']); // hosts a LinkSpin /r/ link answers on, learned from every spins answer function init(cfg, st0) { C = cfg; store = st0; } +// learn LinkSpin's link hosts (public; sent even when no account matches) so a foreign spin link is spotted after a restart too +let hostsAt = 0; +async function warmHosts() { + if (!base() || String(process.env.NETWORK_SSO_SECRET || '').trim().length < 32 || Date.now() - hostsAt < 3600000) return; + hostsAt = Date.now(); const r = await post({ username: '', op: 'spins' }, 6000).catch(() => ({})); + for (const h of Array.isArray(r.hosts) ? r.hosts : []) if (/^[a-z0-9.-]+\.[a-z]{2,}$/i.test(String(h))) lsHosts.add(String(h).toLowerCase()); + if (!Array.isArray(r.hosts)) hostsAt = Date.now() - 3000000; // no answer: try again in 10 minutes +} const base = () => String(process.env.LS_TRACK_URL || (C && C.lsBase) || '').replace(/\/+$/, ''); const on = () => !!(C && process.env.LS_TRACK !== '0' && String(process.env.NETWORK_SSO_SECRET || '').trim().length >= 32 && base()); @@ -36,6 +52,7 @@ const ownerName = a => { const m = store.member(a.owner); return m && m.username // what the member sees about tracking for their ad function state(a) { if (!a) return null; + if (a.spin) return 'spin'; if (a.track === false) return 'off'; if (MACRO.test(String(a.link || ''))) return 'macros'; if (a.ls && a.ls.url === a.link && a.ls.link) return 'tracked'; @@ -43,8 +60,8 @@ function state(a) { if (a.lsNoAccount && a.lsTry && Date.now() - a.lsTry < 86400000) return 'no-account'; return 'pending'; } -const wants = a => a && a.status !== 'removed' && a.track !== false && !MACRO.test(String(a.link || '')) && !(a.ls && a.ls.url === a.link && a.ls.link) && !!ownerName(a); -function dest(a) { return a && a.track !== false && a.ls && a.ls.link && a.ls.url === a.link && !MACRO.test(String(a.link || '')) ? a.ls.link : null; } +const wants = a => a && !a.spin && a.status !== 'removed' && a.track !== false && !MACRO.test(String(a.link || '')) && !(a.ls && a.ls.url === a.link && a.ls.link) && !!ownerName(a); +function dest(a) { return a && !a.spin && a.track !== false && a.ls && a.ls.link && a.ls.url === a.link && !MACRO.test(String(a.link || '')) ? a.ls.link : null; } async function ensureAd(a) { if (!on() || !wants(a)) return { skipped: true }; @@ -61,6 +78,7 @@ async function ensureAd(a) { } // the retry sweep: ads that want a tracked link and have not been tried lately (failures back off 10 minutes, no account a day) async function sweep(max) { + warmHosts().catch(() => {}); if (!on()) return 0; st.sweeps++; let n = 0; const backoff = Number(process.env.LS_RETRY_MS || 600000); for (const a of store.liveAds()) { @@ -81,5 +99,34 @@ async function clicks(username) { cache.set(k, { at: Date.now(), v }); if (cache.size > 20000) cache.clear(); return v; } +// the member's own spin links (read only) +async function spins(username) { + if (!base() || String(process.env.NETWORK_SSO_SECRET || '').trim().length < 32) return { error: 'The LinkSpin link is not set up yet.' }; + if (!username) return { error: 'Sign in through InstantAdPay or LinkSpin once to link your LinkSpin account.' }; + const r = await post({ username: String(username), op: 'spins' }, 6000); + if (r.error) { st.lastError = String(r.error).slice(0, 160); return { error: 'LinkSpin did not answer just now. Try again in a minute.' }; } + for (const h of (Array.isArray(r.hosts) ? r.hosts : []).concat(r.host ? [r.host] : [])) if (/^[a-z0-9.-]+\.[a-z]{2,}$/i.test(String(h))) lsHosts.add(String(h).toLowerCase()); + if (r.account === false) return { account: false, spins: [] }; + const spins = (Array.isArray(r.spins) ? r.spins : []).filter(x => x && /^[a-z0-9]{4,12}$/i.test(String(x.code || '')) && /^https:\/\//.test(String(x.url || ''))) + .map(x => ({ code: String(x.code).toLowerCase(), name: String(x.name || '').slice(0, 80), url: String(x.url), destinations: Number(x.destinations) || 0, paused: !!x.paused })); + return { account: true, host: r.host || null, hosts: Array.from(lsHosts), spins }; +} +// is this ad link a LinkSpin spin link, and is it the member's own? (asked on every save of an ad link that looks like one) +async function checkSpin(url, username) { + let u; try { u = new URL(String(url || '')); } catch (e) { return { spin: false }; } + const m = /^\/r\/([a-z0-9]{4,12})\/?$/i.exec(u.pathname); if (!m) return { spin: false }; + const host = u.hostname.toLowerCase().replace(/^www\./, ''); const code = m[1].toLowerCase(); + const mine = lsHosts.has(host) || (base() && (() => { try { return new URL(base()).hostname.toLowerCase() === host; } catch (e) { return false; } })()); + const r = await spins(username); + if (r.error) return mine ? { error: 'LinkSpin could not confirm that spin link is yours just now. ' + r.error } : { spin: false }; + if (!lsHosts.has(host)) return { spin: false }; // a /r/ link on some other site: an ordinary link + if (NET_CODES.has(code)) return { spin: false }; // the network's own fixed links stay allowed as before + if (r.account === false) return { error: 'No LinkSpin account was found for your network username, so that spin link cannot be confirmed as yours.' }; + const sp = r.spins.find(x => x.code === code); + if (!sp) return { error: 'That spin link is not one of yours. Use one of your own LinkSpin spin links (pick it under "Use one of my spin links").' }; + if (sp.paused) return { error: 'That spin link is paused on LinkSpin. Turn it back on there first, or pick another.' }; + if (!sp.destinations) return { error: 'That spin link has no active pages on LinkSpin yet. Add a page to it there first.' }; + return { spin: true, code }; +} function view() { return Object.assign({ on: on(), base: base() }, st); } -module.exports = { init, ensureAd, sweep, clicks, dest, state, view, on, _reset: () => cache.clear() }; +module.exports = { init, ensureAd, sweep, clicks, dest, state, view, on, spins, checkSpin, _hosts: lsHosts, _reset: () => cache.clear() }; diff --git a/public/assets/my.js b/public/assets/my.js index b545164..ac71014 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -29,13 +29,34 @@ if (!ls || !ls.on) return ''; const why = { off: 'Tracking is off for this ad: visitors go straight to your link.', macros: 'Your link has {clickid} or {placement} codes, so it goes out as it is (not through LinkSpin).', pending: 'Your LinkSpin tracked link is being set up. Until then visitors go straight to your link.', 'no-username': 'Sign in through InstantAdPay or LinkSpin once to link your LinkSpin account.', - 'no-account': 'No LinkSpin account was found for your network username yet. Visitors go straight to your link.' }[ls.state]; + 'no-account': 'No LinkSpin account was found for your network username yet. Visitors go straight to your link.', + spin: 'Your ad link is your own LinkSpin spin link, so its clicks already show in your LinkSpin Reports.' }[ls.state]; if (ls.state !== 'tracked') return '

' + esc(why || '') + '

'; const c = ls.clicks; return '

Tracked with LinkSpin: ' + esc(ls.link.replace(/^https?:\/\//, '').replace(/\?.*$/, '')) + '' + (c ? ' · ' + VAB.n(c.hits) + ' clicks in all, ' + VAB.n(c.hits30) + ' in 30 days (' + VAB.n(c.unique30) + ' unique)' : ' · clicks show in your LinkSpin Reports') + ' · Open LinkSpin

'; }; + // "Use one of my spin links" (2026-11-15): the member's own LinkSpin spin links as the ad link. A spin link is already tracked on + // LinkSpin, so "Track with LinkSpin" is switched off (and greyed) while the link is one. The server checks the link is the member's own. + let spins = null, spinAd = null; + const isSpin = v => { v = String(v || '').trim().toLowerCase(); if (spinAd && v === String(spinAd).toLowerCase()) return true; return !!(spins && spins.some(x => x.url.toLowerCase() === v)); }; + const spinMark = () => { const on = isSpin($('fLink').value); $('fTrack').disabled = on; $('trackNote').hidden = !on; $('fTrack').closest('label').style.opacity = on ? '0.6' : ''; }; + $('fLink').addEventListener('input', spinMark); + $('spinBtn').onclick = async () => { + const box = $('spinList'); + if (!box.hidden) { box.hidden = true; return; } + box.hidden = false; box.innerHTML = '

Asking LinkSpin for your spin links...

'; + const r = await VAB.getJSON('/api/my/spins').catch(() => ({ error: 'LinkSpin did not answer. Try again in a minute.' })); + if (r.error) { box.innerHTML = '

' + esc(r.error) + '

'; return; } + spins = r.spins || []; + if (!r.account) { box.innerHTML = '

No LinkSpin account was found for your network username yet. Open LinkSpin

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

You have no spin links on LinkSpin yet. Make one there (add every page you promote), then come back and pick it. Open LinkSpin

'; return; } + box.innerHTML = '

Pick one. Your ad sends each click to the next page on that spin link.

' + + spins.map((x, i) => '').join(''); + box.querySelectorAll('button[data-i]').forEach(b => { b.onclick = () => { const x = spins[Number(b.dataset.i)]; $('fLink').value = x.url; spinMark(); box.hidden = true; VAB.status('Spin link picked. Save your ad to use it.', 'ok'); }; }); + }; async function load() { const d = await VAB.getJSON('/api/my'); if (d.error) { VAB.status(d.error, 'err'); return; } $('dash').hidden = false; @@ -72,7 +93,8 @@ } else { $('adForm').hidden = !!a; $('adNote').hidden = !!a; if ($('editAd')) $('editAd').onclick = () => { const h = !$('adForm').hidden; $('adForm').hidden = h; $('adNote').hidden = h; $('editAd').textContent = h ? 'Edit ad' : 'Close the editor'; if (!h) $('fHead').focus(); }; - if (a) { $('adHead').textContent = 'My text ad'; $('fHead').value = a.headline; $('fL1').value = a.line1; $('fL2').value = a.line2 || ''; $('fLink').value = a.link; $('fTrack').checked = a.track !== false; $('adSave').textContent = 'Save changes'; } + if (a) { $('adHead').textContent = 'My text ad'; $('fHead').value = a.headline; $('fL1').value = a.line1; $('fL2').value = a.line2 || ''; $('fLink').value = a.link; $('fTrack').checked = a.track !== false; $('adSave').textContent = 'Save changes'; spinAd = a.spin ? a.link : null; } + spinMark(); if (!counted) { counter($('fHead'), $('cHead'), lim.headline); counter($('fL1'), $('cL1'), lim.line); counter($('fL2'), $('cL2'), lim.line); counted = true; } else ['fHead', 'fL1', 'fL2'].forEach(id => $(id).dispatchEvent(new Event('input'))); } diff --git a/public/my.html b/public/my.html index e8d8bdd..c7f507b 100644 --- a/public/my.html +++ b/public/my.html @@ -66,7 +66,8 @@ - +
One free ad, every page you promote: your LinkSpin spin link rotates the traffic.
+
Tracking codes work: {clickid} and {placement} are filled on every click.
@@ -87,6 +88,6 @@ - + diff --git a/qa/smoke.mjs b/qa/smoke.mjs index 7b72bde..a7a2d84 100644 --- a/qa/smoke.mjs +++ b/qa/smoke.mjs @@ -109,14 +109,17 @@ const TG = []; const TG_PORT = PORT + 4; listen(TG_PORT, async (q, r, b) => { TG.push({ method: q.url.split('/').pop(), token: q.url.split('/')[1], body: JSON.parse(b || '{}') }); r.setHeader('Content-Type', 'application/json'); r.end('{"ok":true,"result":{}}'); }); // ---- stand-in LinkSpin partner endpoint /api/partner/vab/links (net.v1 signature). Starts DOWN (404, as before LinkSpin ships it). ---- -const LS = { up: false, calls: [], badSig: 0, links: new Map(), known: new Set(['one', 'owner', 'four', 'five', 'six', 'seven', 'topdog', 'downline']), stats: {} }; const LS_PORT = PORT + 5; +const LS = { up: false, calls: [], badSig: 0, links: new Map(), known: new Set(['one', 'owner', 'four', 'five', 'six', 'seven', 'topdog', 'downline']), stats: {}, spins: { one: [{ code: 'onespin1', name: 'My three offers', destinations: 3, paused: false }, { code: 'onepaus1', name: 'Resting', destinations: 1, paused: true }, { code: 'oneempt1', name: 'Empty', destinations: 0, paused: false }], owner: [{ code: 'ownspin1', name: 'Owner rotator', destinations: 2, paused: false }] } }; const LS_PORT = PORT + 5; listen(LS_PORT, async (q, r, b) => { r.setHeader('Content-Type', 'application/json'); if (!LS.up || q.url !== '/api/partner/vab/links') { r.statusCode = 404; return r.end('{"error":"Not found"}'); } const want = crypto.createHmac('sha256', SSO_SECRET).update('net.v1.' + q.headers['x-net-ts'] + '\n' + b).digest('hex'); if (q.headers['x-net-sig'] !== want) { LS.badSig++; r.statusCode = 401; return r.end('{"error":"unauthorized"}'); } const j = JSON.parse(b || '{}'); LS.calls.push(j); + const SPIN_HOSTS = ['linkspin.app', 'qa-spin.net', 'qa-spare.net']; + if (j.op === 'spins' && !LS.known.has(String(j.username || '').toLowerCase())) return r.end(JSON.stringify({ account: false, hosts: SPIN_HOSTS })); if (!LS.known.has(String(j.username || '').toLowerCase())) return r.end('{"account":false}'); + if (j.op === 'spins') return r.end(JSON.stringify({ account: true, username: j.username, host: 'qa-spin.net', hosts: SPIN_HOSTS, spins: (LS.spins[j.username] || []).map(x => Object.assign({ url: 'https://qa-spin.net/r/' + x.code }, x)) })); if (j.op === 'stats') return r.end(JSON.stringify({ account: true, stats: LS.stats[j.username] || {} })); const links = {}; for (const x of j.links || []) { const k = j.username + ':' + x.id; let l = LS.links.get(k); if (!l) { l = { code: crypto.randomBytes(3).toString('hex'), url: x.url }; LS.links.set(k, l); } l.url = x.url; links[x.id] = { code: l.code, link: 'https://spin.test/r/' + l.code + '?s1=' + x.id + '&placement=' + x.id, created: false }; } @@ -446,6 +449,35 @@ const mtop = await anon.json('/api/wire?page=member&u=topdog'); ok(q2.ok && q2.linkspin === 'no-account' && m2.linkspin.state === 'no-account', 'no LinkSpin account for the username: the ad works with its own link', m2.linkspin); } { const s2 = await anon.json('/api/admin/status', undefined, { 'x-admin-token': ADMIN }); ok(s2.linkspin && s2.linkspin.on === true && s2.linkspin.ensured >= 3 && s2.linkspin.failed >= 1 && !JSON.stringify(s2.linkspin).includes(SSO_SECRET), 'admin status: LinkSpin tracking counters, no secret', s2.linkspin); } + console.log('14b2. "Use one of my spin links" (the own LinkSpin spin link as the ad link)'); + { let sp = await M1.json('/api/my/spins'); + ok(sp._status === 200 && sp.account === true && sp.spins.map(x => x.code).join(',') === 'onespin1,onepaus1,oneempt1' && sp.spins[0].url === 'https://qa-spin.net/r/onespin1' && sp.spins[0].destinations === 3 && sp.spins[1].paused === true, "the picker lists the member's own spin links from LinkSpin", sp); + const sc = LS.calls.filter(c => c.op === 'spins' && c.username === 'one'); ok(sc.length >= 1 && !sc.some(c => c.email) && LS.badSig === 0, 'the spins call: signed net.v1, network username only', sc.slice(-1)); + sp = await STR.json('/api/my/spins'); ok(sp._status === 403 && !sp.spins, 'a non-member gets no spin list', sp); + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://qa-spin.net/r/ownspin1' })); ok(pa._status === 400 && /not one of yours/.test(pa.error), "someone else's spin link is refused", pa); + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://linkspin.app/r/ownspin1' })); ok(pa._status === 400 && /not one of yours/.test(pa.error), "someone else's spin link on the main LinkSpin host is refused too", pa); + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://qa-spare.net/r/zzzzzz9' })); ok(pa._status === 400 && /not one of yours/.test(pa.error), 'an unknown code on another LinkSpin link host is refused', pa); + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://qa-spin.net/r/onepaus1' })); ok(pa._status === 400 && /paused/.test(pa.error), "the member's own paused spin link is refused", pa); + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://qa-spin.net/r/oneempt1' })); ok(pa._status === 400 && /no active pages/.test(pa.error), 'a spin link with no active pages is refused', pa); + my = await M1.json('/api/my'); ok(my.ad.link === 'https://member-1.example-shop.com/third' && my.ad.spin === false, 'a refused spin link leaves the ad as it was', my.ad); + const ownBy = await OWN.json('/api/my/ad', adBody('own', { link: 'https://qa-spin.net/r/onespin1' })); ok(ownBy._status === 400 && /not one of yours/.test(ownBy.error), "the other way round: member one's link is refused for the owner", ownBy); + const n1 = LS.calls.length; + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://qa-spin.net/r/onespin1', track: true })); + r = await anon.req('/go/' + ad1 + '?p=ticker'); my = await M1.json('/api/my'); + ok(pa.ok && pa.linkspin === 'spin' && my.ad.spin === true && my.ad.link === 'https://qa-spin.net/r/onespin1' && my.linkspin.state === 'spin', "the member's own spin link is accepted (LinkSpin confirmed it)", [pa, my.ad, my.linkspin]); + ok(r.status === 302 && r.headers.get('location') === 'https://qa-spin.net/r/onespin1', '/go/ sends straight to the spin link, no tracked-link wrapper', r.headers.get('location')); + await sleep(900); ok(!LS.calls.slice(n1).some(c => c.op === 'ensure' && c.username === 'one'), 'no tracked link is made for a spin-link ad (the sweep leaves it alone)', LS.calls.slice(n1).map(c => c.op)); + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://linkspin.app/r/nwiap?s1=one' })); ok(pa.ok && pa.linkspin !== 'spin', "the network's own fixed LinkSpin links stay allowed as before", pa); + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://member-1.example-shop.com/r/abcd12' })); ok(pa.ok && pa.linkspin !== 'spin', 'a /r/ link on any other site is an ordinary link', pa); + LS.up = false; + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://qa-spin.net/r/onespin1' })); ok(pa._status === 400 && /could not confirm/.test(pa.error), 'LinkSpin not answering: a spin link cannot be confirmed, so it is refused', pa); + sp = await M1.json('/api/my/spins'); ok(sp._status === 502 && /LinkSpin/.test(sp.error), 'LinkSpin not answering: the picker says so', sp); + LS.up = true; + pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://member-1.example-shop.com/third', track: true })); + my = await M1.json('/api/my'); ok(pa.ok && pa.linkspin === 'tracked' && my.ad.spin === false && my.linkspin.state === 'tracked', 'back to an ordinary link: tracked with LinkSpin again', [pa, my.linkspin]); + const h = await (await anon.req('/my')).text(); const js = await (await anon.req('/assets/my.js?v=7')).text(); + ok(/id="spinBtn"[^>]*>Use one of my spin links<\/script>/.test(hh) && (hh.match(/class="step"/g) || []).length === 3, 'front page carries the PolHunter embed on the 3 How it works steps'); diff --git a/server.js b/server.js index a64f9fb..76b311e 100644 --- a/server.js +++ b/server.js @@ -361,10 +361,17 @@ const server = http.createServer(async (req, res) => { let ls = null; // LinkSpin tracking of the ad (lstrack.js): state, the tracked link, its clicks as LinkSpin counts them if (a) { const stt = lstrack.state(a); ls = { on: lstrack.on(), track: a.track !== false, state: stt, link: stt === 'tracked' ? a.ls.link : null, clicks: null }; if (stt === 'tracked' && m.username) { const cs = await lstrack.clicks(m.username).catch(() => null); if (cs && cs[String(a.id)]) { const c0 = cs[String(a.id)]; ls.clicks = { hits: c0.hits || 0, hits30: c0.hits30 || 0, unique30: c0.unique30 || 0 }; } } } - return json(res, 200, { address: me, username: m.username, netVerified: netVerified(m), ad: a ? { id: a.id, headline: a.headline, line1: a.line1, line2: a.line2, link: a.link, status: a.status, views: a.views || 0, clicks: a.clicks || 0, vclicks: a.vclicks || 0, createdAt: a.createdAt, track: a.track !== false } : null, linkspin: ls, + return json(res, 200, { address: me, username: m.username, netVerified: netVerified(m), ad: a ? { id: a.id, headline: a.headline, line1: a.line1, line2: a.line2, link: a.link, status: a.status, views: a.views || 0, clicks: a.clicks || 0, vclicks: a.vclicks || 0, createdAt: a.createdAt, track: a.track !== false, spin: !!a.spin } : null, linkspin: ls, boosts: wire.purchases().filter(b => b.buyer === me).sort((x, y) => (y.at || 0) - (x.at || 0)).map(wire.boostView), earned: myEarned(me), line: line.slice(0, 8), lineOk: lo.ok, page, joinUrl: joinUrl(''), boost: C.boost }); } + // "Use one of my spin links" (Marty 2026-11-15): the member's own LinkSpin spin links, read from LinkSpin (lstrack.spins) + if (p === '/api/my/spins' && req.method === 'GET') { + if (limited(req, 'spins', 120, 3600000)) return json(res, 429, { error: 'Too many requests this hour.' }); + const m = store.member(me); if (!netVerified(m)) return json(res, 403, { error: 'Sign in through InstantAdPay or LinkSpin to use your spin links.' }); + const r = await lstrack.spins(m.username); if (r.error) return json(res, 502, { error: r.error }); + return json(res, 200, { account: r.account !== false, spins: r.spins || [] }); + } // the member's one text ad: create, or edit (a Boost follows the ad, so editing keeps it) if (p === '/api/my/ad' && req.method === 'POST') { if (limited(req, 'ad', 30, 3600000)) return json(res, 429, { error: 'Too many changes this hour.' }); @@ -376,14 +383,18 @@ const server = http.createServer(async (req, res) => { if (line1.length < 3 || line1.length > C.ad.line) return json(res, 400, { error: 'Write the first line in 3 to ' + C.ad.line + ' characters.' }); if (line2.length > C.ad.line) return json(res, 400, { error: 'Keep the second line to ' + C.ad.line + ' characters.' }); const lk = safety.checkLink(b.link, 'Your link'); if (lk.error) return json(res, 400, lk); + // a LinkSpin spin link (/r/ on a LinkSpin host) is accepted ONLY when LinkSpin confirms it is this member's own + // (lstrack.checkSpin, Marty 2026-11-15). It is already tracked on LinkSpin, so it never gets the tracked-link wrapper. + const sp = await lstrack.checkSpin(lk.url, m.username); if (sp.error) return json(res, 400, { error: sp.error }); + const spin = sp.spin ? sp.code : null; const cur = store.adOf(me); if (C.linkProbe && (!cur || cur.link !== lk.url)) { const pr = await safety.probeLink(lk.url, { frames: false }); if (pr.error) return json(res, 400, pr); } // "Track with LinkSpin" (default on): the ad's public link goes through the member's own LinkSpin tracked link (lstrack.js). // LinkSpin is asked right away (at most 4 s); if it does not answer, the ad goes live with its own link and the sweep retries. const track = b.track === undefined ? (cur ? cur.track !== false : true) : b.track !== false && b.track !== 'off' && b.track !== 0; const lsNow = async x => { if (!lstrack.on() || x.track === false) return lstrack.state(x); await Promise.race([lstrack.ensureAd(x).catch(() => {}), new Promise(r => setTimeout(r, 4000).unref())]); return lstrack.state(x); }; - if (cur) { Object.assign(cur, { headline, line1, line2, link: lk.url, track, status: cur.status === 'paused' ? 'paused' : 'live' }); if (cur.link !== (cur.ls && cur.ls.url)) delete cur.lsTry; store.saveAd(cur); return json(res, 200, { ok: true, ad: { id: cur.id }, created: false, linkspin: await lsNow(cur) }); } - const a = store.addAd({ owner: me, headline, line1, line2, link: lk.url, track, status: 'live', views: 0, clicks: 0, vclicks: 0 }); store.bump('adsPosted'); + if (cur) { Object.assign(cur, { headline, line1, line2, link: lk.url, track, spin, status: cur.status === 'paused' ? 'paused' : 'live' }); if (cur.link !== (cur.ls && cur.ls.url)) delete cur.lsTry; store.saveAd(cur); return json(res, 200, { ok: true, ad: { id: cur.id }, created: false, linkspin: await lsNow(cur) }); } + const a = store.addAd({ owner: me, headline, line1, line2, link: lk.url, track, spin, status: 'live', views: 0, clicks: 0, vclicks: 0 }); store.bump('adsPosted'); wire.attachPending(me, a.id); return json(res, 200, { ok: true, ad: { id: a.id }, created: true, linkspin: await lsNow(a) }); }