Drip Runner trial (2026-09-30): /api/my/driprunner hand-off, /refuel verified-visit page for the game (advertiser charged, viewer gets fuel not credits, signed callback + receipt), completeVisit(opts)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-30 13:33:37 -05:00
parent 3ae9ab55e9
commit 587272673b
4 changed files with 164 additions and 0 deletions
BIN
View File
Binary file not shown.
+46
View File
@@ -0,0 +1,46 @@
/* Drip Runner refuel: one verified visit, then back to the game with a signed receipt. */
(function () {
'use strict';
var $ = function (id) { return document.getElementById(id); };
var q = new URLSearchParams(location.search); var tok = q.get('t') || '';
var nonce = ''; try { nonce = JSON.parse(atob(tok.split('.')[0].replace(/-/g, '+').replace(/_/g, '/'))).nonce || ''; } catch (e) {}
var ret = null, dwell = 8, left = 8, timer = null, done = false;
function msg(title, text, backUrl) { $('rfFrame').innerHTML = '<div class="rf-msg" style="background:#0b1020;height:100%"><h1>' + title + '</h1><p>' + text + '</p></div>'; $('rfDone').hidden = true; $('rfCheck').hidden = true; if (backUrl) { var b = $('rfBack'); b.hidden = false; b.onclick = function () { location.href = backUrl; }; } }
function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]; }); }
function api(p, body) { return fetch(p, body ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}).then(function (r) { return r.json(); }); }
function ring() { $('rfN').textContent = left; $('rfRing').style.setProperty('--p', ((dwell - left) / dwell * 100) + '%'); }
function tick() {
if (document.hidden) return; // the timer only runs while the page is in front
left--; if (left > 0) return ring();
clearInterval(timer); ring(); $('rfHint').textContent = 'One quick check to count the visit:';
challenge();
}
function challenge() {
api('/api/refuel/challenge?n=' + encodeURIComponent(nonce)).then(function (c) {
if (c.early) { setTimeout(challenge, (c.wait || 1) * 1000 + 300); return; }
if (c.error) { $('rfHint').textContent = c.error; return; }
$('rfPrompt').textContent = 'Tap the ' + c.prompt + ':'; var w = $('rfOpts'); w.innerHTML = '';
c.options.forEach(function (em, i) { var b = document.createElement('button'); b.type = 'button'; b.textContent = em; b.addEventListener('click', function () { answer(i); }); w.appendChild(b); });
$('rfCheck').hidden = false;
});
}
function answer(i) {
api('/api/refuel/done', { n: nonce, answer: i }).then(function (r) {
if (r.error) { if (r.retry) return challenge(); $('rfHint').textContent = r.error; $('rfCheck').hidden = true; return; }
done = true; $('rfCheck').hidden = true; $('rfHint').textContent = 'Visit counted. Your tank is full.';
var b = $('rfDone'); b.disabled = false; b.textContent = 'Back to the run'; b.onclick = function () { location.href = r.ret; };
setTimeout(function () { location.href = r.ret; }, 1200);
});
}
if (!tok) return msg('No refuel link', 'Open this page from the game’s Refuel button.');
api('/api/refuel/open?t=' + encodeURIComponent(tok)).then(function (r) {
if (r.error) return msg('Refuel link problem', esc(r.error));
if (r.done) { location.href = r.ret; return; }
if (r.none) return msg('No sponsor pages right now', r.why === 'cap' ? 'You have done today’s verified visits on InstantAdPay. Refuels reopen tomorrow.' : 'No verified-visit packs are running at the moment. Try again in a while.', r.ret + '&none=1');
ret = r.ret; dwell = r.dwell || 8; left = Math.max(1, dwell - (r.elapsed || 0));
$('rfTitle').textContent = r.title || 'Member site'; try { $('rfUrl').textContent = new URL(r.target).hostname; } catch (e) {}
var f = document.createElement('iframe'); f.src = r.target; f.setAttribute('referrerpolicy', 'no-referrer'); f.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms allow-popups'); $('rfFrame').innerHTML = ''; $('rfFrame').appendChild(f);
var o = $('rfOpen'); o.href = r.target; o.hidden = false;
ring(); timer = setInterval(tick, 1000);
}).catch(function () { msg('Could not load the visit', 'Check your connection and go back to the game.'); });
})();
+42
View File
@@ -0,0 +1,42 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<meta name="robots" content="noindex,nofollow">
<title>Refuel · InstantAdPay verified visit</title>
<link rel="stylesheet" href="/assets/site.css?v=20260929b">
<style>
html,body{height:100%}
body{margin:0;display:flex;flex-direction:column;background:#0b1020;color:#e6edf3}
.rf-bar{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px 14px;background:#0E1730;border-bottom:1px solid #22304f;font-size:13px}
.rf-bar b{color:#fff}.rf-bar .rf-url{color:#8fa3c4;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.rf-frame{flex:1;min-height:0;background:#fff;position:relative}
.rf-frame iframe{position:absolute;inset:0;width:100%;height:100%;border:0}
.rf-dock{padding:12px 14px calc(12px + env(safe-area-inset-bottom,0px));background:#0E1730;border-top:1px solid #22304f}
.rf-row{display:grid;grid-template-columns:48px 1fr;gap:12px;align-items:center}
.rf-ring{width:48px;height:48px;border-radius:50%;background:conic-gradient(#FF6A1A var(--p,0%),#22304f 0);display:grid;place-items:center;font:800 13px ui-monospace,Menlo,Consolas,monospace;position:relative}
.rf-ring:after{content:"";position:absolute;inset:5px;border-radius:50%;background:#0E1730}.rf-ring span{position:relative;z-index:1}
.rf-dock p{margin:0;font-size:13px;color:#afc0d8}.rf-dock p b{color:#fff}
.rf-opts{display:flex;gap:8px;flex-wrap:wrap;margin-top:8px}
.rf-opts button{font-size:24px;padding:8px 14px;border-radius:10px;border:1px solid #22304f;background:#141F3A;cursor:pointer}
.rf-btn{display:block;width:100%;margin-top:10px;padding:13px;border-radius:12px;border:0;font:800 15px system-ui,sans-serif;letter-spacing:.06em;text-transform:uppercase;color:#fff;background:linear-gradient(180deg,#FFB088,#FF6A1A 55%,#D44E00);cursor:pointer}
.rf-btn[disabled]{opacity:.45}
.rf-btn.ghost{background:transparent;border:1px solid #22304f;color:#afc0d8;font-size:13px;padding:10px}
.rf-msg{padding:24px 18px;text-align:center}
.rf-msg h1{font-size:22px;margin:0 0 8px}.rf-msg p{color:#afc0d8}
a.rf-open{color:#8FF0FF;font-size:12px}
</style>
</head>
<body>
<div class="rf-bar"><span>InstantAdPay · <b>verified visit</b> · refuel for Drip Runner</span><span class="rf-url" id="rfUrl"></span></div>
<div class="rf-frame" id="rfFrame"></div>
<div class="rf-dock" id="rfDock">
<div class="rf-row"><div class="rf-ring" id="rfRing"><span id="rfN">…</span></div><div><p><b id="rfTitle">Loading the sponsor page…</b></p><p id="rfHint">Stay on this page. The timer only runs while it is in front.</p><a class="rf-open" id="rfOpen" href="#" target="_blank" rel="noopener" hidden>Page not showing? Open it in a new tab (the timer keeps running here).</a></div></div>
<div id="rfCheck" hidden><p id="rfPrompt" style="margin-top:10px"></p><div class="rf-opts" id="rfOpts"></div></div>
<button class="rf-btn" id="rfDone" type="button" disabled>Waiting…</button>
<button class="rf-btn ghost" id="rfBack" type="button" hidden>Back to the game</button>
</div>
<script src="/assets/refuel.js?v=20260930a"></script>
</body>
</html>
+76
View File
@@ -1224,6 +1224,30 @@ function pushFeed(ev) {
}
// ---- server ----
// -- Drip Runner (2026-09-30): the hand-off, refuel visits and the signed callback to the game.
// Tokens share PolHunter's shape (base64url payload . base64url HMAC) under a separate secret.
const DR_SECRET = () => String(process.env.DR_SSO_SECRET || '').trim();
const DR_URL = () => String(process.env.DR_URL || 'https://driprunner.saasy.top').replace(/\/+$/, '');
const drB64u = b => Buffer.from(b).toString('base64').replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
const drSign = payload => drB64u(crypto.createHmac('sha256', DR_SECRET()).update(payload).digest());
function drMint(claims, ttlMs) { const payload = JSON.stringify(Object.assign({ iat: Date.now(), exp: Date.now() + (ttlMs || 300000), nonce: crypto.randomBytes(12).toString('hex') }, claims)); return drB64u(payload) + '.' + drSign(payload); }
function drOpen(token) {
if (DR_SECRET().length < 32) return { error: 'Drip Runner is not connected yet.' };
const [p, sig] = String(token || '').split('.'); if (!p || !sig) return { error: 'That link is not valid.' };
let payload; try { payload = Buffer.from(String(p).replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'); } catch (e) { return { error: 'That link is not valid.' }; }
const want = drSign(payload); if (want.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return { error: 'That link is not valid.' };
let c; try { c = JSON.parse(payload); } catch (e) { return { error: 'That link is not valid.' }; }
if (!c.exp || Date.now() > c.exp) return { error: 'That refuel link has expired. Go back to the game and tap Refuel again.' };
return { ok: true, claims: c };
}
const refuelTokens = new Map(); // nonce -> { email, memberId, id, title, target, ts, ret, challenge, done }
async function drCallback(body) {
const raw = JSON.stringify(body); const ts = String(Date.now());
const sig = crypto.createHmac('sha256', DR_SECRET()).update(ts + '\n' + raw).digest('hex');
try { const r = await fetch(DR_URL() + '/api/refuel/callback', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-DR-Ts': ts, 'X-DR-Sig': sig }, body: raw, signal: AbortSignal.timeout(8000) }); return r.ok; }
catch (e) { console.warn('driprunner callback', e.message); return false; }
}
const server = http.createServer(async (req, res) => {
try {
const u = new URL(req.url, 'http://x');
@@ -2401,6 +2425,57 @@ const server = http.createServer(async (req, res) => {
const tok = b64u(payload) + '.' + b64u(crypto.createHmac('sha256', secret).update(payload).digest());
res.writeHead(302, { Location: huntUrl + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end(); // the loop is closed
}
// -- Drip Runner hand-off (2026-09-30): sign the member across, the game verifies with the shared secret
if (p === '/api/my/driprunner' && req.method === 'GET') {
const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: '/my' }); return res.end(); }
if (DR_SECRET().length < 32) return json(res, 503, { error: 'Drip Runner is not connected yet.' });
const acct = await accounts.byEmail(s.email);
const memberId = (acct && acct.memberId) || s.memberId || 0;
const tok = drMint({ memberId: Number(memberId), email: s.email, wallet: (acct && acct.address) || s.address || null, username: (acct && acct.username) || null });
res.writeHead(302, { Location: DR_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store' }); return res.end();
}
// -- Drip Runner refuel: a real verified visit (advertiser charged as usual); the player gets fuel, not credits
if (p === '/api/refuel/open' && req.method === 'GET') {
const r = drOpen(u.searchParams.get('t')); if (r.error) return json(res, 400, { error: r.error });
const c = r.claims; if (c.kind !== 'refuel' || !c.nonce || !c.email || !c.ret) return json(res, 400, { error: 'That is not a refuel link.' });
for (const [n, v] of refuelTokens) if (v.ts + 30 * 60000 < Date.now()) refuelTokens.delete(n);
let t = refuelTokens.get(c.nonce);
if (t && t.done) return json(res, 200, { done: true, ret: t.doneRet || t.ret });
if (!t) {
const email = String(c.email).toLowerCase();
const status = await ads.visitStatus(email);
if (status.count >= status.cap) return json(res, 200, { none: true, why: 'cap', ret: c.ret });
const ad = await ads.serveVisit(email, viewerGeo(req));
if (!ad) return json(res, 200, { none: true, why: 'empty', ret: c.ret });
t = { email, memberId: Number(c.memberId), id: ad.id, title: ad.title, target: ad.target, ts: Date.now(), ret: c.ret, challenge: null, done: false };
refuelTokens.set(c.nonce, t);
}
return json(res, 200, { title: t.title, target: t.target, dwell: ads.rates().visitDwellSeconds || 8, ret: t.ret, elapsed: Math.floor((Date.now() - t.ts) / 1000) });
}
if (p === '/api/refuel/challenge' && req.method === 'GET') {
const t = refuelTokens.get(String(u.searchParams.get('n') || ''));
if (!t || t.done) return json(res, 400, { error: 'That refuel is no longer open.' });
const dwellMs = (ads.rates().visitDwellSeconds || 8) * 1000; const age = Date.now() - t.ts;
if (age < dwellMs - 400) return json(res, 200, { early: true, wait: Math.ceil((dwellMs - age) / 1000) });
const pick = CAPTCHA.slice().sort(() => Math.random() - 0.5).slice(0, 5); const answer = Math.floor(Math.random() * pick.length);
t.challenge = { answer };
return json(res, 200, { prompt: pick[answer][1], options: pick.map(x => x[0]) });
}
if (p === '/api/refuel/done' && req.method === 'POST') {
const b = await readBody(req); const nonce = String(b.n || ''); const t = refuelTokens.get(nonce);
if (!t || t.done) return json(res, 400, { error: 'That refuel is no longer open.' });
if (!t.challenge) return json(res, 400, { error: 'Finish the quick check first.', retry: true });
if (Number(b.answer) !== t.challenge.answer) { t.challenge = null; return json(res, 400, { error: 'Wrong pick.', retry: true }); }
const r = await ads.completeVisit(t.email, t.id, { reward: false, note: 'Drip Runner refuel' });
if (r.error) return json(res, 400, r);
t.done = true;
const credits = ads.rates().visitCostPerVisit || 3;
const posted = await drCallback({ nonce, memberId: t.memberId, campaignId: t.id, credits });
const receipt = drMint({ kind: 'refuel-receipt', nonce, campaignId: t.id, credits }, 15 * 60000);
t.doneRet = t.ret + '&ok=1&r=' + encodeURIComponent(receipt);
return json(res, 200, { ok: true, posted, ret: t.doneRet });
}
if (p === '/api/my/claim' && req.method === 'POST') {
const s = await auth.fromRequest(req);
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
@@ -3502,6 +3577,7 @@ const server = http.createServer(async (req, res) => {
if (p === '/wallets') return sendFile(res, path.join(PUBLIC_DIR, 'wallets.html'));
if (p === '/friday') return sendFile(res, path.join(PUBLIC_DIR, 'friday.html'));
if (p === '/wednesday') return sendFile(res, path.join(PUBLIC_DIR, 'wednesday.html'));
if (p === '/refuel') return sendFile(res, path.join(PUBLIC_DIR, 'refuel.html')); // Drip Runner refuel visit (2026-09-30)
// per-partner kit pages (Marty, 2026-09-29): /partners/<slug> serves public/kits/<slug>.html, one file per reviewer or site owner
{ const mk = p.match(/^\/partners\/([a-z0-9-]{2,40})$/); if (mk) { const f = path.join(PUBLIC_DIR, 'kits', mk[1] + '.html'); if (fs.existsSync(f)) return sendFile(res, f); } }
if (p === '/plan-lab') return sendFile(res, path.join(PUBLIC_DIR, 'plan-lab.html')); // Reach Ladder simulator for Marty's planning group: unlisted, shared by link (2026-09-27)