Refill notices on LinkSpin (Fuel Your Offers stage 1, Marty approved 2026-10-24): refill.js copied from InstantAdPay. Low (80% of budget delivered, refillLowPct), out, and idle (7 days after an unanswered out notice, 100+ credits free, nothing running): one email + one on-site notice per owner per pass, naming each ad and what it delivered, then the relaunch line (100+ credits free) or the /credits link, then the packages from the chain catalog and a streak-line hook for stage 2. Email skips drip unsubscribes and carries the unsubscribe link; the notice (kind notice) always goes. Every send is watched 45 days for purchase / relaunch / resumed / topup. marks.js: one-time claims shared by both app copies during a deploy (event_marks with a DB, exclusive file create on the shared volume without one); every send is claimed first. Settings refillNotices '1' (default on) + refillLowPct 80; admin GET /api/admin/refill, POST /run and /reset, an Overview card (admin-refill.js). qa/refill.test.cjs (12 checks incl. two app copies on one volume) + run.sh fuel mode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Admin > Overview > Refill notices (2026-10-24): who was told their ads ran low, ran out or sat idle, and what they did next.
|
||||
(function () {
|
||||
const $ = id => document.getElementById(id);
|
||||
if (!$('rfBox')) return;
|
||||
const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
||||
const ct = ts => new Date(Number(ts)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT';
|
||||
const STATE = { low: 'running low', out: 'out of credits', idle: 'idle a week' };
|
||||
async function load() {
|
||||
try {
|
||||
const r = await (await fetch('/api/admin/refill', { cache: 'no-store' })).json();
|
||||
if (r.error) throw new Error(r.error);
|
||||
const t = r.totals || {};
|
||||
$('rfSub').textContent = (r.enabled ? 'on' : 'OFF (site setting refillNotices)') + ', low at ' + r.lowPct + '% delivered';
|
||||
const st = Object.entries(r.byState || {}).map(([k, v]) => esc(STATE[k] || k) + ': ' + v.sent + ' sent, ' + v.converted + ' acted').join(' · ');
|
||||
const kinds = Object.entries(r.byKind || {}).map(([k, v]) => esc(k) + ' ' + v).join(', ');
|
||||
$('rfBox').innerHTML = '<p class="small" style="margin:0 0 8px"><b>' + (t.sent || 0) + '</b> sent (' + (t.emailed || 0) + ' emailed), <b>' + (t.converted || 0) + '</b> acted on it (' + (t.ratePct || 0) + '%)'
|
||||
+ (t.purchasesUsd ? ', $' + t.purchasesUsd + ' in packages after a notice' : '') + (t.medianHours != null ? ', median ' + t.medianHours + ' h' : '') + '</p>'
|
||||
+ '<p class="small muted" style="margin:0 0 8px">' + st + (kinds ? '<br>' + kinds : '') + '</p>'
|
||||
+ ((r.recent || []).length ? '<div class="tbl-wrap"><table class="tbl small"><tr><th>When</th><th>Owner</th><th>State</th><th>Ads</th><th>Credits then</th><th>Next</th></tr>'
|
||||
+ r.recent.slice(0, 20).map(x => '<tr><td>' + esc(ct(x.at)) + '</td><td>' + esc(x.owner) + '</td><td>' + esc(STATE[x.state] || x.state) + (x.emailed ? '' : ' <span class="muted">(on-site only)</span>') + '</td><td>' + esc((x.names || []).join(', ')) + '</td><td>' + Number(x.credits || 0).toLocaleString() + '</td><td>' + (x.converted ? esc(x.converted.kind) + ' after ' + x.converted.hours + ' h' : '<span class="muted">nothing yet</span>') + '</td></tr>').join('') + '</table></div>' : '<p class="small muted">Nothing sent yet.</p>');
|
||||
} catch (e) { $('rfBox').textContent = 'Could not load: ' + e.message; }
|
||||
}
|
||||
$('rfRun') && $('rfRun').addEventListener('click', async () => {
|
||||
$('rfRun').disabled = true;
|
||||
try { const r = await (await fetch('/api/admin/refill/run', { method: 'POST', cache: 'no-store' })).json(); $('rfSub').textContent = 'pass done: ' + (r.sent || 0) + ' sent'; } catch (e) {}
|
||||
$('rfRun').disabled = false; load();
|
||||
});
|
||||
load();
|
||||
})();
|
||||
Reference in New Issue
Block a user