Files
martbost e5fb985c6b Fuel Your Offers member guide at /refuel (Marty, 2026-10-24): LinkSpin-first wording (Credits, Ads, Banner Spin), same rules as InstantAdPay's refuel.js, flow drawn in HTML/CSS (works at 390 px), pub.css look, hero og:image banners/fuel-your-offers-1200x675.jpg, refuel-guide.js opens join/member/off-site links in a new tab (with ?ref) when framed. Route + TRAFFIC_PAGES + sitemap; Training entry (catalog/training.json "refuel-guide"); "How the Refuel streak works" link on the Monthly Refuel panel and in the Engine Room.
Fixes: Engine Room streak line no longer asks for the other site once both are refueled (engine.js + engine-room.js copied from InstantAdPay, byte-identical). Ads-screen Monthly Refuel rows had no spacing ("InstantAdPay+30%"): own flex row style. Load into my Banner Spin: size checkboxes, pre-ticked to what fits the tier (728x90 + 300x250 on an empty Starter), and kitspin.js returns one plain message: what loaded, what did not and why (tier holds N Banner Spins), and what to do; /api/my/kits adds spinRoom. Test added (refuel-kit 6/6).
Chatbot CANNED + refuelFact point to /refuel. fuel.js + engine-room.js ?v=20261024rg.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 08:07:32 -05:00

62 lines
5.2 KiB
JavaScript

// "Load into my Banner Spin" for the Refuel Kit (2026-10-24). Each Banner Spin size in an unlocked kit goes into one of the
// member's Banner Spins of that size that has room, or into a new Banner Spin when the member's tier allows one more.
// The banner is the member's own personalized file (copied into uploads like a normal Banner Spin upload, so health checks,
// moderation and Member content treat it the same), labelled "Refuel Kit <month>", the target their own link.
// Loading the same kit twice does not add it twice.
'use strict';
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
async function load(d) { // { kit, bannerspin, content, uploadsDir, email, month, variant, sizes }
const { kit, bannerspin, email, month } = d;
const mk = await kit.myKits(email); const k = mk.on && mk.kits.find(x => x.month === month);
if (!k) return { error: 'No such kit.' };
if (!k.unlocked) return { error: 'Your next counted refuel unlocks this kit.' };
const t = await bannerspin.tierFor(email); if (!t.ok) return { error: t.reason, status: 403 };
const want = Array.isArray(d.sizes) && d.sizes.length ? d.sizes.map(String) : k.sizes.filter(x => x.ready).map(x => x.size);
const label = 'Refuel Kit ' + month; const results = [];
for (const size of want.filter(z => bannerspin.SIZES[z] && k.sizes.some(x => x.size === z && x.ready))) {
const mine = await bannerspin.list(email);
const has = mine.find(x => x.size === size && x.banners.some(b => b.label === label));
if (has) { results.push({ size, spinId: has.id, spin: has.name, already: true }); continue; }
const r = await kit.renderFor(email, month, size, d.variant === 'gif' && k.gif ? 'gif' : 'still');
if (r.error) { results.push({ size, error: r.error }); continue; }
if (r.bytes > bannerspin.MAX_BYTES) { results.push({ size, error: 'The ' + size + ' file is over 150 KB, so Banner Spin cannot take it. Use the still version.' }); continue; }
let spin = mine.find(x => x.size === size && x.banners.length < t.banners && !x.adminOff), created = false;
if (!spin) { const c = await bannerspin.create(email, { name: 'Refuel Kit ' + size, size, fallback: mk.link || '' }); if (c.error) { results.push(Object.assign({ size, error: c.error }, mine.length >= t.spins ? { full: true } : {})); continue; } spin = c.spin; created = true; }
const name = crypto.randomBytes(12).toString('hex') + '.' + r.ext;
fs.writeFileSync(path.join(d.uploadsDir, name), fs.readFileSync(r.file));
const mime = { png: 'image/png', jpg: 'image/jpeg', gif: 'image/gif' }[r.ext];
try { if (d.content) d.content.noteUpload(name, email, r.bytes, mime, ''); } catch (e) {}
bannerspin.noteImage(email, name, r.w, r.h, r.bytes, mime);
const add = await bannerspin.addBanner(email, spin.id, { image: '/uploads/' + name, target: mk.link, label });
results.push(add.error ? { size, error: add.error } : { size, spinId: spin.id, spin: spin.name, created });
}
return { ok: true, results, message: summary(results, t) };
}
// one plain sentence set for the member (2026-10-24): what loaded, what did not and why, and what to do about it. A Starter
// tier holds 2 Banner Spins, so a full kit loads two sizes; that is the rule, and the message has to say so up front.
const join = a => a.length <= 1 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1];
function summary(results, t) {
const ok = results.filter(x => !x.error), full = results.filter(x => x.error && x.full), bad = results.filter(x => x.error && !x.full);
const out = [];
if (ok.length) out.push('Loaded: ' + join(ok.map(x => x.size + (x.already ? ' (already in "' + x.spin + '")' : x.created ? ' (new Banner Spin "' + x.spin + '")' : ' (added to "' + x.spin + '")'))) + '.');
if (full.length) out.push('Not loaded: ' + join(full.map(x => x.size)) + '. Your ' + t.label + ' tier holds ' + t.spins + ' Banner Spins, one size each, and they are all in use. Nothing is broken: pick the sizes you want most and load those, or delete a Banner Spin under Links to make room.'
+ (t.next ? ' ' + t.next.label + ' (' + t.next.need + ') holds ' + t.next.spins + '.' : ''));
for (const x of bad) out.push(x.size + ': ' + x.error);
if (!results.length) out.push('Pick at least one size to load.');
return out.join(' ');
}
// what the Refuel Kit panel needs to pre-pick sizes: the tier, Banner Spins in use, and the sizes that fit (sizes with a
// Banner Spin that has room first, then new ones in order of use: 728x90, 300x250, 468x60, 160x600)
const PREFER = ['728x90', '300x250', '468x60', '160x600'];
async function room(email, bannerspin) {
const t = await bannerspin.tierFor(email); if (!t.ok) return { ok: false, reason: t.reason };
const mine = await bannerspin.list(email); const sizes = PREFER.filter(z => bannerspin.SIZES[z]);
const fits = sizes.filter(z => mine.some(x => x.size === z && x.banners.length < t.banners && !x.adminOff));
let free = Math.max(0, t.spins - mine.length); const suggested = sizes.filter(z => fits.includes(z) || (free > 0 && free-- > 0));
return { ok: true, tier: t.label, spins: t.spins, used: mine.length, next: t.next, sizes, suggested, all: suggested.length >= sizes.length };
}
module.exports = { load, room, summary };