Returning-member results (2026-11-13): /w/<code> opens counted per code (welcome-visits.json, MySQL document), GET /api/admin/welcome-stats: codes opened, total opens, new members since the first open with their sponsors
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -262,6 +262,10 @@ const server = http.createServer(async (req, res) => {
|
|||||||
const wm = /^\/w\/([a-z0-9]{8,16})$/.exec(p);
|
const wm = /^\/w\/([a-z0-9]{8,16})$/.exec(p);
|
||||||
if (wm) {
|
if (wm) {
|
||||||
const ok = !!WELCOME()[wm[1]];
|
const ok = !!WELCOME()[wm[1]];
|
||||||
|
if (ok && !isBot(req)) { // returning-member link opens (2026-11-13): how many come back from the email, per code, first + last time
|
||||||
|
const VF = path.join(C.dataDir, 'welcome-visits.json'); let v = {}; try { v = JSON.parse(fs.readFileSync(VF, 'utf8')); } catch (e) {}
|
||||||
|
const r = v[wm[1]] || { n: 0, first: Date.now() }; r.n++; r.last = Date.now(); v[wm[1]] = r; try { fs.writeFileSync(VF, JSON.stringify(v)); } catch (e) {}
|
||||||
|
}
|
||||||
res.writeHead(302, { Location: '/', 'Cache-Control': 'no-store', 'Set-Cookie': ok ? cookie('bl.wl', wm[1], 120 * 86400, false) : cookie('bl.wl', '', 0, false) });
|
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();
|
return res.end();
|
||||||
}
|
}
|
||||||
@@ -445,6 +449,16 @@ const server = http.createServer(async (req, res) => {
|
|||||||
fs.writeFileSync(path.join(C.dataDir, 'welcome.json'), JSON.stringify(cur));
|
fs.writeFileSync(path.join(C.dataDir, 'welcome.json'), JSON.stringify(cur));
|
||||||
return json(res, 200, { ok: true, added: n, total: Object.keys(cur).length });
|
return json(res, 200, { ok: true, added: n, total: Object.keys(cur).length });
|
||||||
}
|
}
|
||||||
|
// returning-member results: personal links opened, and how many of those visitors went on to buy (matched by the wallet that
|
||||||
|
// signed in on the same browser is not tracked; this counts link opens and new members since the first open)
|
||||||
|
if (p === '/api/admin/welcome-stats' && req.method === 'GET') {
|
||||||
|
const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' });
|
||||||
|
let v = {}; try { v = JSON.parse(fs.readFileSync(path.join(C.dataDir, 'welcome-visits.json'), 'utf8')); } catch (e) {}
|
||||||
|
const codes = Object.keys(v); const opens = codes.reduce((t, k) => t + v[k].n, 0); const since = codes.length ? Math.min(...codes.map(k => v[k].first)) : Date.now();
|
||||||
|
const newMembers = chain.allMembers().filter(m => m.joinedAt >= since);
|
||||||
|
return json(res, 200, { codesOpened: codes.length, opens, firstOpen: codes.length ? since : null, newMembersSince: newMembers.length,
|
||||||
|
newMembers: newMembers.map(m => ({ address: m.address, sponsor: m.sponsor, joinedAt: m.joinedAt })) });
|
||||||
|
}
|
||||||
// -- admin (ADMIN_TOKEN header): keeper preview + index status. No key material is ever returned.
|
// -- admin (ADMIN_TOKEN header): keeper preview + index status. No key material is ever returned.
|
||||||
if (p === '/api/admin/status' && req.method === 'GET') {
|
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' });
|
const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' });
|
||||||
|
|||||||
Reference in New Issue
Block a user