89b5969b25
- ads.js: a login buy with every slot taken returns full:true and a reserve offer; with reserve:true it is charged the full slot price at once (purchased credits only, credit log 'Login slot reserved (queue #N)') and stored with status 'queued' + queuedAt, no starts/expires, never served or counted as a slot. First paid, first served. - Promotion (promoteLoginQueue): on a slot expiring (scheduleSweep), a member pausing a slot, every new login buy, and a one-minute tick. The oldest reservation becomes active, starts now, ends in 30 days; the owner gets an on-site notice (kind 'notice') and an email unless unsubscribed. - Deploy-overlap safety: the cap decision runs under a lease row in the new app_locks table (one conditional UPDATE takes it, an expired lease can be taken over); every start/cancel/edit is a conditional UPDATE on status='queued', so a reservation starts at most once and a cancel racing a start has exactly one winner. Live login buys and paused-slot resumes also take the lease, so the cap holds for them too. - A freed slot goes to the line first: a paused slot resumes only while live + queued < loginSlotsMax, with a plain message saying the line is ahead. - Cancel before the start: full refund as purchased-grade credits (credit log 'Login slot reservation cancelled: refund'), once. Edit target/image/headline before the start, free. Cancelled reservations can be archived. - Estimated start per place from the live slots' end dates and the reservations ahead, shown in Central time and labelled an estimate. - db.js: campaigns.queued_at BIGINT NULL, app_locks table + 'login_queue' row, all added on boot. - server.js: loginLine in GET /api/my/campaigns, POST /api/my/campaigns/:id/cancel-reservation and /edit-reservation (safe-browsing, reach and image checks), GET /api/admin/login-queue, POST /api/admin/login-queue/:id/cancel, the promotion notice hook and the one-minute tick. - Member UI (my.js, my.html): open slots or the line with place and estimated start on the Login ad form, the button becomes "Reserve the next slot", IAP.confirmBox before paying, In line #N + estimated start in the list, Edit and Cancel and refund. Admin (admin.js, admin.html): Login-ad line card with owner, queued at, place, estimated start, cancel + refund. Tags bumped to 20261023lq. - chatbot.js: new canned 'login-ads' answer and the LOGIN ADS fact updated (6 slots, the paid line, cancel = full refund before start). The knowledge base seeds the new entry on boot. - audit.js: queued/cancelled reservations are not per-day login campaigns. - QA: qa/login-queue.cjs (JSON store end to end) and qa/login-queue-sql.cjs (SQL path guard logic against a fake SQL layer), bash qa/run.sh login-queue. qa/login-slot.mjs pattern follows the refactor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
2.2 KiB
JavaScript
43 lines
2.2 KiB
JavaScript
// Login ads are a flat 30-day slot, not a daily meter.
|
|
//
|
|
// The old model charged 100 credits for every day a campaign was shown, with no end date.
|
|
// That produced 74-day queues, and every new campaign added 100/day of charges while adding
|
|
// no inventory — on 18 Sep, 15 campaigns were charged 1,500 credits against a platform that
|
|
// had produced 367 login impressions in its whole life.
|
|
import { createRequire } from 'node:module';
|
|
const require = createRequire(import.meta.url);
|
|
const ads = require('../ads.js');
|
|
|
|
const ok = [], bad = [];
|
|
const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || !extra ? '' : ' -> ' + extra)); };
|
|
|
|
const r = ads.rates();
|
|
t('a slot price is configured', Number(r.loginSlotCredits) > 0, String(r.loginSlotCredits));
|
|
t('a slot length is configured', Number(r.loginSlotDays) > 0, String(r.loginSlotDays));
|
|
t('the slot is 3,000 credits for 30 days', r.loginSlotCredits === 3000 && r.loginSlotDays === 30,
|
|
r.loginSlotCredits + ' / ' + r.loginSlotDays);
|
|
|
|
// the price matches what 30 days used to cost, so nobody pays more than before
|
|
t('same total as 30 days at the old daily rate',
|
|
r.loginSlotCredits === 30 * r.loginCreditsPerDay,
|
|
r.loginSlotCredits + ' vs ' + (30 * r.loginCreditsPerDay));
|
|
|
|
// the source guarantees that matter, checked directly — these are the behaviours that stop
|
|
// a slot draining against days when the gate produced nothing
|
|
const src = require('fs').readFileSync(new URL('../ads.js', import.meta.url), 'utf8');
|
|
|
|
t('buying a slot charges the whole price up front',
|
|
/Login-ad slot \(/.test(src) && /chargeCredits\(campaign\.id, (v\.)?c\.budget, 'Login-ad slot/.test(src));
|
|
t('a slot gets an end date at purchase',
|
|
/out\.expires = Date\.now\(\) \+ days \* 86400000/.test(src));
|
|
t('the MySQL daily meter skips slot campaigns',
|
|
/expires IS NULL AND \(last_day_charged/.test(src));
|
|
t('the JSON daily meter skips slot campaigns',
|
|
/if \(c\.expires\) continue; \/\/ slot buy/.test(src));
|
|
t('a short budget is refused with the slot price named',
|
|
/A login-ad slot is ' \+ cost \+ ' credits for ' \+ days \+ ' days/.test(src));
|
|
|
|
console.log('PASS ' + ok.length);
|
|
for (const b of bad) console.log('FAIL ' + b);
|
|
process.exit(bad.length ? 1 : 0);
|