diff --git a/ads.js b/ads.js index a3ae034..2caa946 100644 Binary files a/ads.js and b/ads.js differ diff --git a/audit.js b/audit.js index 597c6d8..a1aafb6 100644 --- a/audit.js +++ b/audit.js @@ -12,7 +12,7 @@ function refunded() { const out = {}; try { for (const f of fs.readdirSync(R.dat async function run() { const out = { checkedAt: Date.now(), checks: [] }; if (!db.enabled()) { out.checks.push({ name: 'Counters', ok: true, detail: 'JSON mode: not checked', issues: [] }); return out; } - const camps = await db.q("SELECT id, name, type, status, imps, clicks, spent, accrued, budget, created, house FROM campaigns WHERE house=0 OR house IS NULL"); + const camps = await db.q("SELECT id, name, type, status, imps, clicks, spent, accrued, budget, created, starts, house FROM campaigns WHERE house=0 OR house IS NULL"); const back = refunded(); for (const c of camps) if (back[c.id]) c.spent = Math.max(0, Number(c.spent) - back[c.id]); // already made right const logStart = (await db.q('SELECT MIN(day) d FROM camp_hours'))[0].d; const logStartMs = logStart ? Date.parse(logStart + 'T00:00:00Z') : 0; const byType = t => camps.filter(c => c.type === t); @@ -42,13 +42,18 @@ async function run() { // 4. featured: a live booking older than two hours must have views { const issues = []; const now = Date.now(); - for (const c of byType('featured').filter(c => c.status === 'active' && now - Number(c.created) > 2 * 3600e3)) if (!Number(c.imps)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ': live with 0 views'); + // counted from when the booking STARTS: a paid booking scheduled for later has no views yet by design + // (#275 was flagged on 2026-09-27 hours before its 7 PM start) + for (const c of byType('featured').filter(c => c.status === 'active' && now - Math.max(Number(c.created), Number(c.starts) || 0) > 2 * 3600e3)) if (!Number(c.imps)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ': live with 0 views'); add('featured: live bookings have views', issues, byType('featured').filter(c => c.status === 'active').length + ' live bookings'); } // 5. clicks can only exceed views where a click precedes the counted view (visits, login) { const issues = []; - for (const c of camps.filter(c => !['visits', 'login'].includes(c.type) && Number(c.clicks) > Number(c.imps) + 5)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ' (' + c.type + '): ' + c.clicks + ' clicks vs ' + c.imps + ' views'); + // only where the buyer was charged: this check protects buyers, and a campaign that never spent a credit + // cannot have overcharged anyone (#146: a placeholder video that never played, paused by the source + // sweep, clicks on its button while the player failed, 0 credits spent) + for (const c of camps.filter(c => !['visits', 'login'].includes(c.type) && Number(c.spent) + Number(c.accrued || 0) > 0 && Number(c.clicks) > Number(c.imps) + 5)) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ' (' + c.type + '): ' + c.clicks + ' clicks vs ' + c.imps + ' views'); add('clicks vs views', issues, 'campaigns with more clicks than views, where that cannot happen'); } // 6. budgets: spent can never pass budget