"Use one of my spin links" on the text-ad form (Marty 2026-11-15): a member picks one of their own LinkSpin spin links as the ad link, so one free ad rotates clicks across every page they promote. Listed live from LinkSpin (GET /api/my/spins -> lstrack.spins, /api/partner/vab/links op 'spins'). A LinkSpin /r/<code> link on any LinkSpin host is accepted ONLY when LinkSpin confirms it is the signed-in member's own (lstrack.checkSpin): someone else's, a paused one, one with no active pages, or any while LinkSpin is not answering is refused; the network's fixed nw* links and /r/ links on other sites stay ordinary links; other shortener rules unchanged. A spin-link ad (ad.spin) never gets the "Track with LinkSpin" wrapper: /go/<ad> sends straight to the spin link, the checkbox is greyed with a note. LinkSpin hosts learned from every spins answer (warmed hourly by the sweep). Chatbot: CANNED spin-link + FACTS. my.js?v=7. Smoke 217 pass (14b2: foreign refused, own accepted), chatbot 206 pass

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 14:37:18 -06:00
parent 8630c9aa9a
commit 4dd1e5a07f
6 changed files with 130 additions and 14 deletions
+50 -3
View File
@@ -11,6 +11,12 @@
// ensureAd(ad) -> updates ad.ls { code, link, url, at } or ad.lsErr / ad.lsTry; saves through the store
// clicks(username) -> { <ad id>: { 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/<code> 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() };