Friday Bonus Hunts: InstantAdPay counts the banked days
Each day Saturday through Thursday (Central) that a member opens an inbox ad and watches a video banks one extra PolHunter hunt for the following Friday. If their inbox had no unread solo ad that day, the video alone counts, so nobody is blocked by an empty inbox. These are the two slowest-delivering ad types (about 6-7 views per campaign per day against 40-50 for banners), so the game sends attention exactly where advertisers are short of it. fridaybank.js counts from video_seen and solo_inbox.read_ts with DST-safe Central midnights. /api/my/friday-bank feeds a card on the Earn tab (week chips, today's two steps with links to the right sub-tab); /api/hunt/friday-bank answers PolHunter, HMAC-signed with the existing HUNT_SSO_SECRET, 5-minute window. QA member walk: 0 bugs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// Friday Bonus Hunts (Marty, 2026-09-26).
|
||||
//
|
||||
// PolHunter hunters bank one extra FRIDAY hunt for each day, Saturday through Thursday (Central),
|
||||
// that they do both of the things InstantAdPay's two slowest ad types need:
|
||||
// - watch at least one video ad (video_seen has a row for that day), and
|
||||
// - open at least one inbox (solo) ad that day (solo_inbox.read_ts falls on that day).
|
||||
// Fairness rule: a member whose inbox had NO unread solo ad at the end of a day can't open one,
|
||||
// so for them the video alone counts that day. Nobody is blocked by an empty inbox.
|
||||
//
|
||||
// Why these two: they were the worst-delivering ad types on 2026-09-26 (about 6-7 views per
|
||||
// campaign per day against 40-50 for banners and text), because they only get a view when a
|
||||
// member chooses to open them. The game gives members a reason to.
|
||||
//
|
||||
// This module only COUNTS. PolHunter decides how many of the banked hunts can be used (capped
|
||||
// by how many missions exist) and only on the Friday itself.
|
||||
'use strict';
|
||||
|
||||
let db = null;
|
||||
function init(deps) { db = deps && deps.db; }
|
||||
|
||||
const TZ = 'America/Chicago';
|
||||
const dayOf = ms => new Date(ms).toLocaleDateString('en-CA', { timeZone: TZ });
|
||||
|
||||
// Midnight Central at the START of a 'YYYY-MM-DD' day, as epoch ms. Found by testing the two
|
||||
// possible offsets (CDT -5, CST -6) instead of assuming one, so it stays right across DST.
|
||||
function ctStart(dayKey) {
|
||||
for (const off of [5, 6]) {
|
||||
const t = Date.parse(dayKey + 'T00:00:00Z') + off * 3600000;
|
||||
if (dayOf(t) === dayKey && dayOf(t - 1) !== dayKey) return t;
|
||||
}
|
||||
return Date.parse(dayKey + 'T05:00:00Z');
|
||||
}
|
||||
function addDays(dayKey, n) {
|
||||
const d = new Date(dayKey + 'T12:00:00Z'); d.setUTCDate(d.getUTCDate() + n); return d.toISOString().slice(0, 10);
|
||||
}
|
||||
function weekdayOf(dayKey) { return new Date(dayKey + 'T12:00:00Z').getUTCDay(); } // 0 Sun .. 5 Fri
|
||||
|
||||
// The Friday this week's banking counts toward: today if today is Friday, otherwise the next one.
|
||||
function fridayFor(now) {
|
||||
const today = dayOf(now || Date.now());
|
||||
const wd = weekdayOf(today);
|
||||
return addDays(today, (5 - wd + 7) % 7);
|
||||
}
|
||||
|
||||
// { friday, today, isFriday, window:[Sat..Thu], days:[{day, video, solo, soloNeeded, banked, future}], banked }
|
||||
async function bankFor(email, now) {
|
||||
now = now || Date.now();
|
||||
const e = String(email || '').trim().toLowerCase();
|
||||
const friday = fridayFor(now), today = dayOf(now);
|
||||
const days = []; for (let i = 6; i >= 1; i--) days.push(addDays(friday, -i)); // Sat .. Thu
|
||||
const out = { friday, today, isFriday: today === friday, days: [], banked: 0 };
|
||||
if (!e || !db || !db.enabled()) { out.days = days.map(d => ({ day: d, video: false, solo: false, soloNeeded: true, banked: false, future: d > today })); return out; }
|
||||
|
||||
const winStart = ctStart(days[0]), winEnd = ctStart(friday);
|
||||
const vids = await db.q('SELECT DISTINCT day FROM video_seen WHERE email=? AND day>=? AND day<=?', [e, days[0], days[5]]);
|
||||
const vset = new Set(vids.map(r => String(r.day instanceof Date ? r.day.toISOString().slice(0, 10) : r.day).slice(0, 10)));
|
||||
// every solo row that could matter: delivered before the window closed
|
||||
const solos = await db.q('SELECT delivered, read_ts FROM solo_inbox WHERE email=? AND delivered < ?', [e, winEnd]);
|
||||
|
||||
for (const d of days) {
|
||||
const s = ctStart(d), eod = ctStart(addDays(d, 1));
|
||||
const future = d > today;
|
||||
const video = vset.has(d);
|
||||
const solo = solos.some(r => r.read_ts && Number(r.read_ts) >= s && Number(r.read_ts) < eod);
|
||||
// unread at the end of that day = delivered before end of day and not read by then
|
||||
const unreadAtEnd = solos.some(r => Number(r.delivered) < eod && (!r.read_ts || Number(r.read_ts) >= eod));
|
||||
// for today, "end of day" hasn't happened; they still need to open one if one is waiting now
|
||||
const soloNeeded = d === today ? solos.some(r => Number(r.delivered) <= now && !r.read_ts) || solo : unreadAtEnd || solo;
|
||||
const banked = !future && video && (solo || !soloNeeded);
|
||||
out.days.push({ day: d, video, solo, soloNeeded, banked, future });
|
||||
if (banked) out.banked++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
module.exports = { init, bankFor, fridayFor, ctStart };
|
||||
@@ -2363,6 +2363,7 @@
|
||||
const st = await (await fetch('/api/my/earn')).json();
|
||||
if (st.error) return null;
|
||||
$('earnProgress').textContent = 'today: ' + st.views + ' / ' + st.target + ' ads viewed';
|
||||
loadFridayBank();
|
||||
$('earnBalance').textContent = (st.earnedAvailable != null ? st.earnedAvailable : st.earned) + ' earned credits available' + (st.reserved ? ' · ' + st.reserved + ' in live campaigns' : '');
|
||||
if ($('earnActLink')) $('earnActLink').onclick = e => { e.preventDefault(); jumpTo('campaigns', 'creditActivity'); };
|
||||
const done = st.views >= st.target;
|
||||
@@ -2981,3 +2982,24 @@
|
||||
};
|
||||
btn.addEventListener('click', go); inp.addEventListener('keydown', e => { if (e.key === 'Enter') go(); });
|
||||
})();
|
||||
|
||||
// Friday Bonus Hunts card on the Earn tab (2026-09-26). Hoisted so the Earn loader can call it.
|
||||
async function loadFridayBank() {
|
||||
const card = document.getElementById('fbankCard'); if (!card) return;
|
||||
let b; try { const r = await fetch('/api/my/friday-bank', { credentials: 'same-origin' }); if (!r.ok) return; b = await r.json(); } catch (e) { return; }
|
||||
const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
const wd = d => WD[new Date(d + 'T12:00:00Z').getUTCDay()];
|
||||
document.getElementById('fbankCount').textContent = b.banked + ' banked';
|
||||
document.getElementById('fbankDays').innerHTML = (b.days || []).map(d => {
|
||||
const st = d.banked ? ['#43e8c3', '✓'] : d.future ? ['var(--line-strong)', '·'] : d.day === b.today ? ['#ffb238', '○'] : ['var(--line-strong)', '×'];
|
||||
return '<span title="' + d.day + '" style="display:inline-flex;align-items:center;gap:5px;padding:4px 10px;border-radius:999px;border:1px solid ' + st[0] + ';font-size:13px"><b style="color:' + st[0] + '">' + st[1] + '</b>' + wd(d.day) + '</span>';
|
||||
}).join('') + '<span style="display:inline-flex;align-items:center;padding:4px 10px;border-radius:999px;background:rgba(180,140,255,.18);font-size:13px">Fri: +' + b.banked + ' hunts</span>';
|
||||
const t = (b.days || []).find(d => d.day === b.today);
|
||||
let msg = '';
|
||||
if (b.isFriday) msg = b.banked ? '<b>It\'s Friday.</b> Your ' + b.banked + ' banked hunt' + (b.banked === 1 ? '' : 's') + ' are live on <a href="/api/my/polhunter">PolHunter</a> today.' : 'It\'s Friday. Bank hunts Saturday through Thursday for next Friday.';
|
||||
else if (t && t.banked) msg = '✓ <b>Today is banked.</b> Come back tomorrow to bank another.';
|
||||
else if (t) msg = 'To bank today: ' + (t.video ? '✓ video watched' : '<a href="#" data-earn-go="videos">watch one video</a>') + (t.soloNeeded ? ' and ' + (t.solo ? '✓ inbox ad opened' : '<a href="#" data-earn-go="inbox">open one inbox ad</a>') : ' (no inbox ad waiting, so the video alone counts)') + '.';
|
||||
const el = document.getElementById('fbankToday'); el.innerHTML = msg;
|
||||
el.querySelectorAll('[data-earn-go]').forEach(a => a.addEventListener('click', ev => { ev.preventDefault(); const tab = document.querySelector('[data-earn="' + a.dataset.earnGo + '"]'); if (tab) tab.click(); }));
|
||||
card.hidden = false;
|
||||
}
|
||||
|
||||
+7
-1
@@ -600,6 +600,12 @@
|
||||
<button class="subtab" data-earn="inbox" type="button">Inbox Ads<span class="pill" id="inboxBadge2" hidden></span></button>
|
||||
</div>
|
||||
|
||||
<div class="card" id="fbankCard" hidden style="border-color:rgba(180,140,255,.45)">
|
||||
<h3 style="margin:0 0 4px">🎯 Friday Bonus Hunts <span class="badge" id="fbankCount" style="margin-left:6px">0 banked</span></h3>
|
||||
<p class="small muted" style="margin:0 0 10px" id="fbankLead">Each day, Saturday through Thursday, open one <b>Inbox Ad</b> and watch one <b>video</b> here. Every day you do both banks one extra PolHunter hunt for Friday.</p>
|
||||
<div id="fbankDays" style="display:flex;flex-wrap:wrap;gap:6px"></div>
|
||||
<p class="small" style="margin:10px 0 0" id="fbankToday"></p>
|
||||
</div>
|
||||
<div class="earn-sub" id="earn-watch">
|
||||
<div class="card">
|
||||
<h3>Earn credits by viewing ads</h3>
|
||||
@@ -1073,7 +1079,7 @@
|
||||
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/wallet.js?v=20260911a"></script>
|
||||
<script src="/assets/promo.js?v=20260925a"></script>
|
||||
<script src="/assets/my.js?v=20260925a"></script>
|
||||
<script src="/assets/my.js?v=20260926a"></script>
|
||||
<script src="/assets/chat.js?v=20260907l"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -45,6 +45,7 @@ const leaderboard = require('./leaderboard');
|
||||
const toolkit = require('./toolkit');
|
||||
const badge = require('./badge'); // achievement badge image drawn on the server with ffmpeg (2026-09-16)
|
||||
const friday = require('./friday');
|
||||
const fridaybank = require('./fridaybank'); // Friday Bonus Hunts: days banked Sat-Thu by solo + video (2026-09-26)
|
||||
const refill = require('./refill'); // campaign running-low / ran-out notices, and what came of them // Five Dollar Friday: +20% credits on Friday packs, the wave, the badge (Marty, 2026-09-20)
|
||||
const snapshot = require('./snapshot'); // daily growth snapshot -> Telegram payments feed (Marty, 2026-09-15)
|
||||
const pipeline = require('./pipeline'); // sponsor follow-up board (coming soon until site setting pipelineMode = on) (Marty, 2026-09-15)
|
||||
@@ -471,6 +472,7 @@ async function boot() {
|
||||
snapshot.init({ dataDir: DATA_DIR, db, chain, siteConfig, publicDir: PUBLIC_DIR,
|
||||
send: async (c, t, th) => { await telegramSend(c, t, th); return true; },
|
||||
sendPhoto: (c, jpeg, cap, th) => telegramSendPhoto(c, jpeg, cap, th) });
|
||||
fridaybank.init({ db });
|
||||
friday.init({ dataDir: DATA_DIR, siteConfig, chain, ads, accounts, mailer, drip, marks,
|
||||
telegram: async text => { const sc = siteConfig(); if (!sc.telegramBotToken || !sc.telegramEchoChatId) return false; return telegramSend(sc.telegramEchoChatId, '\u{1F7E0} <b>InstantAdPay</b> \u00b7 ' + text, sc.telegramEchoTopicId); },
|
||||
notify: async (memberId, subject, text, kind) => { const a = await accounts.byMemberId(memberId); if (!a || !a.email) return; const html = '<p>' + String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/(https:\/\/[^\s]+)/g, '<a href="$1" target="_blank" rel="noopener">$1</a>').split('\n\n').join('</p><p>').replace(/\n/g, '<br>') + '</p>'; await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [a.email], subject, html, kind || 'notice'); } });
|
||||
@@ -2316,6 +2318,24 @@ const server = http.createServer(async (req, res) => {
|
||||
earnTokens.delete(s.email); // single use
|
||||
return json(res, 200, await ads.recordView(s.email));
|
||||
}
|
||||
// -- Friday Bonus Hunts (2026-09-26). The member's own progress, for the Earn tab card.
|
||||
if (p === '/api/my/friday-bank' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
return json(res, 200, await fridaybank.bankFor(s.email));
|
||||
}
|
||||
// PolHunter asks, server to server, signed with the same shared secret as the hand-off:
|
||||
// sig = HMAC-SHA256(HUNT_SSO_SECRET, 'fridaybank:' + email + ':' + ts), ts within 5 minutes.
|
||||
if (p === '/api/hunt/friday-bank' && req.method === 'GET') {
|
||||
const secret = String(process.env.HUNT_SSO_SECRET || '').trim();
|
||||
if (secret.length < 32) return json(res, 503, { error: 'not connected' });
|
||||
const q = new URL(req.url, 'http://x').searchParams;
|
||||
const email = String(q.get('email') || '').trim().toLowerCase(), ts = Number(q.get('ts') || 0), sig = String(q.get('sig') || '');
|
||||
if (!email || !ts || Math.abs(Date.now() - ts) > 300000) return json(res, 400, { error: 'stale or missing' });
|
||||
const want = crypto.createHmac('sha256', secret).update('fridaybank:' + email + ':' + ts).digest('hex');
|
||||
if (sig.length !== want.length || !crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want))) return json(res, 401, { error: 'bad signature' });
|
||||
return json(res, 200, await fridaybank.bankFor(email));
|
||||
}
|
||||
// -- PolHunter hand-off (2026-09-19): sign the member across; polhunter.com verifies with the shared secret
|
||||
if (p === '/api/my/polhunter' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
|
||||
Reference in New Issue
Block a user