Prepaid login-ad line: when all member slots are taken, members pay now to reserve the next one (Marty, 2026-10-23: "they need to pay for the slot now to get a place in line")

- 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>
This commit is contained in:
martbost
2026-10-23 07:14:57 -05:00
parent c45f1769e7
commit 89b5969b25
13 changed files with 455 additions and 12 deletions
+6 -1
View File
@@ -232,6 +232,11 @@
</div>
<div class="pane" id="pane-campaigns" hidden>
<div class="card">
<div class="card-head"><h3>Login-ad line</h3><span class="sub" id="lqSub">paid reservations waiting for a slot</span></div>
<p class="small muted" style="margin:0 0 10px">When every member slot is taken, a member can pay now to reserve the next one. The oldest paid reservation starts the moment a slot frees (on expiry, on a pause, and on a one-minute check), before any paused slot can come back. Estimated starts assume every live slot runs its full term. Cancel gives the full price back as purchased credits.</p>
<div class="tablewrap"><table class="adm-table" id="lqTable"></table></div>
</div>
<div class="card">
<div class="card-head"><h3>All campaigns</h3><span class="sub" id="campSub">newest first</span></div>
<p style="margin:0 0 10px"><input id="campFilter" placeholder="Filter by owner, name, type or status" style="width:100%"></p>
@@ -606,6 +611,6 @@
<script src="/assets/common.js?v=20261016n"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/admin-kb.js?v=20261020kb"></script>
<script src="/assets/admin.js?v=20261022gpk"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script>
<script src="/assets/admin.js?v=20261023lq"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script>
</body>
</html>
+21
View File
@@ -256,10 +256,31 @@
// ── all campaigns ──
let allCamps = [];
async function loadCampaigns() {
loadLoginLine().catch(e => IAP.status(e.message, 'bad'));
const r = await api('/api/admin/campaigns');
allCamps = r.campaigns || [];
drawCamps();
}
// prepaid login-ad line (2026-10-23): paid reservations waiting for a slot, oldest paid first. Dates in Central time.
const lqWhen = ts => ts ? esc(ctWhen(ts)) : '<span class="muted">unknown</span>'; // ctWhen (below) prints Central time
async function loadLoginLine() {
const d = await api('/api/admin/login-queue');
$('lqSub').textContent = d.used + ' of ' + d.max + ' member slots live · ' + d.queued + ' paid reservation' + (d.queued === 1 ? '' : 's') + ' in line · ' + d.free + ' open';
$('lqTable').innerHTML = '<tr><th>Place</th><th>ID</th><th>Owner</th><th>Campaign</th><th>Paid</th><th>Queued at</th><th>Estimated start</th><th></th></tr>'
+ (d.queue.length ? d.queue.map(c => '<tr><td><b>#' + c.place + '</b></td><td>#' + c.id + '</td><td><span class="trunc" title="' + esc(c.owner) + '">' + esc(c.owner) + '</span></td>'
+ '<td>' + esc(c.name) + '<div><a class="small trunc" href="' + esc(c.targetUrl) + '" target="_blank" rel="noopener">' + esc(c.targetUrl) + '</a></div></td>'
+ '<td class="mono small">' + Number(c.paid || 0).toLocaleString() + '</td><td class="small muted">' + lqWhen(c.queuedAt) + '</td><td class="small">' + lqWhen(c.estStart) + '</td>'
+ '<td class="act"><button class="btn small sec" data-lqcancel="' + c.id + '" data-lqowner="' + esc(c.owner) + '" data-lqpaid="' + Number(c.paid || 0) + '">Cancel + refund</button></td></tr>').join('')
: '<tr><td colspan="8" class="muted">Nobody is waiting. When every slot is taken, members can pay now to reserve the next one.</td></tr>');
}
document.addEventListener('click', async e => {
const b = e.target.closest('[data-lqcancel]'); if (!b) return;
const ok = await IAP.confirmBox('Cancel reservation #' + b.dataset.lqcancel + ' for ' + b.dataset.lqowner + '? The full ' + Number(b.dataset.lqpaid || 0).toLocaleString() + ' credits go back to them as purchased credits, and everyone behind moves up one place.', { title: 'Cancel and refund', ok: 'Cancel and refund', cancel: 'Keep it' });
if (!ok) return;
b.disabled = true;
try { const r = await api('/api/admin/login-queue/' + b.dataset.lqcancel + '/cancel', {}); IAP.status('Reservation #' + r.id + ' cancelled, ' + Number(r.refunded || 0).toLocaleString() + ' credits refunded.', 'ok'); await loadCampaigns(); }
catch (err) { IAP.status(err.message, 'bad'); b.disabled = false; }
});
function drawCamps() {
const q = ($('campFilter').value || '').trim().toLowerCase();
const list = allCamps.filter(c => !q || [c.owner, c.name, c.type, c.status, c.targetUrl, String(c.id)].join(' ').toLowerCase().includes(q));
+68 -6
View File
@@ -1068,6 +1068,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
const r = await (await fetch('/api/my/campaigns')).json();
if (r.error) return;
lastRates = r.rates;
lastLoginLine = r.loginLine || null; loginLineHint();
if ($('cGeoHint') && r.tiers) $('cGeoHint').textContent = 'All three ticked = everyone. Tier 1: ' + r.tiers.t1.join(', ') + '. Tier 2: ' + r.tiers.t2.join(', ') + '. Tier 3: every other country. Geo applies to delivery on this site; a narrowed banner or text ad is kept off the worldwide partner network. ' + (r.geoReady ? '' : 'Country data is still loading, so narrowed campaigns pause until it is ready. ') + 'IP geolocation by DB-IP.';
// populate the banner-size dropdown once (ids map to NAS width/height)
if (r.bannerSizes && $('cSize') && !$('cSize').options.length)
@@ -1107,10 +1108,11 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
+ (((r.doorStats && r.doorStats[c.id]) || c.placement === 'golden' || c.placement === 'doors') ? (ds => '<div class="muted small" title="Spooky Doors: every door opened on this pack, and how many different players opened one">\u{1F383} ' + ds.doors.toLocaleString() + ' door' + (ds.doors === 1 ? '' : 's') + ' opened \u00b7 ' + ds.players.toLocaleString() + ' player' + (ds.players === 1 ? '' : 's') + '</div>')((r.doorStats && r.doorStats[c.id]) || { doors: 0, players: 0 }) : '') + '</td>'
: c.type === 'featured' ? '<td class="num" data-l="Spent"><span class="muted small" title="featured runs are paid in full when booked (' + (r.rates.featuredPerDay || 40) + ' credits a day); nothing more is charged while the run is live">paid up front</span></td><td class="num" data-l="Run">' + featRun(c) + '</td>'
: '<td class="num" data-l="Spent">' + c.spent + '</td><td class="num" data-l="Budget">' + c.budget + '</td>')
+ '<td data-l="Status">' + (c.status === 'out' ? (c.type === 'visits' ? '<span class="badge">pack delivered</span>' : '<span class="badge amber">budget spent</span>') : c.status === 'done' ? '<span class="muted">' + (c.type === 'featured' ? 'run ended' : 'ended') + '</span>' : c.scheduled ? '<span class="badge">scheduled</span>' : c.status) + '</td>'
+ '<td data-l="Status">' + (c.status === 'queued' ? queuedCell(c) : c.status === 'cancelled' ? '<span class="muted" title="cancelled before it started; the full price came back to your balance">cancelled, refunded</span>' : c.status === 'out' ? (c.type === 'visits' ? '<span class="badge">pack delivered</span>' : '<span class="badge amber">budget spent</span>') : c.status === 'done' ? '<span class="muted">' + (c.type === 'featured' ? 'run ended' : 'ended') + '</span>' : c.scheduled ? '<span class="badge">scheduled</span>' : c.status) + '</td>'
+ '<td class="act">' + (c.status === 'active' ? '<button class="btn small sec" data-camp="' + c.id + '" data-act="pause">Pause</button>'
: c.status === 'paused' ? '<button class="btn small sec" data-camp="' + c.id + '" data-act="resume">Resume</button>' : '')
+ (['paused', 'out', 'done'].includes(c.status) ? ' <button class="btn small quiet" data-arch="' + c.id + '" data-archname="' + esc(c.name || ('#' + c.id)) + '" data-archleft="' + Math.max(0, (c.budget || 0) - (c.spent || 0)) + '" title="move it out of this list, keep its numbers">Archive</button>' : '')
: c.status === 'paused' ? '<button class="btn small sec" data-camp="' + c.id + '" data-act="resume">Resume</button>'
: c.status === 'queued' ? '<button class="btn small sec" data-qedit="' + c.id + '">Edit</button> <button class="btn small quiet" data-qcancel="' + c.id + '" data-qname="' + esc(c.name || ('#' + c.id)) + '" data-qpaid="' + Number(c.spent || 0) + '">Cancel and refund</button>' : '')
+ (['paused', 'out', 'done', 'cancelled'].includes(c.status) ? ' <button class="btn small quiet" data-arch="' + c.id + '" data-archname="' + esc(c.name || ('#' + c.id)) + '" data-archleft="' + Math.max(0, (c.budget || 0) - (c.spent || 0)) + '" title="move it out of this list, keep its numbers">Archive</button>' : '')
+ (c.type === 'featured' ? ' <button class="btn small sec" data-extend="' + c.id + '" title="book more days at the daily rate">Extend run</button>'
: c.type === 'visits' ? ' <button class="btn small sec" data-morevisits="' + c.id + '" data-vper="' + placeCost(c.doorOnly ? c.placement : 'all', r.rates) + '" data-vdoor="' + (c.doorOnly ? (c.placement === 'golden' ? 'golden' : 'doors') : '') + '">' + (c.doorOnly ? 'Buy more doors' : 'Buy more visits') + '</button>'
: c.type === 'login' ? '' // a login slot is a flat 30-day buy: nothing to top up
@@ -1142,6 +1144,27 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
await loadCampaigns(); loadDashboard();
} catch (e) { IAP.status(e.message, 'bad'); }
}));
// prepaid login-ad line (2026-10-23): a reservation can be edited for free and cancelled for the full price back until it starts
el.querySelectorAll('button[data-qcancel]').forEach(b => b.addEventListener('click', async () => {
const paid = Number(b.dataset.qpaid) || 0;
const ok = await IAP.confirmBox('You give up your place in line and the full ' + paid.toLocaleString() + ' credits come back to your balance right away, as purchased credits. You can reserve again later, at the back of the line.',
{ title: 'Cancel ' + b.dataset.qname + '?', ok: 'Cancel and refund', cancel: 'Keep my place' });
if (!ok) return;
b.disabled = true;
try { const x = await api('/api/my/campaigns/' + b.dataset.qcancel + '/cancel-reservation'); IAP.status('Reservation cancelled. ' + Number(x.refunded || 0).toLocaleString() + ' credits are back in your balance.', 'ok'); await loadCampaigns(); loadDashboard(); }
catch (e) { IAP.status(e.message, 'bad'); b.disabled = false; await loadCampaigns(); }
}));
el.querySelectorAll('button[data-qedit]').forEach(b => b.addEventListener('click', async () => {
const c = r.campaigns.find(x => x.id === Number(b.dataset.qedit)); if (!c) return;
const target = await IAP.ask({ title: 'Edit your reserved login ad', text: 'Target URL: the page members see when they sign in. Editing is free until the ad starts.', value: c.targetUrl || '', placeholder: 'https://', ok: 'Next' });
if (target === null) return;
const image = await IAP.ask({ title: 'Image (optional)', text: 'A direct image link (.png or .jpg) shown as the clickable creative. Leave it empty for a plain link card.', value: c.imageUrl || '', placeholder: 'https://', ok: 'Next' });
if (image === null) return;
const title = await IAP.ask({ title: 'Headline (optional)', text: 'Shown on the link card when there is no image. Up to 60 characters.', value: c.title || '', placeholder: 'Visit today\'s sponsor', ok: 'Save changes' });
if (title === null) return;
try { await api('/api/my/campaigns/' + c.id + '/edit-reservation', { targetUrl: target.trim(), imageUrl: image.trim(), title: title.trim() }); IAP.status('Saved. Your place in line is unchanged.', 'ok'); await loadCampaigns(); }
catch (e) { IAP.status(e.message, 'bad'); }
}));
el.querySelectorAll('button[data-camp]').forEach(b => b.addEventListener('click', async () => {
try { await api('/api/my/campaigns/' + b.dataset.camp + '/' + b.dataset.act); await loadCampaigns(); }
catch (e) { IAP.status(e.message, 'bad'); }
@@ -1178,6 +1201,28 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
} catch (e) {}
}
let lastRates = null;
let lastLoginLine = null; // { max, used, queued, free, credits, days, nextPlace, nextEstStart, mine: [{ id, place, estStart }] }
// every date about the login-ad line is shown in Central time, Marty's clock
function ctWhen(ts) { return new Date(ts).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' Central'; }
function queuedCell(c) {
const m = lastLoginLine && (lastLoginLine.mine || []).find(x => x.id === c.id);
return '<span class="badge amber" title="paid in full; it starts on its own when a slot frees">In line' + (m ? ' #' + m.place : '') + '</span>'
+ '<div class="muted small">' + (m && m.estStart ? 'Estimated start ' + esc(ctWhen(m.estStart)) : 'Start date not known yet') + '</div>';
}
// the Login ad form: open slots, or the paid line with this buyer's place and estimated start
function loginLineHint() {
const el = $('cLoginLine'); const isLogin = $('cType') && $('cType').value === 'login';
if (el) el.hidden = !isLogin || !lastLoginLine;
if ($('createCampBtn')) $('createCampBtn').textContent = isLogin && lastLoginLine && !lastLoginLine.free ? 'Reserve the next slot' : 'Launch campaign';
if (!el || !isLogin || !lastLoginLine) return;
const L = lastLoginLine;
el.textContent = L.free
? L.free + ' of ' + L.max + ' login-ad slots open now. Yours goes live the moment you launch: ' + Number(L.credits).toLocaleString() + ' purchased credits for ' + L.days + ' days.'
: 'All ' + L.max + ' login-ad slots are taken' + (L.queued ? ' and ' + L.queued + ' paid ' + (L.queued === 1 ? 'reservation is' : 'reservations are') + ' in line' : '') + '. You can reserve the next slot: you pay the same '
+ Number(L.credits).toLocaleString() + ' purchased credits now and take place #' + L.nextPlace + ' in line. Your ' + L.days + ' days start when your turn comes, not before.'
+ (L.nextEstStart ? ' Estimated start: ' + ctWhen(L.nextEstStart) + '. That is an estimate: a slot can end early if its owner archives it, which moves the line forward.' : '')
+ ' Until it starts you can edit it for free, or cancel it for every credit back.';
}
function soloHint() {
if (!lastRates || $('cType').value !== 'solo') return;
const cost = lastRates.soloCostPerRecipient || 5;
@@ -1241,6 +1286,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
// runs on every type change AND once at load, so the default type (banner) shows its size + image rows immediately
function applyType() { // hoisted: loadCampaigns may run before this line is reached
whereHint();
loginLineHint();
const t = $('cType').value;
$('cImageRow').hidden = t !== 'banner'; // only banners carry a creative; login frames its URL
if ($('cImageHint')) $('cImageHint').hidden = t !== 'banner';
@@ -1360,7 +1406,14 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
const t = $('cType').value;
const isVideo = t === 'video', isFeat = t === 'featured';
if (isVideo && !cVidDims && $('cVideoUrl').value) cVidDims = await probeVideoDims($('cVideoUrl').value);
await api('/api/my/campaigns', { type: t, name: $('cName').value,
// login ad with every slot taken: pay now for a place in line (Marty, 2026-10-23), after one plain confirmation
const confirmReserve = async (place, est) => IAP.confirmBox('Every login-ad slot is taken right now. Reserving charges the full ' + Number((lastLoginLine && lastLoginLine.credits) || (lastRates && lastRates.loginSlotCredits) || 0).toLocaleString()
+ ' purchased credits now and puts you at place #' + place + ' in line. Your ad starts on its own when a slot frees, and runs its full ' + ((lastLoginLine && lastLoginLine.days) || 30) + ' days from then.'
+ (est ? '\n\nEstimated start: ' + ctWhen(est) + '. That is an estimate: a slot can end early if its owner archives it.' : '')
+ '\n\nUntil it starts you can edit it for free, or cancel it and get every credit back.', { title: 'Reserve the next login-ad slot?', ok: 'Pay now and reserve', cancel: 'Not now' });
let reserve = false;
if (t === 'login' && lastLoginLine && !lastLoginLine.free) { if (!(await confirmReserve(lastLoginLine.nextPlace, lastLoginLine.nextEstStart))) return; reserve = true; }
const sendCamp = extra => api('/api/my/campaigns', Object.assign({ type: t, name: $('cName').value,
targetUrl: $('cTarget').value, imageUrl: $('cImage').value, size: $('cSize').value,
title: isVideo ? $('cVideoTitle').value : isFeat ? $('cFeatTitle').value : t === 'visits' ? $('cVisitTitle').value : $('cTitle').value,
body: t === 'solo' ? soloBody : $('cBody').value,
@@ -1373,9 +1426,18 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
startsAt: ($('cStartAt') && $('cStartAt').value && !isFeat) ? new Date($('cStartAt').value).getTime() : 0,
endsAt: ($('cEndAt') && $('cEndAt').value && !isFeat) ? new Date($('cEndAt').value).getTime() : 0,
ctaLabel: isVideo ? $('cVideoCta').value : $('cCtaLabel').value,
budget: isFeat ? (Number($('cFeatDays').value) * (lastRates.featuredPerDay || 40)) : t === 'visits' ? (Number($('cVisitCount').value) * placeCost(visitPlace())) : Number($('cBudget').value) });
budget: isFeat ? (Number($('cFeatDays').value) * (lastRates.featuredPerDay || 40)) : t === 'visits' ? (Number($('cVisitCount').value) * placeCost(visitPlace())) : Number($('cBudget').value) }, extra || {}));
let res;
try { res = await sendCamp({ reserve }); }
catch (e) { // the last slot went while the form was open: offer the line instead of a dead end
if (!(t === 'login' && e.data && e.data.full)) throw e;
if (!(await confirmReserve(e.data.place, e.data.estStart))) { await loadCampaigns(); return; }
res = await sendCamp({ reserve: true });
}
const schedStart = ($('cStartAt') && $('cStartAt').value && !isFeat) ? new Date($('cStartAt').value) : null;
IAP.status(schedStart && schedStart.getTime() > Date.now() ? 'Campaign saved. It starts serving ' + schedStart.toLocaleString([], { dateStyle: 'medium', timeStyle: 'short' }) + '.' : 'Campaign is live. It starts serving right away.', 'ok');
if (res && res.queued) IAP.status('Reserved and paid. You are #' + res.place + ' in line' + (res.estStart ? ', estimated start ' + ctWhen(res.estStart) : '') + '. We will tell you on site and by email the moment it goes live.', 'ok');
else if (t === 'login' && reserve) IAP.status('A slot opened up while you were deciding, so your login ad is live now.', 'ok');
else IAP.status(schedStart && schedStart.getTime() > Date.now() ? 'Campaign saved. It starts serving ' + schedStart.toLocaleString([], { dateStyle: 'medium', timeStyle: 'short' }) + '.' : 'Campaign is live. It starts serving right away.', 'ok');
// clear EVERY field so no target/creative carries into the next campaign
['cName', 'cBudget', 'cTarget', 'cImage', 'cTitle', 'cBody', 'cCtaLabel',
'cVideoUrl', 'cVideoTitle', 'cVideoCta', 'cVisitTitle', 'cVisitCount', 'cFeatTitle', 'cDailyCap', 'cStartAt', 'cEndAt']
+2 -1
View File
@@ -528,6 +528,7 @@
<option value="visits">Verified visits (guaranteed unique)</option>
</select></p>
<p class="small muted" id="cWhere" style="margin:-4px 0 10px"></p>
<p class="small" id="cLoginLine" hidden style="grid-column:1/-1;margin:-4px 0 10px"></p>
<p><input id="cName" placeholder="Campaign name" style="width:100%"></p>
<p id="cBudgetRow"><input id="cBudget" type="number" placeholder="Budget (credits)" min="10" style="width:100%"></p>
<p id="cCapRow" style="grid-column:1/-1"><input id="cDailyCap" type="number" placeholder="Daily cap in credits (optional) — paces the budget across days" min="10" style="width:100%">
@@ -1188,7 +1189,7 @@
<script src="/assets/wallet.js?v=20260911a"></script>
<script src="/assets/promo.js?v=20261016p"></script>
<script src="/assets/support.js?v=20261016a"></script>
<script src="/assets/my.js?v=20261022gpw"></script>
<script src="/assets/my.js?v=20261023lq"></script>
<script src="/assets/chat.js?v=20261016n"></script>
</body>
</html>