From 33a6710909b8599c1177f389143492a943f42a89 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 3 Nov 2026 06:26:42 -0600 Subject: [PATCH] Admin: POST /api/admin/rotations makes tracked spin links on a member's account (one rotation per link, optional traffic source), for the standalone games page and partner placements (Marty 2026-11-03) Co-Authored-By: Claude Fable 5.1 --- server.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server.js b/server.js index e1ab985..2907ab2 100644 --- a/server.js +++ b/server.js @@ -2209,6 +2209,26 @@ const server = http.createServer(async (req, res) => { if (!a) return json(res, 404, { error: 'No member matches "' + q.slice(0, 60) + '".' }); return json(res, 200, await adminMember.view(a.email)); } + // admin-made tracked links for a member (2026-11-03, Marty: a standalone copy of the games page needs LinkSpin tracking + // on every outbound link, built while he was away from his sign-in). POST { email, sourceId? | source?: { name, site }, + // links: [{ name, url, label }] } -> one rotation per link on that member's account, one destination each, attached to the + // source when one is given or created. The same route serves partner placements later (one spin link per site). + if (p === '/api/admin/rotations' && req.method === 'POST') { + if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); + const b = await readBody(req); const a = await adminMember.resolve(String(b.email || '')); + if (!a) return json(res, 404, { error: 'No member matches that email.' }); + const host = String(siteConfig().linkDomains || '').split(',').map(x => x.trim().toLowerCase()).filter(h => h && !h.startsWith('www.'))[0] || SITE_HOST; + let sourceId = String(b.sourceId || '').trim(); + if (!sourceId && b.source && b.source.name) { const s = await sources.create(a.email, { template: 'custom', name: String(b.source.name), site: String(b.source.site || '') }); if (s.error) return json(res, 400, { error: 'source: ' + s.error }); sourceId = s.source.id; } + const out = []; + for (const l of (Array.isArray(b.links) ? b.links : []).slice(0, 25)) { + const c = await rotator.create(a.email, { name: String(l.name || ''), fallback: String(l.url || '') }); if (c.error) { out.push({ name: l.name, error: c.error }); continue; } + const d = await rotator.addDest(a.email, c.rotation.id, { url: String(l.url || ''), label: String(l.label || ''), weight: 1 }); if (d.error) { out.push({ name: l.name, error: d.error }); continue; } + if (sourceId) { const up = await rotator.update(a.email, c.rotation.id, { sourceId }); if (up && up.error) out.push({ name: l.name, warn: 'source not attached: ' + up.error }); } + out.push({ name: l.name, id: c.rotation.id, code: c.rotation.code, url: 'https://' + host + '/r/' + c.rotation.code, to: l.url }); + } + return json(res, 200, { ok: true, email: a.email, sourceId: sourceId || null, links: out }); + } if (p === '/api/admin/member' && req.method === 'PATCH') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req);