Admin spin-link route accepts up to 2 MB (BTC4Hits rotator #297 sends 834 URLs; every other route keeps the 64 KB limit)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-11 08:41:37 -06:00
parent bfa13302e1
commit aff03d9c5c
+3 -3
View File
@@ -912,10 +912,10 @@ async function adClickTarget(campOrId, url, req, extra) {
return { url: out, cookie: clickCookie(id), id };
} catch (e) { console.error('ad click id', e.message); return { url }; }
}
function readBody(req) {
function readBody(req, max) { // max: a larger body for one admin route only (2026-11-11, BTC4Hits import: #297 has 834 URLs); everything else stays at 64 KB
return new Promise((resolve, reject) => {
let d = ''; let n = 0;
req.on('data', c => { n += c.length; if (n > 64 * 1024) { req.destroy(); reject(new Error('too big')); } d += c; });
req.on('data', c => { n += c.length; if (n > (max || 64 * 1024)) { req.destroy(); reject(new Error('too big')); } d += c; });
req.on('end', () => { try { resolve(d ? JSON.parse(d) : {}); } catch (e) { reject(e); } });
req.on('error', reject);
});
@@ -2245,7 +2245,7 @@ const server = http.createServer(async (req, res) => {
// 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 || ''));
const b = await readBody(req, 2e6); 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();