AI ad writer on the text-ad form (Marty 2026-11-17: "do it on the other sites too"): "Write my ad from my link" asks the network hub (hubadwriter.js, POST /v1/adwriter, 60/90 limits) for 3 ads from the member's own page; shown only when the hub says on; chatbot fact; my.js?v=9

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 08:00:39 -06:00
parent b062939577
commit e0adc62c31
7 changed files with 133 additions and 3 deletions
+1
View File
@@ -92,6 +92,7 @@ const FAQ = [
const FACTS = () => [
'- WHAT IT IS: ViralAdBlitz (' + URL_ + ') is the network\'s text-ad home. One free text ad per network member (an InstantAdPay or LinkSpin account, checked with the network hub). Sign in on ' + URL_ + '/my through InstantAdPay or LinkSpin (network sign-in) or with a wallet signature (free, cannot move funds).',
'- AI AD WRITER (LIVE 2026-11-17): on the ad form at ' + URL_ + '/my, put your link in the Your link box (a page or your own LinkSpin spin link) and tap "Write my ad from my link": it reads that page and suggests 3 ads using only what the page says (no made-up claims, numbers or income promises); tapping one fills the headline and first line to edit, nothing is posted until you save; 5 writes a day per member (reset at midnight Central), the same page again within 24 hours is free. It is the same network ad writer as on ViralAdSource, InstantAdPay and LinkSpin.',
'- THE AD: headline 3 to ' + C.ad.headline + ' characters, line 1 3 to ' + C.ad.line + ', line 2 optional up to ' + C.ad.line + ', an https link to a real public page that answers, no link shorteners (except the member\'s OWN LinkSpin spin link: "Use one of my spin links" on the ad form lists them, the server accepts a LinkSpin /r/ link only when LinkSpin confirms it belongs to the signed-in member, never someone else\'s, never a paused one or one with no active pages; it rotates the ad\'s clicks across the member\'s pages and is already tracked, so "Track with LinkSpin" is off for it). One ad per member, editable any time, a Boost follows the ad when it is edited. "Track with LinkSpin" (default on) sends the link through the member\'s own LinkSpin tracked link; My page shows those clicks; {clickid}/{placement} links are not tracked.',
'- MEMBER PAGE ' + URL_ + '/<network username>: the owner\'s ad on top, then the ads of the first 5 people above them in the hub sponsor line who have a live ad (labelled LEVEL 1 to LEVEL 5 in the order shown; the site walks up to ' + C.lineSearch + ' places), then ' + C.boostSlots + ' Boosted places, then "Join free under @owner" (InstantAdPay\'s join page). Front page: a live ticker of the newest ads (Boosted ones starred), "Top ads this week" by verified clicks, today\'s numbers, the live ledger and contract proof.',
'- VERIFIED VIEWS: a real browser keeps the page open and visible for ' + C.visitSeconds + ' seconds; the server decides which ads were shown; one view per visitor per ad per 24 hours; never the owner\'s own; bots, early sends and more than ' + C.perIpDay + ' browsers per connection per day are refused. Verified clicks: once per visitor per ad per 24 hours, never the owner\'s own; raw clicks are counted apart.',
+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 = 'viraladblitz';
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 } }; } };
+17
View File
@@ -44,6 +44,23 @@
const isSpin = v => { v = String(v || '').trim().toLowerCase(); if (spinAd && v === String(spinAd).toLowerCase()) return true; return !!(spins && spins.some(x => x.url.toLowerCase() === v)); };
const spinMark = () => { const on = isSpin($('fLink').value); $('fTrack').disabled = on; $('trackNote').hidden = !on; $('fTrack').closest('label').style.opacity = on ? '0.6' : ''; };
$('fLink').addEventListener('input', spinMark);
// the AI ad writer (Marty 2026-11-17): 3 suggestions the hub writes only from the member's own page; picking one fills the form
if (c.aiWriter) {
$('aiBox').hidden = false;
let opts = [];
$('aiWrite').onclick = async () => {
const box = $('aiList'), url = $('fLink').value.trim(); box.hidden = false;
if (!/^https?:\/\/\S+\.\S+/i.test(url)) { box.innerHTML = '<p class="small" style="margin:0">Put your link in the Your link box first (starting with https://), then tap the button again.</p>'; $('fLink').focus(); return; }
$('aiWrite').disabled = true; box.innerHTML = '<p class="small muted" style="margin:0">Reading your page and writing 3 ads. This takes a few seconds...</p>';
const r = await VAB.post('/api/my/adwriter', { url }).catch(() => ({ error: 'The ad writer did not answer. Try again in a minute.' }));
$('aiWrite').disabled = false;
if (r.error) { box.innerHTML = '<p class="small" style="margin:0">' + esc(r.error) + '</p>'; return; }
opts = r.options || [];
box.innerHTML = '<p class="small muted" style="margin:0 0 8px">Tap one to use it. Check every word is true for your offer before you post.' + (typeof r.left === 'number' ? ' Ad writes left today: ' + r.left + '.' : '') + '</p>'
+ opts.map((o, i) => '<button type="button" class="btn-soft" data-ai="' + i + '" style="display:block;width:100%;text-align:left;margin:0 0 6px"><b>' + esc(o.headline) + '</b><br><span class="small">' + esc(o.line || '') + '</span></button>').join('');
box.querySelectorAll('button[data-ai]').forEach(b => { b.onclick = () => { const o = opts[Number(b.dataset.ai)]; $('fHead').value = o.headline; $('fL1').value = o.line || ''; ['fHead', 'fL1'].forEach(id => $(id).dispatchEvent(new Event('input'))); box.hidden = true; VAB.status('Filled in. Edit it as you like, then save your ad.', 'ok'); }; });
};
}
$('spinBtn').onclick = async () => {
const box = $('spinList');
if (!box.hidden) { box.hidden = true; return; }
+2 -1
View File
@@ -67,6 +67,7 @@
<label class="f">Second line (optional) <input id="fL2" maxlength="90" autocomplete="off"><span class="cnt" id="cL2"></span></label>
<label class="f">Your link <input id="fLink" maxlength="600" autocomplete="off" inputmode="url" placeholder="https://" required></label>
<div class="spinpick" style="margin:-4px 0 4px"><button class="btn-line" type="button" id="spinBtn">Use one of my spin links</button> <span class="small muted">One free ad, every page you promote: your LinkSpin spin link rotates the traffic.</span><div id="spinList" hidden style="margin-top:10px"></div></div>
<div class="spinpick" id="aiBox" hidden style="margin:-4px 0 4px"><button class="btn-line" type="button" id="aiWrite">Write my ad from my link</button> <span class="small muted">Put your link in first. We read that page and suggest 3 ads using only what it says. Nothing is posted until you save.</span><div id="aiList" hidden style="margin-top:10px"></div></div>
<label class="chk"><input type="checkbox" id="fTrack" checked> <span><b>Track with LinkSpin</b><br><span class="small muted">Your ad link goes out as a tracked link on your own LinkSpin account, so LinkSpin Reports show its clicks. Visitors still land on your link. Untick it for programs that refuse redirected traffic.</span><span class="small" id="trackNote" hidden><br>Not needed here: your spin link is already tracked on LinkSpin.</span></span></label>
<div class="row" style="margin:0"><button class="btn-red" id="adSave" type="submit">Post my free text ad</button><span class="small muted">Tracking codes work: {clickid} and {placement} are filled on every click.</span></div>
</form>
@@ -88,6 +89,6 @@
<script src="/assets/common.js?v=9"></script>
<script src="/assets/chat.js?v=2" defer></script>
<script src="/assets/wallet.js?v=6"></script>
<script src="/assets/my.js?v=8"></script>
<script src="/assets/my.js?v=9"></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);
+2 -1
View File
@@ -49,6 +49,7 @@ listen(HUB_PORT, async (q, r, b) => {
else if (j.email) p = all.find(x => x.email === j.email);
return r.end(JSON.stringify({ person: hubView(p) }));
}
if (String(q.url).startsWith('/v1/adwriter')) return r.end(JSON.stringify({ on: true, daily: 5, left: 5 })); // the ad writer (hubadwriter.js; its own test covers the calls)
HUB.got.push({ route: q.url, body: j }); r.end('{"ok":true}');
});
// ---- stand-in InstantAdPay member lookup (only used while the hub is down) ----
@@ -476,7 +477,7 @@ const mtop = await anon.json('/api/wire?page=member&u=topdog');
pa = await M1.json('/api/my/ad', adBody(1, { link: 'https://member-1.example-shop.com/third', track: true }));
my = await M1.json('/api/my'); ok(pa.ok && pa.linkspin === 'tracked' && my.ad.spin === false && my.linkspin.state === 'tracked', 'back to an ordinary link: tracked with LinkSpin again', [pa, my.linkspin]);
const h = await (await anon.req('/my')).text(); const js = await (await anon.req('/assets/my.js?v=7')).text();
ok(/id="spinBtn"[^>]*>Use one of my spin links</.test(h) && /id="trackNote"/.test(h) && /my\.js\?v=8/.test(h) && /\/api\/my\/spins/.test(js), 'the ad form has "Use one of my spin links" and the tracking note'); }
ok(/id="spinBtn"[^>]*>Use one of my spin links</.test(h) && /id="trackNote"/.test(h) && /my\.js\?v=9/.test(h) && /id="aiWrite"/.test(h) && /\/api\/my\/spins/.test(js), 'the ad form has "Use one of my spin links" and the tracking note'); }
console.log('14c. PolHunter mission (front page, How it works)');
{ const hr = await anon.req('/'); const hh = await hr.text(); const csp = hr.headers.get('content-security-policy') || '';
+14 -1
View File
@@ -26,6 +26,7 @@ const shop = require('./shop');
const promokit = require('./promokit');
const hubreport = require('./hubreport');
const hubpeople = require('./hubpeople');
const adwriter = require('./hubadwriter'); // the network AI ad writer, asked through the hub (2026-11-17)
const hubevents = require('./hubevents'); // network hub hook (2026-11-16): sign-out-everywhere, block and erase end sessions here
const hubline = require('./hubline');
const proof = require('./proof');
@@ -269,7 +270,8 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/config' && req.method === 'GET') {
return json(res, 200, { site: C.site, siteName: C.siteName, chainId: C.chainId, chainName: C.chainName, rpc: C.publicRpc, walletConnectProjectId: C.walletConnectProjectId,
boost: C.boost, split: C.split, deliverDays: C.deliverDays, levels: C.levels, visitSeconds: C.visitSeconds, ad: C.ad, sso: networksso.enabled(),
shop: { live: shop.watching(), contract: shop.watching() ? C.contractAddress : null }, explorer: C.explorer, joinUrl: joinUrl('') });
shop: { live: shop.watching(), contract: shop.watching() ? C.contractAddress : null }, explorer: C.explorer, joinUrl: joinUrl(''),
aiWriter: await adwriter.status().then(w => (w.on ? { daily: w.daily } : null)) });
}
// everything a page shows, with its visit ticket. page=front|member|other, u=<username> for member pages
if (p === '/api/wire' && req.method === 'GET') {
@@ -394,6 +396,17 @@ const server = http.createServer(async (req, res) => {
const r = await lstrack.spins(m.username); if (r.error) return json(res, 502, { error: r.error });
return json(res, 200, { account: r.account !== false, spins: r.spins || [] });
}
// the AI ad writer (Marty 2026-11-17): 3 suggested ads written by the hub only from the member's own page; nothing is posted
if (p === '/api/my/adwriter' && req.method === 'POST') {
if (!(await adwriter.enabled())) return json(res, 503, { error: 'The ad writer is switched off right now. You can still write your ad yourself.' });
if (limited(req, 'adwriter', 12, 3600000)) return json(res, 429, { error: 'Too many ad writes from this connection this hour. Try again later, or write your ad yourself.' });
const m = store.member(me); await verifyNet(me).catch(() => {});
if (!netVerified(m)) return json(res, 403, { error: 'The ad writer is for network members. Join InstantAdPay or LinkSpin free, then sign in here through them.', join: joinUrl('') });
const b = await readBody(req);
const r = await adwriter.write(me, String(b.url || '').trim().slice(0, 600), { headline: C.ad.headline, line: C.ad.line });
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 });
}
// the member's one text ad: create, or edit (a Boost follows the ad, so editing keeps it)
if (p === '/api/my/ad' && req.method === 'POST') {
if (limited(req, 'ad', 30, 3600000)) return json(res, 429, { error: 'Too many changes this hour.' });