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:
+35
-1
@@ -138,4 +138,38 @@ async function stats(owner, id) {
|
||||
}
|
||||
function totals() { return { rotations: J.db.rotations.length, hits: J.db.hits.length }; }
|
||||
|
||||
module.exports = { init, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary };
|
||||
// ── demo spins (home page, 2026-10-07) ─────────────────────────────────────────────────────────────────────
|
||||
// A visitor with no account pastes up to three pages and gets a working link at once. The rotation is owned by
|
||||
// 'demo:<token>' (token in the ls.demo cookie) and expires after 24 h unless the visitor signs in, at which point
|
||||
// claim() hands it to their email and the expiry is lifted. Demo owners never count against a member's quota.
|
||||
const DEMO_TTL = 24 * DAY;
|
||||
async function createDemo(token, urls) {
|
||||
const t = String(token || '').replace(/[^a-f0-9]/g, '').slice(0, 32); if (t.length < 16) return { error: 'Bad demo token.' };
|
||||
const owner = 'demo:' + t;
|
||||
if (J.db.rotations.some(r => r.owner === owner)) return { error: 'This browser already made a demo spin. Sign in to make more.' };
|
||||
const clean = (urls || []).map(cleanUrl).filter(Boolean).slice(0, 3);
|
||||
if (clean.length < 1) return { error: 'Paste at least one page address that starts with https://' };
|
||||
const r = await create(owner, { name: 'My first spin' }); if (r.error) return r;
|
||||
const rec = J.db.rotations.find(x => x.id === r.rotation.id); rec.demo = true; rec.expires = Date.now() + DEMO_TTL;
|
||||
for (const u of clean) await addDest(owner, rec.id, { url: u, weight: 1, label: '' });
|
||||
J.save(); return { ok: true, rotation: pub(rec) };
|
||||
}
|
||||
async function claim(demoOwner, newOwner) {
|
||||
const o = norm(newOwner); if (!o || !demoOwner) return { ok: false };
|
||||
const mine = J.db.rotations.filter(r => r.owner === demoOwner);
|
||||
for (const r of mine) { r.owner = o; delete r.demo; delete r.expires; r.name = r.name === 'My first spin' ? 'My first spin' : r.name; }
|
||||
if (mine.length) J.save(); return { ok: true, claimed: mine.length };
|
||||
}
|
||||
function sweepDemos() {
|
||||
const now = Date.now(); const gone = new Set();
|
||||
J.db.rotations = J.db.rotations.filter(r => { if (r.demo && r.expires && r.expires < now) { gone.add(r.id); return false; } return true; });
|
||||
if (gone.size) { J.db.hits = J.db.hits.filter(h => !gone.has(h.r)); J.db.conv = J.db.conv.filter(c => !gone.has(c.r)); J.save(); }
|
||||
return gone.size;
|
||||
}
|
||||
function servedToday() {
|
||||
// Central-time day, like Reports
|
||||
const now = new Date(); const ct = new Date(now.toLocaleString('en-US', { timeZone: 'America/Chicago' }));
|
||||
const startCt = new Date(ct.getFullYear(), ct.getMonth(), ct.getDate()).getTime(); const start = now.getTime() - (ct.getTime() - startCt);
|
||||
return J.db.hits.filter(h => h.ts >= start && !h.bot).length;
|
||||
}
|
||||
module.exports = { init, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary, createDemo, claim, sweepDemos, servedToday };
|
||||
|
||||
Reference in New Issue
Block a user