Share links preview as the sharer's own card (badge with their name) for Telegram/Facebook/X; the game page previews as the Drip Runner banner, not the blank badge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-04 10:18:49 -05:00
parent 75ba7ba388
commit 4fa68b2745
2 changed files with 190 additions and 172 deletions
+18
View File
@@ -207,6 +207,24 @@ const server = http.createServer(async (req, res) => {
if (first) notify('signin', { memberId: r.claims.memberId, username: r.claims.username, wallet: r.claims.wallet, via: guest ? 'a share link' : null }).catch(() => {});
res.writeHead(302, { Location: '/play' + (pendingClears.length ? '?collected=' + pendingClears.length : ''), 'Set-Cookie': [sso.cookie(sid)].concat(guest ? [sso.clearGuestCookie()] : []), 'Cache-Control': 'no-store' }); return res.end();
}
// a member's share card (2026-10-04, Neville/cryptoassets: his link previewed as the blank First Chapter badge): the badge with
// the sharer's name on the plate, rendered once and cached by lib/badge.js
{ const mc = /^\/r\/([A-Za-z0-9_.-]{1,40})\/card\.jpg$/.exec(p); if (mc) {
const sharer = game.byUsername(mc[1]); if (!sharer) return sendFile(res, path.join(PUBLIC_DIR, 'og-driprunner.jpg'));
const f = await badge.render('ch1', '@' + sharer.username, 'invites you to play Drip Runner', 'PLAY FREE \u00b7 EARN POL');
if (!f) return sendFile(res, path.join(PUBLIC_DIR, 'og-driprunner.jpg'));
res.writeHead(200, Object.assign({ 'Content-Type': 'image/jpeg', 'Cache-Control': 'public, max-age=86400' }, SEC)); return fs.createReadStream(f).pipe(res);
} }
{ const mr = /^\/r\/([A-Za-z0-9_.-]{1,40})$/.exec(p);
// link-preview robots (Telegram, Facebook, X, WhatsApp...) get the sharer's own card; people get the game, as before
if (mr && /TelegramBot|facebookexternalhit|Facebot|Twitterbot|WhatsApp|Slackbot|Discordbot|LinkedInBot|SkypeUriPreview|redditbot|Iframely|Embedly|vkShare|Pinterest|Googlebot|bingbot/i.test(String(req.headers['user-agent'] || ''))) {
const sh = game.byUsername(mr[1]); const nm = sh ? sh.username : null; const card = SITE + '/r/' + encodeURIComponent(mr[1]) + '/card.jpg';
const t = nm ? '@' + nm + ' invited you to Drip Runner' : 'Drip Runner: hop the network, get paid in POL';
const d = 'A fast little runner game in the InstantAdPay network. Play free, clear chapters and collect POL rewards.';
res.writeHead(200, Object.assign({ 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' }, SEC));
return res.end('<!doctype html><html><head><meta charset="utf-8"><title>' + esc(t) + '</title><meta name="description" content="' + esc(d) + '"><meta property="og:type" content="website"><meta property="og:site_name" content="Drip Runner"><meta property="og:url" content="' + esc(SITE + '/r/' + mr[1]) + '"><meta property="og:title" content="' + esc(t) + '"><meta property="og:description" content="' + esc(d) + '"><meta property="og:image" content="' + esc(nm ? card : SITE + '/og-driprunner.jpg') + '"><meta property="og:image:width" content="' + (nm ? 1080 : 1200) + '"><meta property="og:image:height" content="' + (nm ? 1080 : 630) + '"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:title" content="' + esc(t) + '"><meta name="twitter:image" content="' + esc(nm ? card : SITE + '/og-driprunner.jpg') + '"></head><body><a href="/play">Play Drip Runner</a></body></html>');
}
}
{ const mr = /^\/r\/([A-Za-z0-9_.-]{1,40})$/.exec(p); if (mr) {
const sharer = game.byUsername(mr[1]);
if (!sharer) { res.writeHead(302, { Location: '/', 'Cache-Control': 'no-store' }); return res.end(); }