AI ad writer on LinkSpin (Marty 2026-11-17: "do it on the other sites too"): "Write my ad from my link" on the Ads screen text ads (60/140) and "Write my headline from my link" in the page builder (headline 90 + subhead 200), both asking the network hub (hubadwriter.js, POST /v1/adwriter) through GET/POST /api/my/adwriter; shown only when the hub says on; chatbot fact, KNOWLEDGE_DATE 2026-11-17; ads-screen.js/pages-screen.js ?v=20261117aiw. Plus the PolHunter embed on the home page (3 tiles) with polhunter.com in script-src and connect-src (punch list L2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 08:43:47 -06:00
parent 5613d10224
commit ae39e05fc5
9 changed files with 165 additions and 6 deletions
+2 -1
View File
File diff suppressed because one or more lines are too long
+54
View File
@@ -0,0 +1,54 @@
// The network AI ad writer, asked through the hub (Marty 2026-11-17: "the AI generation of the ads worked really well. Let's go
// ahead and do it on the other sites too."). The hub reads the member's page, asks the model and filters the copy
// (network-hub lib/adwriter.js); this file only signs the call for this site's signed-in member and passes the answer on.
// status(member?) -> {on, daily, left?} (cached 60 s; on: false when the hub is unset, unreachable or switched off)
// write(member, url, limits) -> {ok, options: [{headline, line?}], url, cached, left} | {error (member-friendly), code, status, left?}
// Signed as HUB_SITE with HUB_SECRET: X-Hub-Site, X-Hub-Ts, X-Hub-Sig = hex HMAC-SHA256(ts + newline + raw body), like every /v1 call.
// AI_WRITER=0 hides the button on this site. Nothing is posted: the member picks an option, edits it and saves it themselves.
'use strict';
const crypto = require('crypto');
const DEFAULT_SITE = 'linkspin';
const hubUrl = () => String(process.env.HUB_URL || '').trim().replace(/\/+$/, '');
const secret = () => String(process.env.HUB_SECRET || '').trim();
const site = () => String(process.env.HUB_SITE || DEFAULT_SITE).trim();
const configured = () => !/^(0|false|no|off)$/i.test(String(process.env.AI_WRITER || '').trim()) && !!hubUrl() && secret().length >= 32;
async function call(route, body, timeoutMs) {
const raw = JSON.stringify(body); const ts = String(Date.now());
const sig = crypto.createHmac('sha256', secret()).update(ts + '\n' + raw).digest('hex');
const r = await fetch(hubUrl() + route, { method: 'POST', body: raw, signal: AbortSignal.timeout(timeoutMs),
headers: { 'Content-Type': 'application/json', 'X-Hub-Site': site(), 'X-Hub-Ts': ts, 'X-Hub-Sig': sig } });
let j = null; try { j = await r.json(); } catch (e) { j = null; }
return { status: r.status, body: j || {} };
}
let st = { at: 0, v: { on: false, daily: 0 } };
async function status(member) {
if (!configured()) return { on: false, daily: 0 };
if (!member && Date.now() - st.at < 60000) return st.v;
try {
const r = await call('/v1/adwriter/status', member ? { member: String(member) } : {}, 3000);
const v = r.status === 200 && r.body && typeof r.body.on === 'boolean' ? r.body : { on: false, daily: 0 };
if (!member) st = { at: Date.now(), v: { on: v.on, daily: v.daily || 0 } };
return v;
} catch (e) { if (!member) st = { at: Date.now() - 45000, v: { on: false, daily: 0 } }; return { on: false, daily: 0 }; } // a down hub is asked again in 15 s
}
// the button shows only when the hub says the writer is on (60 s cache, never waits on a slow hub for long)
async function enabled() { return (await status()).on === true; }
async function write(member, url, limits) {
if (!configured()) return { error: 'The ad writer is switched off right now. You can still write your ad yourself.', code: 'off', status: 503 };
try {
const r = await call('/v1/adwriter', { member: String(member), url: String(url || '').trim().slice(0, 600), limits }, 75000);
const b = r.body || {};
if (r.status === 200 && b.ok && Array.isArray(b.options)) return { ok: true, options: b.options, url: b.url, cached: !!b.cached, left: b.left };
if (r.status === 401 || r.status === 403 || !b.message) { console.error('hubadwriter: hub answered ' + r.status + ' ' + String(b.error || '')); return { error: 'The ad writer is busy right now. Try again in a minute, or write your ad yourself.', code: 'hub', status: 502 }; }
return { error: String(b.message), code: b.error || b.code || 'error', status: r.status >= 400 && r.status < 600 ? r.status : 502, left: b.left };
} catch (e) {
console.error('hubadwriter: ' + (e.name === 'TimeoutError' || e.name === 'AbortError' ? 'timeout' : String(e.message).slice(0, 120)));
return { error: 'The ad writer did not answer in time. Try again in a minute, or write your ad yourself.', code: 'hub', status: 504 };
}
}
module.exports = { status, enabled, write, configured, _reset: () => { st = { at: 0, v: { on: false, daily: 0 } }; } };
+2 -1
View File
@@ -60,6 +60,7 @@
<label class="lbl">Headline (60)<input class="field" id="fTitle" maxlength="60"></label>
<label class="lbl">One line (140)<input class="field" id="fBody" maxlength="140"></label>
</div>
<div id="aiRow" hidden style="margin-top:10px"><button class="btn sm" type="button" id="aiWrite">Write my ad from my link</button> <span class="muted" style="font-size:12px">Put your link in Where the click goes first. We read that page and suggest 3 text ads using only what it says. Nothing launches until you tap Launch.</span><div id="aiList" hidden style="margin-top:8px"></div></div>
<div id="prev" style="margin-top:12px"></div>
<div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:14px;align-items:center"><button class="btn pri" type="button" id="fGo">Launch</button><button class="btn ghost" type="button" id="fCancel">Cancel</button><span class="led" id="fCost"></span></div>
</div>
@@ -76,7 +77,7 @@
</div>
</div>
<script src="/assets/cr-shell.js?v=20261115hub"></script>
<script src="/assets/ads-screen.js?v=20261114tu"></script>
<script src="/assets/ads-screen.js?v=20261117aiw"></script>
<script src="/assets/fuel.js?v=20261113sso"></script>
<script src="/assets/engine-room.js?v=20261113sso"></script>
</body>
+19 -2
View File
@@ -2,7 +2,7 @@
// viewer, member zones and the partner network, and earn credits by viewing. Types are limited to the three Marty chose.
(function () {
const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt, api = CR.api, toast = CR.toast, dialog = CR.dialog;
let D = null, EARN = null, TYPE = 'banner', SPINS = [], HOSTS = [], IMG = '';
let D = null, EARN = null, TYPE = 'banner', SPINS = [], HOSTS = [], IMG = '', AIW = false;
CR.mount({ active: 'ads', title: 'Ads', sub: 'loading', actions: '<button class="btn pri" type="button" id="newBtn">+ New ad</button>' });
const NOTE = {
banner: 'Runs in the ad viewer, in every member zone on outside sites, and on the partner network. Views are timed on the server. Spends purchased or earned credits.',
@@ -148,7 +148,7 @@
window.addEventListener('storage', e => { if (e.key === 'iap-view-done') earnRefresh(); });
$('earnClaim').addEventListener('click', async () => { try { const r = await api('/api/my/claim', {}); toast('+' + r.credited + ' credits' + (r.streakDay > 1 ? ', streak day ' + r.streakDay : '') + '. Spend them on an ad.'); load(); } catch (e) { toast(e.message, true); } });
// -- composer
function setType(t) { TYPE = t; document.querySelectorAll('#typeChips .chip').forEach(c => c.classList.toggle('on', c.dataset.t === t)); $('typeNote').textContent = t === 'login' ? loginNote() : NOTE[t]; $('bannerFields').hidden = t !== 'banner'; $('textFields').hidden = t !== 'text'; $('fCap').parentElement.hidden = t === 'login';
function setType(t) { TYPE = t; document.querySelectorAll('#typeChips .chip').forEach(c => c.classList.toggle('on', c.dataset.t === t)); $('typeNote').textContent = t === 'login' ? loginNote() : NOTE[t]; $('bannerFields').hidden = t !== 'banner'; $('textFields').hidden = t !== 'text'; $('aiRow').hidden = t !== 'text' || !AIW; $('fCap').parentElement.hidden = t === 'login';
const L = slotInfo(), full = t === 'login' && !L.free; const fb = $('fBudget');
if (t === 'login') { fb.dataset.keep = fb.dataset.keep || fb.value; fb.value = L.credits; fb.readOnly = true; } else { if (fb.readOnly && fb.dataset.keep) fb.value = fb.dataset.keep; delete fb.dataset.keep; fb.readOnly = false; }
$('fGo').disabled = false; $('fGo').textContent = full ? 'Reserve the next slot' : 'Launch'; $('fGo').title = full ? 'All login-ad slots are taken: pay now for a place in line' : '';
@@ -185,6 +185,23 @@
setType(TYPE);
});
$('fCancel').addEventListener('click', () => { $('composer').hidden = true; });
// the AI ad writer (Marty 2026-11-17): 3 text ads the network hub writes only from the member's own page; picking one fills the
// headline and line to edit. Shown only when the hub answers it is on.
CR.get('/api/my/adwriter').then(w => { AIW = !!(w && w.on); if (!$('composer').hidden) setType(TYPE); }).catch(() => { AIW = false; });
{ let opts = [];
$('aiWrite').addEventListener('click', async () => {
const box = $('aiList'), url = $('fTarget').value.trim(); box.hidden = false;
if (!/^https?:\/\/\S+\.\S+/i.test(url)) { box.innerHTML = '<span class="muted">Put your link in Where the click goes first (starting with https://), or pick a spin link, then tap the button again.</span>'; $('fTarget').focus(); return; }
$('aiWrite').disabled = true; box.innerHTML = '<span class="muted">Reading your page and writing 3 ads. This takes a few seconds...</span>';
let r; try { r = await api('/api/my/adwriter', { url, kind: 'text' }); } catch (e) { r = { error: e.message || 'The ad writer did not answer. Try again in a minute.' }; }
$('aiWrite').disabled = false;
if (r.error) { box.innerHTML = '<span class="bad">' + esc(r.error) + '</span>'; return; }
opts = r.options || [];
box.innerHTML = '<div class="muted" style="font-size:12px;margin-bottom:6px">Tap one to use it. Check every word is true for your offer before you launch.' + (typeof r.left === 'number' ? ' Ad writes left today: ' + r.left + '.' : '') + '</div>'
+ opts.map((o, i) => '<button type="button" class="btn ghost" data-ai="' + i + '" style="display:block;width:100%;text-align:left;margin:0 0 6px;white-space:normal;height:auto"><b>' + esc(o.headline) + '</b><br><span class="ink2">' + esc(o.line || '') + '</span></button>').join('');
box.querySelectorAll('button[data-ai]').forEach(b => b.addEventListener('click', () => { const o = opts[Number(b.dataset.ai)]; $('fTitle').value = o.headline; $('fBody').value = o.line || ''; box.hidden = true; preview(); toast('Filled in. Edit it as you like, then tap Launch.'); }));
});
}
$('fGo').addEventListener('click', async () => {
const body = { type: TYPE, name: $('fName').value, targetUrl: $('fTarget').value.trim(), budget: Number($('fBudget').value), geo: $('fGeo').value };
if (TYPE !== 'login' && $('fCap').value) body.dailyCap = Number($('fCap').value);
+26
View File
@@ -88,6 +88,7 @@
// pasted provider forms: say at paste time which autoresponder the form posts to
+ (k === 'formEmbed' ? '<div class="muted" id="providerNote" style="font-size:12px" hidden></div>' : '')).join('');
if ($('imgUpload')) { $('imgUpload').addEventListener('click', () => $('imgFile').click()); $('imgFile').addEventListener('change', () => { uploadFile($('imgFile').files[0]); $('imgFile').value = ''; }); drawImages(); }
aiHeadline(p);
if ($('f-formEmbed')) { const fe = $('f-formEmbed'); const upd = () => providerNote(fe.value); fe.addEventListener('input', upd); fe.addEventListener('paste', () => setTimeout(upd, 0)); upd(); }
// the Look panel: niche preset, design, colours, layout. Each change saves at once and the gallery/preview refresh.
const d = p.design || {}; const setLook = async patch => { try { await api('/api/my/pages/' + p.id, patch); load(true); } catch (e) { toast(e.message, true); } };
@@ -101,6 +102,31 @@
$('layouts').querySelectorAll('button').forEach(b => b.addEventListener('click', () => setLook({ layout: b.dataset.l })));
if (!quiet && window.matchMedia('(max-width:900px)').matches) $('side').scrollIntoView({ behavior: 'smooth' });
}
// the AI ad writer on the headline (Marty 2026-11-17): the network hub reads the button link (or the scanned page) and suggests
// 3 headline + subhead pairs written only from it; picking one fills both fields to edit. Saved only with Save.
let AIW = null;
async function aiHeadline(p) {
const sub = $('f-sub'); if (!sub) return;
if (AIW === null) { try { const w = await CR.get('/api/my/adwriter'); AIW = !!(w && w.on); } catch (e) { AIW = false; } }
if (!AIW || !$('f-sub') || $('aiHead')) return;
const wrap = document.createElement('div'); wrap.id = 'aiHead'; wrap.style.margin = '0 0 10px';
wrap.innerHTML = '<button class="btn sm" type="button" id="aiHeadBtn">Write my headline from my link</button> <span class="muted" style="font-size:11px">Reads the Button link page and suggests 3 headlines with a subhead, using only what that page says.</span><div id="aiHeadList" hidden style="margin-top:8px"></div>';
$('f-sub').closest('label').after(wrap);
let opts = [];
$('aiHeadBtn').addEventListener('click', async () => {
const box = $('aiHeadList'); box.hidden = false;
const url = (($('f-ctaUrl') && $('f-ctaUrl').value) || (p.scan && p.scan.url) || '').trim();
if (!/^https?:\/\/\S+\.\S+/i.test(url)) { box.innerHTML = '<span class="muted">Put the offer link in the Button link field first (starting with https://), then tap the button again.</span>'; return; }
$('aiHeadBtn').disabled = true; box.innerHTML = '<span class="muted">Reading the page and writing 3 headlines. This takes a few seconds...</span>';
let r; try { r = await api('/api/my/adwriter', { url, kind: 'page' }); } catch (e) { r = { error: e.message || 'The ad writer did not answer. Try again in a minute.' }; }
$('aiHeadBtn').disabled = false;
if (r.error) { box.innerHTML = '<span class="bad">' + esc(r.error) + '</span>'; return; }
opts = r.options || [];
box.innerHTML = '<div class="muted" style="font-size:11px;margin-bottom:6px">Tap one to use it, then Save. Check every word is true for your offer.' + (typeof r.left === 'number' ? ' Writes left today: ' + r.left + '.' : '') + '</div>'
+ opts.map((o, i) => '<button type="button" class="btn ghost" data-ai="' + i + '" style="display:block;width:100%;text-align:left;margin:0 0 6px;white-space:normal;height:auto"><b>' + esc(o.headline) + '</b><br><span class="muted">' + esc(o.line || '') + '</span></button>').join('');
box.querySelectorAll('button[data-ai]').forEach(b => b.addEventListener('click', () => { const o = opts[Number(b.dataset.ai)]; $('f-headline').value = o.headline; if ($('f-sub')) $('f-sub').value = o.line || ''; box.hidden = true; toast('Filled in. Edit it as you like, then tap Save.'); }));
});
}
function collect(p) { const g = k => { const el = $('f-' + k); return el ? el.value : undefined; }; const c = {}; for (const [k] of F[p.type]) { if (k === 'ctaText' || k === 'ctaUrl') continue; c[k] = g(k); } c.cta = { text: g('ctaText'), url: g('ctaUrl') }; for (const k of ['bullets', 'pros', 'cons']) if (c[k] != null) c[k] = c[k].split('\n'); return c; }
$('edSave').addEventListener('click', async () => { const p = PAGES.find(x => x.id === SEL); if (!p) return; try { await api('/api/my/pages/' + p.id, { content: collect(p), title: ($('f-headline').value || p.title).slice(0, 100) }); toast('Saved'); load(true); } catch (e) { toast(e.message, true); } });
$('edPublish').addEventListener('click', async () => { const p = PAGES.find(x => x.id === SEL); if (!p) return; try { await api('/api/my/pages/' + p.id, { content: collect(p) }); const r = await api('/api/my/pages/' + p.id, { status: p.status === 'published' ? 'draft' : 'published' }); toast(r.page.status === 'published' ? 'Live at ' + pageUrl(r.page) : 'Unpublished'); load(true); } catch (e) { toast(e.message, true); } });
+1
View File
@@ -226,5 +226,6 @@
<script src="/assets/home.js?v=20261113me"></script>
<script src="/assets/netline.js?v=20261117nw" data-site="linkspin"></script>
<script src="https://polhunter.com/embed.js" data-slots="3" data-selector="article.tile.card" async></script>
</body>
</html>
+1 -1
View File
@@ -74,6 +74,6 @@
</div>
</div>
<script src="/assets/cr-shell.js?v=20261115hub"></script>
<script src="/assets/pages-screen.js?v=20261021t"></script>
<script src="/assets/pages-screen.js?v=20261117aiw"></script>
</body>
</html>
+43
View File
@@ -0,0 +1,43 @@
// The network ad writer client (2026-11-17): node qa/hubadwriter.test.mjs
// A stand-in hub checks the signature and answers like network-hub lib/adwriter.js; no real hub, no model, no member.
import http from 'node:http';
import crypto from 'node:crypto';
import path from 'node:path';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..');
let pass = 0, fail = 0;
const ok = (c, m, extra) => { if (c) pass++; else { fail++; console.log('FAIL', m, extra !== undefined ? JSON.stringify(extra).slice(0, 300) : ''); } };
const SECRET = 's'.repeat(40); let seen = [], mode = 'good';
const hub = http.createServer((q, r) => { let b = ''; q.on('data', c => { b += c; }); q.on('end', () => {
const sig = crypto.createHmac('sha256', SECRET).update(q.headers['x-hub-ts'] + '\n' + b).digest('hex');
r.setHeader('Content-Type', 'application/json');
if (sig !== q.headers['x-hub-sig']) { r.statusCode = 401; return r.end('{"error":"unauthorized"}'); }
const j = JSON.parse(b); seen.push({ path: q.url, site: q.headers['x-hub-site'], body: j });
if (q.url === '/v1/adwriter/status') return r.end(JSON.stringify(mode === 'off' ? { on: false, daily: 5 } : { on: true, daily: 5, left: j.member ? 3 : undefined }));
if (mode === 'limit') { r.statusCode = 429; return r.end(JSON.stringify({ ok: false, error: 'member_limit', code: 'member_limit', message: 'You have used your 5 ad writes for today.', left: 0 })); }
if (mode === 'slow') return;
r.end(JSON.stringify({ ok: true, options: [{ headline: 'One link for all your pages', line: 'Share one link that rotates your pages.' }], url: 'https://linkspin.app/', cached: false, left: 4 }));
}); });
await new Promise(r => hub.listen(0, '127.0.0.1', r));
process.env.HUB_URL = 'http://127.0.0.1:' + hub.address().port; process.env.HUB_SECRET = SECRET; delete process.env.HUB_SITE; delete process.env.AI_WRITER;
const aw = require(path.join(ROOT, 'hubadwriter.js'));
ok(await aw.enabled(), 'on when the hub says on');
ok(seen[0].path === '/v1/adwriter/status' && seen[0].site && seen[0].site !== '__SITE__', 'signed as this site', seen[0]);
let r = await aw.write('member-1', 'https://linkspin.app', { headline: 60, line: 90 });
ok(r.ok && r.options.length === 1 && r.left === 4, 'options passed on', r);
ok(seen[1].body.member === 'member-1' && seen[1].body.limits.headline === 60 && seen[1].body.limits.line === 90 && seen[1].body.url === 'https://linkspin.app', 'member, url and this site\'s limits sent', seen[1].body);
mode = 'limit'; r = await aw.write('member-1', 'https://linkspin.app', { headline: 60, line: 90 });
ok(r.error === 'You have used your 5 ad writes for today.' && r.status === 429 && r.left === 0, 'the hub message is shown as is', r);
const st = await aw.status('member-1'); ok(st.on && st.left === 3, 'status for a member (left today)', st);
mode = 'off'; aw._reset(); ok(!(await aw.enabled()), 'off when the hub says off');
process.env.HUB_SECRET = 'w'.repeat(40); mode = 'good'; r = await aw.write('member-1', 'https://linkspin.app', { headline: 60, line: 90 });
ok(r.code === 'hub' && /busy/.test(r.error), 'a refused signature: a friendly busy message', r);
aw._reset(); ok(!(await aw.enabled()), 'a refused signature hides the button');
process.env.HUB_SECRET = SECRET; process.env.AI_WRITER = '0'; aw._reset(); const n0 = seen.length; ok(!(await aw.enabled()) && seen.length === n0, 'AI_WRITER=0 hides it without asking the hub', seen.length);
delete process.env.AI_WRITER; process.env.HUB_URL = 'http://127.0.0.1:1'; aw._reset(); ok(!(await aw.enabled()), 'an unreachable hub hides the button');
hub.close();
console.log('hubadwriter: ' + pass + ' passed, ' + fail + ' failed');
process.exit(fail ? 1 : 0);
+17 -1
View File
@@ -50,6 +50,7 @@ const registry = require('./registry'); // network registry: who is who ac
const iapsync = require('./iapsync'); // reverse registry sync: LinkSpin-first members reach InstantAdPay (2026-10-15)
const loginClock = require('./loginadclock'); // login ads on a clock, not only at sign-in (Marty 2026-11-15): see loginadclock.js
const erase = require('./erase'); // member erase (2026-11-15, LS-1021): POST /api/admin/erase + the hub's member.erased event
const adwriter = require('./hubadwriter'); // the network AI ad writer, asked through the hub (2026-11-17): text ads + page headlines
const hubsync = require('./hubsync'); // network hub link, inert unless HUB_ENABLED=1 (2026-11-12)
const SF = require('./sponsorfollow'); // deliberate sponsor changes follow to InstantAdPay until chain-bound + one network tank (2026-10-22)
let follow = null, followStore = null;
@@ -904,7 +905,7 @@ const MIME = { '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.js': '
'.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml', '.webp': 'image/webp',
'.ico': 'image/x-icon', '.json': 'application/json', '.mp4': 'video/mp4', '.woff2': 'font/woff2',
'.gif': 'image/gif', '.webm': 'video/webm', '.txt': 'text/plain; charset=utf-8', '.xml': 'application/xml; charset=utf-8' };
const CSP = "default-src 'self'; script-src 'self' https://cdn.jsdelivr.net 'sha256-NzvNrqk5jB9YZATwo5BF4JoRlJ02HsnFikbKXgEPdaQ=' " + themehead.CSP_HASH + "; worker-src 'self' blob:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https:; media-src 'self' https: blob:; connect-src 'self' https://*.walletconnect.com wss://*.walletconnect.com https://*.walletconnect.org wss://*.walletconnect.org https://*.reown.com wss://*.reown.com https://*.reown.org wss://*.reown.org https://*.web3modal.org https://*.drpc.org https://*.publicnode.com https://*.coinbase.com; font-src 'self' data: https://fonts.gstatic.com https://fonts.reown.com; form-action 'self'; frame-src https: http:";
const CSP = "default-src 'self'; script-src 'self' https://cdn.jsdelivr.net https://polhunter.com 'sha256-NzvNrqk5jB9YZATwo5BF4JoRlJ02HsnFikbKXgEPdaQ=' " + themehead.CSP_HASH + "; worker-src 'self' blob:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https:; media-src 'self' https: blob:; connect-src 'self' https://polhunter.com https://*.walletconnect.com wss://*.walletconnect.com https://*.walletconnect.org wss://*.walletconnect.org https://*.reown.com wss://*.reown.com https://*.reown.org wss://*.reown.org https://*.web3modal.org https://*.drpc.org https://*.publicnode.com https://*.coinbase.com; font-src 'self' data: https://fonts.gstatic.com https://fonts.reown.com; form-action 'self'; frame-src https: http:";
function baseHeaders(extra) {
return Object.assign({ 'Content-Security-Policy': CSP, 'X-Content-Type-Options': 'nosniff',
'Referrer-Policy': 'strict-origin-when-cross-origin' }, extra || {});
@@ -4061,6 +4062,21 @@ const server = http.createServer(async (req, res) => {
const r = b.remove ? audiences.remove(s.email, b.id) : b.id ? audiences.rename(s.email, b.id, b.name) : audiences.create(s.email, b.name);
return json(res, r.error ? 400 : 200, r);
}
// the AI ad writer (Marty 2026-11-17: "do it on the other sites too"): the hub reads the member's page and suggests 3 options written
// only from it. kind 'text' = a text ad (headline 60, one line 140); kind 'page' = a page builder headline (90) + subhead (200).
// Nothing is saved here: the member picks one, edits it and launches or saves it themselves.
if (p === '/api/my/adwriter' && (req.method === 'GET' || req.method === 'POST')) {
const s = await auth.fromRequest(req);
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
if (req.method === 'GET') { const w = await adwriter.status(s.email); return json(res, 200, { on: !!w.on, daily: w.daily || 0, left: w.left }); }
if (!(await adwriter.enabled())) return json(res, 503, { error: 'The ad writer is switched off right now. You can still write it yourself.' });
if (supportFlood('aiw:' + clientIp(req), 12, 3600000)) return json(res, 429, { error: 'Too many ad writes from this connection this hour. Try again later, or write it yourself.' });
const b = await readBody(req);
const limits = b && b.kind === 'page' ? { headline: 90, line: 200 } : { headline: 60, line: 140 };
const r = await adwriter.write(s.email, String((b && b.url) || '').trim().slice(0, 600), limits);
if (r.error) return json(res, r.status || 400, { error: r.error, code: r.code, left: r.left });
return json(res, 200, { ok: true, options: r.options, url: r.url, cached: r.cached, left: r.left });
}
if (p === '/api/my/campaigns' && req.method === 'GET') {
const s = await auth.fromRequest(req);
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });