Returning members (Marty 2026-11-13): /w/<code> personal links remember each old member's sponsor line (network sponsor first, then the old Downline Banners upline, network usernames, nearest first; welcome.json in MySQL via docstore, loaded with POST /api/admin/welcome). When they open the buy page, the sponsor is the first in that line who has a wallet linked AND already owns a spot (the contract only binds a sponsor who is a member); nobody qualifies -> no sponsor, never the company. Plain ?ref= links are used only without a personal code. Smoke 76/76.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-13 11:13:44 -06:00
parent 093464d11b
commit 76d9bc0b21
+33 -3
View File
@@ -133,6 +133,22 @@ async function resolveRef(raw) {
const m = await netMember({ u: r }); return m ? m.address : null;
}
const sponsorOf = req => { const v = cookies(req)['bl.ref']; return ADDR_RE.test(v || '') ? v.toLowerCase() : null; };
// Returning Downline Banners members (Marty 2026-11-13). welcome.json (a MySQL document) maps each personal code to that member's
// sponsor line, nearest first: their network sponsor, then their old Downline Banners upline, as network usernames. /w/<code>
// keeps the code in a cookie; when the member opens the buy page, the first person in that line who has a wallet linked AND owns
// a spot here at that moment becomes the sponsor (the contract only binds a sponsor who is already a member). Nobody qualifies:
// no sponsor, never the company. A plain ?ref= link is used only when there is no personal code.
const WELCOME = () => { try { return JSON.parse(fs.readFileSync(path.join(C.dataDir, 'welcome.json'), 'utf8')); } catch (e) { return {}; } };
async function lineSponsor(req) {
const code = cookies(req)['bl.wl']; const w = code && /^[a-z0-9]{8,16}$/.test(code) ? WELCOME()[code] : null;
if (!w || !Array.isArray(w.line)) return null;
for (const un of w.line.slice(0, 25)) {
const m = await netMember({ u: un }).catch(() => null);
if (m && m.address && chain.isMember(m.address)) return { address: m.address, username: m.username, via: 'line' };
}
return { address: null, via: 'line' };
}
async function sponsorFor(req) { const l = await lineSponsor(req); if (l) return l.address; return sponsorOf(req); }
// ---- sessions (wallet signature sign-in) ----
const challenges = new Map();
@@ -242,6 +258,12 @@ const server = http.createServer(async (req, res) => {
const name = path.basename(p); if (!/^[a-z0-9-]+\.(png|jpg|gif)$/.test(name)) { res.writeHead(404); return res.end(); }
return sendFile(res, path.join(C.dataDir, 'art', name), { 'Cache-Control': 'public, max-age=86400' });
}
const wm = /^\/w\/([a-z0-9]{8,16})$/.exec(p);
if (wm) {
const ok = !!WELCOME()[wm[1]];
res.writeHead(302, { Location: '/', 'Cache-Control': 'no-store', 'Set-Cookie': ok ? cookie('bl.wl', wm[1], 120 * 86400, false) : cookie('bl.wl', '', 0, false) });
return res.end();
}
// click relay: /go/<spotId | h-key>[?g=<gid>&i=<step>] (gate visits counted apart from organic clicks)
if (/^\/go\/[\w-]+$/.test(p)) {
const ref = p.slice(4); const t = board.target(ref);
@@ -291,7 +313,7 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, { totals: t, index: chain.status(), recent, daily: store.daily() });
}
if (p === '/api/sponsor' && req.method === 'GET') {
const raw = u.searchParams.get('ref'); const a = raw ? await resolveRef(raw) : sponsorOf(req);
const raw = u.searchParams.get('ref'); const a = raw ? await resolveRef(raw) : await sponsorFor(req);
return json(res, 200, { address: a || null, member: a ? chain.isMember(a) : false });
}
@@ -362,9 +384,9 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, { ok: true }, { 'Set-Cookie': [cookie('bl.sid', '', 0, true), networksso.offCookie()] }); // signed out stays signed out here for 12 hours
}
if (p === '/api/me' && req.method === 'GET') {
const s = session(req); if (!s) return json(res, 200, { signedIn: false, sponsor: sponsorOf(req) });
const s = session(req); if (!s) return json(res, 200, { signedIn: false, sponsor: await sponsorFor(req) });
store.touch(s.address);
return json(res, 200, { signedIn: true, address: s.address, member: chain.isMember(s.address), sponsor: sponsorOf(req) });
return json(res, 200, { signedIn: true, address: s.address, member: chain.isMember(s.address), sponsor: await sponsorFor(req) });
}
// -- member API (signed in)
@@ -414,6 +436,14 @@ const server = http.createServer(async (req, res) => {
let b; try { b = JSON.parse(raw || '{}'); } catch (e) { return json(res, 400, { error: 'bad json' }); }
const r = refuelspots.enqueue(b); return json(res, r.error ? 400 : 200, r);
}
if (p === '/api/admin/welcome' && req.method === 'POST') {
const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' });
const raw = (await readRaw(req, 4 * 1024 * 1024)).toString('utf8'); let b; try { b = JSON.parse(raw); } catch (e) { return json(res, 400, { error: 'bad json' }); }
const cur = WELCOME(); let n = 0;
for (const [code, v] of Object.entries(b.codes || {})) { if (!/^[a-z0-9]{8,16}$/.test(code) || !v || !Array.isArray(v.line)) continue; cur[code] = { line: v.line.map(x => String(x).toLowerCase()).slice(0, 25), at: Date.now() }; n++; }
fs.writeFileSync(path.join(C.dataDir, 'welcome.json'), JSON.stringify(cur));
return json(res, 200, { ok: true, added: n, total: Object.keys(cur).length });
}
// -- admin (ADMIN_TOKEN header): keeper preview + index status. No key material is ever returned.
if (p === '/api/admin/status' && req.method === 'GET') {
const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' });