Partner tracked links generalized (2026-11-15): POST /api/partner/<site>/links for site dh (DownlineHydra programs) or vab (ViralAdBlitz text ads, the ad id as s1/placement). PARTNER_LINKS maps each site to its network template + link name; keys dh:<id> / vab:<id> keep the two apart; items take program or id. Catalog viraladblitz template gains clickid/placement/s1 params. qa/partner-vablinks.test.mjs 13/13 (signature, unknown site refused, source, edit keeps the code, dh vs vab apart, stats per site); run.sh netsrc runs netsrc 17/17 + partner-dhlinks 13/13 + partner-vablinks 13/13. LOCAL ONLY.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1428,6 +1428,8 @@ function curtained(req, res, u) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// partner sites allowed on /api/partner/<site>/links (2026-11-15): network catalog template + the name the member sees on the link
|
||||
const PARTNER_LINKS = { dh: { template: 'downlinehydra', name: 'DownlineHydra' }, vab: { template: 'viraladblitz', name: 'ViralAdBlitz' } };
|
||||
const server = http.createServer(async (req, res) => {
|
||||
{ const t0 = Date.now(); res.on('finish', () => { const ms = Date.now() - t0; if (ms > 3000) console.warn('slow request', req.method, String(req.url || '').split('?')[0].slice(0, 80), ms + 'ms', res.statusCode); }); } // visibility for member-felt delays (2026-10-12)
|
||||
try {
|
||||
@@ -3130,14 +3132,19 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
return json(res, 200, out, { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
// -- DownlineHydra tracked program links (Marty 2026-11-15). Same net.v1 signature as the Banner Spins call above. A DownlineHydra
|
||||
// -- Partner tracked links (Marty 2026-11-15): /api/partner/<site>/links, site = dh (DownlineHydra program links) or vab (ViralAdBlitz
|
||||
// text ads, the ad id as sub-id). PARTNER_LINKS names each site's network template and link name. Below, "program" = the
|
||||
// partner's item id (a DownlineHydra program, a ViralAdBlitz ad).
|
||||
// DownlineHydra tracked program links (Marty 2026-11-15). Same net.v1 signature as the Banner Spins call above. A DownlineHydra
|
||||
// member saved a referral link for an outside program (a wild head or a my head); their downline sees a LinkSpin link for it
|
||||
// on this member's own account, tagged with the account's "DownlineHydra" source and the program id as a sub-id
|
||||
// (?s1=<program>&placement=<program>, so Reports split clicks by program). Only clean link domains (domains.hosts()).
|
||||
// { email, username?, op: 'ensure', links: [{ program, name, url }] } -> { account, username, host, links: { program: { code, link } }, errors }
|
||||
// { email, username?, op: 'stats' } -> { account, host, stats: { program: { code, link, hits, hits30, unique30 } } }
|
||||
// Nothing else about the account is read or changed.
|
||||
if (p === '/api/partner/dh/links' && req.method === 'POST') {
|
||||
const plm = req.method === 'POST' ? /^\/api\/partner\/([a-z]{2,8})\/links$/.exec(p) : null;
|
||||
if (plm && PARTNER_LINKS[plm[1]]) {
|
||||
const PL = PARTNER_LINKS[plm[1]]; const pfx = plm[1] + ':';
|
||||
let raw = ''; try { raw = await new Promise((ok, no) => { let d = ''; req.on('data', c => { d += c; if (d.length > 65536) { req.destroy(); no(new Error('too big')); } }); req.on('end', () => ok(d)); req.on('error', no); }); } catch (e) { return json(res, 400, { error: 'bad body' }); }
|
||||
const sec = String(process.env.NETWORK_SSO_SECRET || '').trim(); const ts = String(req.headers['x-net-ts'] || ''); const sig = String(req.headers['x-net-sig'] || '');
|
||||
if (sec.length < 32 || !/^\d{13}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 300000) return json(res, 401, { error: 'unauthorized' });
|
||||
@@ -3152,16 +3159,16 @@ const server = http.createServer(async (req, res) => {
|
||||
const host = hs[0].host; const PID = /^[a-z0-9_-]{1,40}$/i;
|
||||
const linkOf = (code, pid) => 'https://' + host + '/r/' + code + '?s1=' + encodeURIComponent(pid) + '&placement=' + encodeURIComponent(pid);
|
||||
if (b.op === 'stats') {
|
||||
const st = rotator.partnerStats(a.email, 'dh:'); const out = {};
|
||||
for (const [k, v] of Object.entries(st)) { const pid = k.slice(3); out[pid] = { code: v.code, link: linkOf(v.code, pid), hits: v.hits, hits30: v.hits30, unique30: v.unique30 }; }
|
||||
const st = rotator.partnerStats(a.email, pfx); const out = {};
|
||||
for (const [k, v] of Object.entries(st)) { const pid = k.slice(pfx.length); out[pid] = { code: v.code, link: linkOf(v.code, pid), hits: v.hits, hits30: v.hits30, unique30: v.unique30 }; }
|
||||
return json(res, 200, { account: true, username: a.username || null, host, stats: out }, { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
if (b.op !== 'ensure' || !Array.isArray(b.links) || !b.links.length || b.links.length > 60) return json(res, 400, { error: 'op' });
|
||||
const src = sources.networkSource(a.email, 'downlinehydra');
|
||||
const src = sources.networkSource(a.email, PL.template);
|
||||
const links = {}, errors = {};
|
||||
for (const x of b.links) {
|
||||
const pid = String((x && x.program) || ''); if (!PID.test(pid)) { errors[pid.slice(0, 40) || '?'] = 'program'; continue; }
|
||||
const r = rotator.ensurePartner(a.email, 'dh:' + pid, 'DownlineHydra: ' + String(x.name || pid).slice(0, 60), String(x.url || ''), src ? src.id : null);
|
||||
const pid = String((x && (x.program || x.id)) || ''); if (!PID.test(pid)) { errors[pid.slice(0, 40) || '?'] = 'program'; continue; }
|
||||
const r = rotator.ensurePartner(a.email, pfx + pid, PL.name + ': ' + String(x.name || pid).slice(0, 60), String(x.url || ''), src ? src.id : null);
|
||||
if (r.error) errors[pid] = r.error; else links[pid] = { code: r.code, link: linkOf(r.code, pid), created: r.created };
|
||||
}
|
||||
return json(res, 200, { account: true, username: a.username || null, host, sourceId: src ? src.id : null, links, errors }, { 'Cache-Control': 'no-store' });
|
||||
|
||||
Reference in New Issue
Block a user