AI ad writer: "Write my ad from my link" on the ad form (Marty 2026-11-17: "okay, let's do it.")
adwriter.js: the server reads the member's page (or follows their LinkSpin spin link, max 5 hops),
SSRF-safe (http/https, ports 80/443, every hop's DNS answer checked and the connection pinned to it,
no private/loopback/link-local/metadata address, 8 s, 1.5 MB, text/html only), extracts title, meta
and og description, h1-h3 and the first paragraphs (about 2,500 tokens), and asks OpenRouter
deepseek/deepseek-v4-flash (reasoning off; fallback anthropic/claude-haiku-5.5) for 3 options
{headline <= 60, line <= 90} written only from the page. Every option goes through the new
safety.checkAdCopy (no dashes, income promises, guarantees, links, shouting; every number must be
on the page) plus the length limits; failing ones are dropped, one retry when none survive. The
member picks one, it fills the form, nothing is posted.
Limits: AI_AD_DAILY (5) per member per Central day, AI_AD_GLOBAL_DAILY (500), 12 an hour per IP,
one at a time, a 24 h cache by page (a repeat is free). Off and hidden without AI_AD_KEY (a dedicated
OpenRouter key, $5 a month). Admin status: writes today, tokens, estimated spend.
safety.privateIp: IPv4-mapped IPv6 in hex form (::ffff:7f00:1) and all of fe80::/10 now count as private.
Chatbot fact added (KNOWLEDGE_DATE 2026-11-17). Server wiring + form markup landed in 828abce.
qa/adwriter.test.mjs 82/82, qa/e2e.mjs 63/63, qa/chatbot.test.mjs 108/108.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -66,8 +66,9 @@ function privateIp(ip) {
|
||||
|| (a === 192 && b === 168) || (a === 192 && b === 0) || (a === 198 && (b === 18 || b === 19)) || a >= 224;
|
||||
}
|
||||
const s = ip.toLowerCase();
|
||||
{ const m = /^(?:::ffff:|::ffff:0:|::|64:ff9b::)([0-9a-f]{1,4}):([0-9a-f]{1,4})$/.exec(s); if (m) { const hi = parseInt(m[1], 16), lo = parseInt(m[2], 16); return privateIp([hi >> 8, hi & 255, lo >> 8, lo & 255].join('.')); } } // IPv4-mapped/compatible/NAT64 in hex form (the URL parser writes ::ffff:127.0.0.1 as ::ffff:7f00:1)
|
||||
if (s.startsWith('::ffff:')) return privateIp(s.slice(7));
|
||||
return s === '::' || s === '::1' || s.startsWith('fc') || s.startsWith('fd') || s.startsWith('fe80') || s.startsWith('ff');
|
||||
return s === '::' || s === '::1' || s.startsWith('fc') || s.startsWith('fd') || /^fe[89ab][0-9a-f]:/.test(s) || s.startsWith('ff');
|
||||
}
|
||||
// Node 20's https agent asks for every address (opts.all, for happy eyeballs) and expects an array back; answering with one
|
||||
// address broke every link check (2026-11-15: no text ad could be posted). Answer in the shape asked for, private ones refused.
|
||||
@@ -136,4 +137,32 @@ async function fetchImage(url) {
|
||||
return { ok: true, buf: r.body, info: c.info };
|
||||
}
|
||||
|
||||
module.exports = { checkLink, checkImage, imageInfo, frameVerdict, probeLink, fetchImage, privateIp, MAX_UPLOAD };
|
||||
// ---- ad copy rules (the AI ad writer, Marty 2026-11-17): plain, honest text ad words. -> { ok } or { error }
|
||||
// No markup, links or emails; no em dash, en dash or double hyphen; no income promises or guarantees; no shouting; and, when the
|
||||
// page text is given, every number in the copy must appear on that page (the writer never invents prices, amounts or results).
|
||||
const PROMISE_RE = [
|
||||
/\bguarantee/i, /\brisk[\s-]*free\b/i, /\bno[\s-]+risk\b/i, /\bget[\s-]+rich\b/i, /\bfinancial[\s-]+freedom\b/i, /\bquit[\s-]+your[\s-]+job\b/i,
|
||||
/\bmillionaires?\b/i, /\b(make|earn|making|earning|makes|earns)\s+(real\s+|extra\s+|big\s+|fast\s+|easy\s+|serious\s+)?(money|cash|income|profits?|\$)/i,
|
||||
/\b(passive|extra|residual|full[\s-]?time|daily|weekly|monthly|guaranteed|unlimited|recurring)\s+(income|profits?|earnings|payouts?)\b/i,
|
||||
/\$\s?\d[\d,.]*\s*\+?\s*(a|per|\/|each|every)\s*(hour|day|week|month|year)\b/i, /\bdouble\s+your\s+(money|income|investment)\b/i,
|
||||
/\b(instant|easy|fast|free)\s+(money|cash)\b/i, /\bcan'?t\s+lose\b/i
|
||||
];
|
||||
function checkAdCopy(text, pageText) {
|
||||
const s = String(text == null ? '' : text);
|
||||
if (!s.trim()) return { error: 'empty' };
|
||||
if (/[<>]|[\u0000-\u001f\u007f]/.test(s)) return { error: 'markup' };
|
||||
if (/[\u2013\u2014\u2015]|--/.test(s)) return { error: 'dash' };
|
||||
if (/https?:\/\/|www\.|\b[\w.+-]+@[\w-]+\.[\w.]+\b/i.test(s)) return { error: 'link' };
|
||||
if (/[\u{1F300}-\u{1FAFF}\u{2600}-\u{27BF}]/u.test(s)) return { error: 'emoji' };
|
||||
if (/#\w/.test(s)) return { error: 'hashtag' };
|
||||
if (/!{2,}|\?{2,}/.test(s) || (s.match(/!/g) || []).length > 1) return { error: 'shouting' };
|
||||
if (/\b[A-Z]{4,}\b(\s+\b[A-Z]{2,}\b){1,}/.test(s)) return { error: 'shouting' };
|
||||
for (const re of PROMISE_RE) if (re.test(s)) return { error: 'promise' };
|
||||
if (pageText != null) {
|
||||
const page = String(pageText).replace(/[\s,]/g, '');
|
||||
for (const n of s.match(/\d[\d,.]*/g) || []) { const d = n.replace(/[,.]+$/, '').replace(/,/g, ''); if (d && !page.includes(d)) return { error: 'number' }; }
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
module.exports = { checkAdCopy, checkLink, checkImage, imageInfo, frameVerdict, probeLink, fetchImage, privateIp, MAX_UPLOAD };
|
||||
|
||||
Reference in New Issue
Block a user