Partner endpoint for DownlineHydra tracked program links (Marty 2026-11-15): POST /api/partner/dh/links, net.v1-signed with NETWORK_SSO_SECRET. op ensure makes or updates one link per program on the member's own account (by email, else network username), tagged with a new 'DownlineHydra' network source and the program id as sub-id (?s1=&placement=), clean link host from domains.hosts(); op stats answers clicks per program. rotator.ensurePartner / partnerStats; catalog template downlinehydra; NET_SRC dh. qa/partner-dhlinks.test.mjs 13/13, partner-spins 13/13, netsrc 16/16. LOCAL ONLY, not pushed or deployed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 05:26:46 -06:00
parent 82e25de691
commit d6e8de3e6a
5 changed files with 163 additions and 2 deletions
+31 -1
View File
@@ -152,6 +152,36 @@ function ensureFixed(owner, code, name, url) {
const r = { id: (J.db.rotations.reduce((m, x) => Math.max(m, x.id), 0) + 1), owner: norm(owner), name: String(name).slice(0, 80), code: c, fallback: '', destinations: [{ id: 1, url: u, label: '', weight: 1, active: true, added: Date.now() }], created: Date.now(), paused: false, nextDest: 2 };
J.db.rotations.push(r); J.save(); return { ok: true, rotation: r, created: true };
}
// DownlineHydra tracked program links (Marty 2026-11-15, /api/partner/dh/links): one link per (account, partner key), e.g.
// key 'dh:ctb19' = the member's Ads Earn Network referral link. Made on the first ask, its one destination follows the member's
// latest referral URL, its traffic source is the account's "DownlineHydra" source. Never past the 100-link account cap.
function ensurePartner(owner, key, name, url, sourceId) {
const k = String(key || ''); if (!/^[a-z]{2,8}:[a-z0-9_-]{1,40}$/i.test(k)) return { error: 'key' };
const u = cleanUrl(url); if (!u || !/^https:\/\//i.test(u)) return { error: 'Destination must be a full https:// address.' };
let r = J.db.rotations.find(x => x.owner === norm(owner) && x.partner === k); let created = false;
if (!r) {
if (J.db.rotations.filter(x => x.owner === norm(owner)).length >= 100) return { error: 'This LinkSpin account already has 100 links.' };
let code = newCode(); while (J.db.rotations.some(x => x.code === code)) code = newCode();
r = { id: (J.db.rotations.reduce((m, x) => Math.max(m, x.id), 0) + 1), owner: norm(owner), name: String(name || k).slice(0, 80), code, fallback: '', destinations: [{ id: 1, url: u, label: '', weight: 1, active: true, added: Date.now() }], created: Date.now(), paused: false, nextDest: 2, partner: k };
J.db.rotations.push(r); created = true;
} else {
const d = r.destinations[0];
if (!d) r.destinations.push({ id: r.nextDest++, url: u, label: '', weight: 1, active: true, added: Date.now() });
else if (d.url !== u) { d.url = u; d.active = true; delete d.autoPaused; }
if (name) r.name = String(name).slice(0, 80);
}
if (sourceId && !r.sourceId) r.sourceId = String(sourceId);
J.save(); return { ok: true, created, code: r.code, id: r.id };
}
// clicks on an account's partner links whose key starts with `prefix` ('dh:'): { key: { code, hits, hits30, unique30 } } (non-bot)
function partnerStats(owner, prefix) {
const mine = J.db.rotations.filter(r => r.owner === norm(owner) && r.partner && r.partner.startsWith(prefix)); const ix = new Map(mine.map(r => [r.id, r.partner]));
const since = Date.now() - 30 * DAY; const out = {};
for (const r of mine) out[r.partner] = { code: r.code, hits: 0, hits30: 0, u: new Set() };
for (const h of J.db.hits) { const k = ix.get(h.r); if (!k || h.bot) continue; const o = out[k]; o.hits++; if (h.ts >= since) { o.hits30++; o.u.add(h.v); } }
for (const k in out) { out[k].unique30 = out[k].u.size; delete out[k].u; }
return out;
}
async function remove(owner, id) { const n = J.db.rotations.length; J.db.rotations = J.db.rotations.filter(r => !(r.id === Number(id) && r.owner === norm(owner))); J.save(); return n !== J.db.rotations.length ? { ok: true } : { error: 'No such rotation.' }; }
// opts.max: the admin import path only (BTC4Hits rotators, 2026-11-11) may go past the 25 a member can add, up to IMPORT_MAX
const DEST_MAX = 25, IMPORT_MAX = 2000;
@@ -366,4 +396,4 @@ function adminAll() {
hits: o.hits, hits7: o.hits7, bots: o.bots, conversions: cv[r.id] || 0 }; });
}
module.exports = { init, convRows, adminAll, hitById, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary, createDemo, claim, sweepDemos, servedToday, window24,
pub, rawRotations, save, findMine, setExternalConvert, PRESETS, cleanHours, cleanTz, cellAt, zoneFor, isOn, COUNTRY_TZ, sourceCounts, detachSource, ensureFixed };
pub, rawRotations, save, findMine, setExternalConvert, PRESETS, cleanHours, cleanTz, cellAt, zoneFor, isOn, COUNTRY_TZ, sourceCounts, detachSource, ensureFixed, ensurePartner, partnerStats };