Public landing page (live stats, how it plays and pays, honest fine print), tester briefing moved to /testers, badge art served from /badges/ (cached, cross-origin) for IAP cards and link previews, signed /api/partner/player for the IAP Games card, /api/public/stats
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -210,13 +210,31 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
// ---- static + pages ----
|
||||
if (p === '/' || p === '/index.html') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'index.html')); }
|
||||
if (p === '/testers') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'testers.html')); } // the pre-launch briefing
|
||||
if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html'));
|
||||
if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html')); // the page asks for the key; every /api/admin call checks it
|
||||
if (p === '/spawn.js') return sendFile(res, path.join(__dirname, 'lib', 'spawn.js'));
|
||||
if (/^\/[a-z0-9._-]+\.(css|js|png|jpg|svg|ico|webp|mp4)$/i.test(p) && !p.includes('..')) return sendFile(res, path.join(PUBLIC_DIR, p.slice(1)));
|
||||
if (/^\/(badges\/)?[a-z0-9._-]+\.(css|js|png|jpg|svg|ico|webp|mp4)$/i.test(p) && !p.includes('..')) return sendFile(res, path.join(PUBLIC_DIR, p.slice(1)), p.startsWith('/badges/') ? { 'Cache-Control': 'public, max-age=86400', 'Access-Control-Allow-Origin': '*' } : undefined); // badge art is also shown on InstantAdPay and in link previews
|
||||
|
||||
// ---- member API ----
|
||||
if (p.startsWith('/api/')) {
|
||||
// the landing page's live numbers (public, no personal data)
|
||||
if (p === '/api/public/stats' && req.method === 'GET') {
|
||||
const players = Object.values(store.read('players', {})).filter(x => x.memberId > 0).length;
|
||||
const paid = store.read('payouts', []).filter(x => x.status === 'paid');
|
||||
return json(res, 200, { players, refuels: store.read('refuels', []).length, chapterDrips: store.read('drips', []).length,
|
||||
polPaid: Math.round(paid.reduce((n, x) => n + x.pol, 0) * 10000) / 10000, payouts: paid.length, dripPol: Number(ledger.settings().dripPol), thresholdPol: Number(ledger.settings().thresholdPol), refSharePct: Number(ledger.settings().refSharePct) || 0 });
|
||||
}
|
||||
// IAP's Games page asks for a player's line on the card: signed with the shared secret, read only (2026-10-01)
|
||||
if (p === '/api/partner/player' && req.method === 'GET') {
|
||||
const m = Number(u.searchParams.get('m')), ts = String(u.searchParams.get('ts') || ''), sig = String(u.searchParams.get('sig') || '');
|
||||
if (!SECRET || !m || !ts || Math.abs(Date.now() - Number(ts)) > 5 * 60000) return json(res, 401, { error: 'bad request' });
|
||||
const want = crypto.createHmac('sha256', SECRET).update('player:' + m + ':' + ts).digest('hex');
|
||||
if (want.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return json(res, 401, { error: 'bad signature' });
|
||||
const pl = game.player(m); if (!pl) return json(res, 200, { played: false });
|
||||
const b = ledger.balance(m);
|
||||
return json(res, 200, { played: true, chapter: pl.chapter, best: pl.best, unpaid: b.unpaid, paidTotal: b.paidTotal, earnedTotal: b.earnedTotal });
|
||||
}
|
||||
const me = sso.fromRequest(req);
|
||||
if (p.startsWith('/api/admin/')) {
|
||||
if (!admin(req, u)) return json(res, 403, { error: 'admin key' });
|
||||
|
||||
Reference in New Issue
Block a user