Admin spin links for the BTC4Hits import: POST /api/admin/rotations takes several destinations per link (urls[], fallback), GET lists a member's links + sources, DELETE removes one; tank waiting list reads every account (was the newest 2000)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2249,12 +2249,25 @@ const server = http.createServer(async (req, res) => {
|
||||
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; }
|
||||
// several destinations (2026-11-11, BTC4Hits rotators): l.urls = [{ url, label }] at equal weight, up to the rotator's own cap of 25
|
||||
const list = Array.isArray(l.urls) && l.urls.length ? l.urls.map(x => typeof x === 'string' ? { url: x } : x) : [{ url: l.url, label: l.label }];
|
||||
if (l.fallback) await rotator.update(a.email, c.rotation.id, { fallback: String(l.fallback) });
|
||||
let added = 0; const destErrors = []; for (const x of list) { const d = await rotator.addDest(a.email, c.rotation.id, { url: String(x.url || ''), label: String(x.label || ''), weight: 1 }); if (d.error) destErrors.push({ url: String(x.url || '').slice(0, 120), error: d.error }); else added++; }
|
||||
if (!added) { await rotator.remove(a.email, c.rotation.id); out.push({ name: l.name, error: (destErrors[0] || {}).error || 'no destination' }); 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 });
|
||||
out.push({ name: l.name, id: c.rotation.id, code: c.rotation.code, url: 'https://' + host + '/r/' + c.rotation.code, to: list[0].url, dests: added, destErrors });
|
||||
}
|
||||
return json(res, 200, { ok: true, email: a.email, sourceId: sourceId || null, links: out });
|
||||
}
|
||||
// a member's spin links + traffic sources (2026-11-11, BTC4Hits import: makes the admin route above idempotent), and removing one
|
||||
if (p === '/api/admin/rotations' && (req.method === 'GET' || req.method === 'DELETE')) {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const a = await adminMember.resolve(String(u.searchParams.get('email') || ''));
|
||||
if (!a) return json(res, 404, { error: 'No member matches that email.' });
|
||||
if (req.method === 'DELETE') { const r = await rotator.remove(a.email, u.searchParams.get('id')); console.log('admin removed rotation', a.email, u.searchParams.get('id')); return json(res, r.error ? 404 : 200, r); }
|
||||
const host = String(siteConfig().linkDomains || '').split(',').map(x => x.trim().toLowerCase()).filter(h => h && !h.startsWith('www.'))[0] || SITE_HOST;
|
||||
return json(res, 200, { email: a.email, linkBase: 'https://' + host + '/r/', rotations: await rotator.list(a.email), sources: (await sources.list(a.email)).sources }, { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
if (p === '/api/admin/member' && req.method === 'PATCH') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const b = await readBody(req);
|
||||
|
||||
@@ -84,7 +84,7 @@ const inTank = a => !a.sponsorRef && !a.memberId; // arrived with no sponsor (or
|
||||
|
||||
// waiting list: newest sign-in first so a live one is easy to spot
|
||||
async function waiting() {
|
||||
const all = await accounts.listAll(2000);
|
||||
const all = await accounts.listAll(1e6); // was 2000: newest-first, so once the site passed 2000 accounts (BTC4Hits import 2026-11-11) older tank members fell off the list
|
||||
return all.filter(a => inTank(a) && !remoteOpen(a.email)).map(a => ({ email: a.email, name: nameOf(a), username: a.username || null, joined: a.created, lastSeen: a.lastSeen || 0, wallet: !!a.address,
|
||||
// wallet linked = ready to switch on payouts, the plain activation held for an adopter (24-hour clock, autoAssign after that)
|
||||
opensAt: inGrace(a) ? graceEnd(a) : 0, // new sign-up: nobody can adopt them by hand before this (0 = open now)
|
||||
|
||||
Reference in New Issue
Block a user