New public home on the Instrument scheme: working demo (paste up to three pages, get a live spin link on a link domain, email code to keep it; demo spins are per browser, five per IP per hour, expire after 24 h unless claimed at sign-in), live strip from the chain and the rotator, the three free tools, the split card, the six-package ladder read from the catalog, LinkSpin share image; pub.css for every public page

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-07 08:58:57 -05:00
parent ad744d8c0f
commit dfb677bb09
6 changed files with 479 additions and 592 deletions
+22 -1
View File
@@ -177,6 +177,7 @@ function getAdminWallAds() {
return [{ name: 'LinkSpin', targetUrl: SITE_URL + '/', bannerUrl: null }];
}
const chatHits = new Map();
const demoLimits = new Map(); // ip -> timestamps of home-page demo spins (5 per hour)
function chatLimited(ip) {
const now = Date.now(), rec = chatHits.get(ip);
if (!rec || now > rec.reset) { chatHits.set(ip, { count: 1, reset: now + 60000 }); return false; }
@@ -397,6 +398,7 @@ async function boot() {
carry.init({ dataDir: DATA_DIR, accounts, registry, chain, mailer, messages, siteConfig, adminEmail: ADMIN_EMAIL, host: SITE_HOST });
const ownHosts = () => [SITE_HOST].concat(String(siteConfig().linkDomains || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean));
rotator.init({ dataDir: DATA_DIR, geo, ownHosts });
setInterval(() => { try { rotator.sweepDemos(); } catch (e) {} }, 60 * 60 * 1000); // unclaimed home-page demo spins expire after 24 h
postbacks.init({ dataDir: DATA_DIR, ownHosts, rotator });
zones.init({ dataDir: DATA_DIR, ads, siteHost: SITE_HOST });
pages.init({ dataDir: DATA_DIR, ownHosts, openrouterKey: () => { if (process.env.OPENROUTER_API_KEY) return process.env.OPENROUTER_API_KEY.trim(); try { return fs.readFileSync(path.join(DATA_DIR, 'openrouter.key'), 'utf8').trim(); } catch (e) { return ''; } } });
@@ -1113,7 +1115,25 @@ const server = http.createServer(async (req, res) => {
}
if (p === '/api/stats' && req.method === 'GET') {
let members = 0; try { members = await chain.memberCount(); } catch (e) {}
return json(res, 200, Object.assign({ onchainMembers: members, siteAccounts: await accounts.count() }, chain.totals()));
return json(res, 200, Object.assign({ onchainMembers: members, siteAccounts: await accounts.count(), servedToday: rotator.servedToday(), rotations: rotator.totals().rotations }, chain.totals()));
}
// -- home-page demo: a working spin link with no account (2026-10-07). One per browser (ls.demo cookie),
// five per IP per hour, 24 h unless the visitor signs in (the email door then claims it).
if (p === '/api/demo/spin' && req.method === 'POST') {
const ip = clientIp(req); const now = Date.now();
const dl = demoLimits.get(ip) || []; const recent = dl.filter(t => now - t < 3600000);
if (recent.length >= 5) return json(res, 429, { error: 'That is plenty of demo links for one hour. Sign in to make more.' });
const b = await readBody(req);
const urls = Array.isArray(b.urls) ? b.urls.map(x => String(x || '').trim()).filter(Boolean) : [];
let token = String(parseCookies(req)['ls.demo'] || '').replace(/[^a-f0-9]/g, '').slice(0, 32);
if (token.length < 16) token = crypto.randomBytes(12).toString('hex');
const r = await rotator.createDemo(token, urls);
if (r.error) return json(res, 400, r);
recent.push(now); demoLimits.set(ip, recent);
const hosts = String(siteConfig().linkDomains || '').split(',').map(x => x.trim()).filter(x => x && !x.startsWith('www.'));
const host = hosts[0] || SITE_HOST;
return json(res, 200, { ok: true, code: r.rotation.code, url: 'https://' + host + '/r/' + r.rotation.code, destinations: r.rotation.destinations.length, expiresIn: 24 * 3600 },
{ 'Set-Cookie': 'ls.demo=' + token + '; Path=/; Max-Age=2592000; HttpOnly; SameSite=Lax' + (IS_PROD ? '; Secure' : '') });
}
// -- 24/7 assistant
@@ -1190,6 +1210,7 @@ const server = http.createServer(async (req, res) => {
if (r.error) return json(res, 400, r);
if (r.created) carry.onJoin(r.account, !!ref).catch(() => {}); // network sponsor carries over when no link was used (LinkSpin)
if (r.created) { const lc = parseCookies(req)['ls.click']; if (lc) { postbacks.bindClick(e, lc); postbacks.convertFor(e, 'join', {}).catch(() => {}); } }
{ const dm = String(parseCookies(req)['ls.demo'] || '').replace(/[^a-f0-9]/g, ''); if (dm.length >= 16) rotator.claim('demo:' + dm, e).catch(() => {}); } // the home-page demo spin becomes theirs
// the lead is in the door: queue the getting-started sequence (opt-in box is pre-checked on both forms)
if (r.created && (b.followups || b.newsletter)) drip.enqueue(e, ref, via).catch(() => {});
// a wallet-only session (signed with a wallet, no account) finishing setup: