c25ae40f8b
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
4.8 KiB
JavaScript
64 lines
4.8 KiB
JavaScript
// The network sites list for the footer's "Part of the network" line (Marty 2026-11-14 trust pack).
|
|
// One source: the hub's public GET /v1/network-sites (HUB_URL). Cached 10 minutes, refreshed in the background, never waits on a
|
|
// slow hub (2.5 s timeout), and falls back to the same built-in list. Never RM Circle, never the games.
|
|
// The same file lives in every network site (InstantAdPay, LinkSpin, Downline Banners, VBB, ViralAdBlitz, 5xYourTeam, Stack POL).
|
|
// 5xYourTeam: its 'fivex' entry and the LinkSpin code nw5x are local until the hub list and LinkSpin netlinks.js add them (phase 2).
|
|
const FALLBACK = [
|
|
{ id: 'iap', name: 'InstantAdPay', url: 'https://instantadpay.com' },
|
|
{ id: 'linkspin', name: 'LinkSpin', url: 'https://linkspin.app' },
|
|
{ id: 'dlb', name: 'Downline Banners', url: 'https://downlinebanners.com' },
|
|
{ id: 'vbb', name: 'Viral Banner Blitz', url: 'https://viralbannerblitz.com' },
|
|
{ id: 'viraladblitz', name: 'ViralAdBlitz', url: 'https://viraladblitz.com' },
|
|
{ id: 'fivex', name: '5xYourTeam', url: 'https://5xyourteam.com' },
|
|
{ id: 'stackpol', name: 'Stack POL', url: 'https://stackpol.com' },
|
|
{ id: 'earnerscorner', name: 'Earners Corner', url: 'https://earnerscorner.com' }
|
|
];
|
|
const TTL = 10 * 60 * 1000;
|
|
let cache = { at: 0, list: FALLBACK, from: 'fallback' };
|
|
let inflight = null;
|
|
|
|
const hubUrl = () => String(process.env.HUB_URL || 'https://hub.saasy.top').trim().replace(/\/+$/, '');
|
|
function clean(list) {
|
|
if (!Array.isArray(list)) return null;
|
|
const ok = list.filter(s => s && typeof s.name === 'string' && /^https:\/\/[a-z0-9.-]+(\/[^\s"'<>]*)?$/i.test(String(s.url || '')))
|
|
.slice(0, 30).map(s => ({ id: String(s.id || s.name).toLowerCase().replace(/[^a-z0-9]+/g, '').slice(0, 30), name: String(s.name).slice(0, 60), url: String(s.url).replace(/\/+$/, '') }));
|
|
return ok.length ? ok : null;
|
|
}
|
|
function refresh() {
|
|
if (inflight || process.env.NETWORK_SITES_HUB === '0') return inflight;
|
|
const ac = new AbortController(); const t = setTimeout(() => ac.abort(), 2500);
|
|
inflight = fetch(hubUrl() + '/v1/network-sites', { signal: ac.signal })
|
|
.then(r => (r.ok ? r.json() : null))
|
|
.then(j => { const l = clean(j); if (l) cache = { at: Date.now(), list: l, from: 'hub' }; else cache.at = Date.now(); })
|
|
.catch(() => { cache.at = Date.now() - TTL + 60 * 1000; }) // hub down: try again in a minute, keep the last good list
|
|
.finally(() => { clearTimeout(t); inflight = null; });
|
|
return inflight;
|
|
}
|
|
function list() { if (Date.now() - cache.at > TTL) refresh(); return cache.list; }
|
|
// Tracked links (Marty 2026-11-14: "make sure each of these sites is its own traffic source and link spun so we can track it"): each
|
|
// entry also gets go = the LinkSpin network link for that site with ?src=<this site>, so a click shows in LinkSpin Reports under the
|
|
// site that sent it (LinkSpin netlinks.js: fixed codes on the admin account). This site = NETWORK_SITE_ID, else the request host.
|
|
// No go for this site itself, or when this site cannot be told (a test host): the page then uses the plain url.
|
|
const CODES = { iap: 'nwiap', linkspin: 'nwls', dlb: 'nwdlb', vbb: 'nwvbb', viraladblitz: 'nwvab', fivex: 'nw5x', downlinehydra: 'nwdh', stackpol: 'nwsp', earnerscorner: 'nwec' };
|
|
const linksBase = () => String(process.env.NETWORK_LINKS_BASE || 'https://linkspin.app').trim().replace(/\/+$/, '');
|
|
const hostOf = u => { try { return new URL(u).hostname.toLowerCase().replace(/^www\./, ''); } catch (e) { return ''; } };
|
|
function selfId(req, l) {
|
|
const env = String(process.env.NETWORK_SITE_ID || '').trim().toLowerCase(); if (env) return env;
|
|
const h = String((req && req.headers && (req.headers['x-forwarded-host'] || req.headers.host)) || '').split(',')[0].trim().toLowerCase().replace(/:\d+$/, '').replace(/^www\./, '');
|
|
const m = h && (l || list()).find(s => hostOf(s.url) === h); return m ? m.id : '';
|
|
}
|
|
// the LinkSpin-tracked link to site `id` sent from site `from` (from = id: the site's own promo kit); extra = { s1: member username, s2: one path segment }
|
|
function tracked(id, from, extra) {
|
|
const code = CODES[id]; if (!code || !from) return '';
|
|
const q = new URLSearchParams({ src: from }); for (const [k, v] of Object.entries(extra || {})) if (v) q.set(k, String(v));
|
|
return linksBase() + '/r/' + code + '?' + q.toString();
|
|
}
|
|
function withGo(l, me) { return l.map(s => { const go = me && s.id !== me ? tracked(s.id, me) : ''; return go ? Object.assign({}, s, { go }) : s; }); }
|
|
// GET /api/network-sites: public, cacheable, the same answer on every page
|
|
function handle(req, res) {
|
|
const l = list();
|
|
res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'public, max-age=300', 'X-Content-Type-Options': 'nosniff' });
|
|
res.end(JSON.stringify(withGo(l, selfId(req, l))));
|
|
}
|
|
module.exports = { list, handle, refresh, tracked, selfId, withGo, CODES, FALLBACK, _state: () => cache };
|