Link-domain pool by channel + safety checks, hosted page images + provider allowlist, Reports pages and zones sections
Item 1 (domains.js): every short link domain in linkDomains gets a channel (email / messaging / social / reserve)
via the new linkDomainChannels site setting ("host:channel,..."; default order email, messaging, social, email,
reserve). Checks every 6 h + Admin > Link domains "Check now": Google Safe Browsing v4 when GSB_API_KEY is set
(unknown otherwise), URIBL + SURBL DNS lists (answer = listed, NXDOMAIN = clean, 127.0.0.1 or errors = unknown),
and a TelegramBot-UA reachability probe. Flagged or listed = BURNED: out of domains.live() (no new links or
pages on it, existing /r/ codes still resolve), admin told once via telegramAdminChatId or ADMIN_EMAIL.
State in DATA_DIR/domains.json. New: GET /api/my/link-hosts, GET+POST /api/admin/domains, admin pane.
/api/my/pages now hands out hosts from domains.live().
Item 2 (pages.js, formrestyle.js): POST /api/my/pages/upload (raw image body, multipart, or JSON base64) for
png/jpg/webp up to 2 MB, 50 per member, magic bytes checked, sharp re-encode when installed, stored under
DATA_DIR/uploads/pages/<owner-hash>/<id>.<ext>, served at /u/pages/... immutable for a year; delete via
POST /api/my/pages/images/<id> {remove}. Pages editor: Upload image button beside the image field + a strip of
the member's images. Provider allowlist (17 autoresponders, Sendy by /subscribe path) exposed as `providers`;
the editor says "Recognised: AWeber" or "Unknown provider: plain post to <host>" at paste time; pub() carries
formProvider. Unknown hosts still allowed when parse-or-refuse passes.
Item 3 (zonereport.js, pages.summary): /api/my/reports returns {spins, pages, zones} (spins still spread at the
top level) for the chosen days; Pages and Zones sections on /reports with 30-day bars, totals, per-item tables,
phone width checked. Zone numbers are a read-only view over zones.json (zones.js untouched).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,48 @@
|
||||
(function () {
|
||||
const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt, api = CR.api, toast = CR.toast, dialog = CR.dialog;
|
||||
let PAGES = [], SEL = null, SCAN = null, TYPE = 'bridge', HOSTS = [], BASE = '';
|
||||
let STYLES = { palettes: [], designs: [], layouts: [], niches: [] };
|
||||
let STYLES = { palettes: [], designs: [], layouts: [], niches: [] }, PROVIDERS = [], IMAGES = [], IMG_MAX = 50, IMG_BYTES = 2 * 1024 * 1024;
|
||||
// which autoresponder a pasted form posts to (same list the server keeps in formrestyle.js, handed over as `providers`)
|
||||
function providerOf(embed) {
|
||||
const f = /<form\b[^>]*>/i.exec(String(embed || '')); if (!f) return null;
|
||||
const am = /\baction\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/i.exec(f[0]); const action = am ? (am[1] || am[2] || am[3]) : '';
|
||||
if (!/^https?:\/\//i.test(action)) return null;
|
||||
let u; try { u = new URL(action); } catch (e) { return null; }
|
||||
const host = u.hostname.toLowerCase().replace(/^www\./, '');
|
||||
for (const pr of PROVIDERS) { const hostHit = (pr.hosts || []).some(h => host === h || host.endsWith('.' + h)); const pathHit = pr.path ? new RegExp(pr.path, 'i').test(u.pathname) : false; if ((pr.hosts && pr.hosts.length && hostHit) || (!(pr.hosts && pr.hosts.length) && pathHit)) return { host, known: true, name: pr.name }; }
|
||||
return { host, known: false, name: '' };
|
||||
}
|
||||
function providerNote(embed) {
|
||||
const el = $('providerNote'); if (!el) return; const src = String(embed || '').trim();
|
||||
if (!src) { el.hidden = true; el.innerHTML = ''; return; }
|
||||
const pr = providerOf(src); el.hidden = false;
|
||||
if (!pr) { el.innerHTML = '<span class="warn">No https:// form action found yet.</span> Paste the whole <form> block your provider gives you.'; return; }
|
||||
el.innerHTML = pr.known ? '<span class="ok"><span class="dot"></span>Recognised: ' + esc(pr.name) + '</span> <span class="muted">Submissions go to ' + esc(pr.host) + '.</span>'
|
||||
: '<span class="warn"><span class="dot"></span>Unknown provider</span> <span class="muted">The form is kept as a plain post to <b>' + esc(pr.host) + '</b>; we cannot vouch for it. It still has to pass the form check when you save.</span>';
|
||||
}
|
||||
// the member's hosted images: a strip of thumbnails under the image field, click to use, x to delete
|
||||
function drawImages() {
|
||||
const box = $('imgStrip'); if (!box) return;
|
||||
box.innerHTML = (IMAGES.length ? IMAGES.map(i => '<span class="im" data-url="' + esc(i.url) + '" title="Use this image"><img src="' + esc(i.url) + '" alt="" loading="lazy"><button type="button" class="x" data-del="' + i.id + '" title="Delete this image">×</button></span>').join('') : '<span class="muted" style="font-size:11px">No uploads yet. PNG, JPG or WebP up to 2 MB, ' + IMG_MAX + ' per account.</span>')
|
||||
+ (IMAGES.length ? '<span class="muted mono" style="font-size:11px;align-self:center">' + IMAGES.length + '/' + IMG_MAX + '</span>' : '');
|
||||
box.querySelectorAll('.im').forEach(s => s.addEventListener('click', e => { if (e.target.closest('[data-del]')) return; const f = $('f-image'); if (f) { f.value = s.dataset.url; f.dispatchEvent(new Event('input')); toast('Image URL filled in. Save to keep it.'); } }));
|
||||
box.querySelectorAll('[data-del]').forEach(b => b.addEventListener('click', async e => { e.stopPropagation(); if (!await dialog({ title: 'Delete this image?', text: 'Pages that still point at it will show no image.', ok: 'Delete', danger: true })) return; try { const r = await api('/api/my/pages/images/' + b.dataset.del, { remove: true }); IMAGES = r.images || []; drawImages(); } catch (er) { toast(er.message, true); } }));
|
||||
}
|
||||
async function uploadFile(file) {
|
||||
if (!file) return; if (!/^image\/(png|jpeg|webp)$/.test(file.type)) return toast('Use a PNG, JPG or WebP image.', true);
|
||||
if (file.size > IMG_BYTES) return toast('That image is over 2 MB. Make it smaller and try again.', true);
|
||||
const btn = $('imgUpload'); if (btn) { btn.disabled = true; btn.textContent = 'Uploading…'; }
|
||||
try {
|
||||
const r = await (await fetch('/api/my/pages/upload', { method: 'POST', headers: { 'Content-Type': file.type }, body: file })).json(); if (r.error) throw new Error(r.error);
|
||||
IMAGES.unshift(r.image); drawImages(); const f = $('f-image'); if (f) { f.value = r.image.url; f.dispatchEvent(new Event('input')); } toast('Uploaded. Save to keep it on the page.');
|
||||
} catch (e) { toast(e.message, true); }
|
||||
if (btn) { btn.disabled = false; btn.textContent = 'Upload image'; }
|
||||
}
|
||||
CR.mount({ active: 'pages', title: 'Pages', sub: 'loading', actions: '<button class="btn pri" type="button" id="newBtn">+ New page</button>' });
|
||||
const pageUrl = p => (BASE || ('https://' + (HOSTS[0] || location.host) + '/p/')) + p.slug;
|
||||
async function load(keepSel) {
|
||||
let r; try { r = await CR.get('/api/my/pages'); } catch (e) { CR.sub('could not load'); return; }
|
||||
PAGES = r.pages || []; HOSTS = r.hosts || []; BASE = r.pageBase || ''; if (r.styles) STYLES = r.styles;
|
||||
PAGES = r.pages || []; HOSTS = r.hosts || []; BASE = r.pageBase || ''; if (r.styles) STYLES = r.styles; PROVIDERS = r.providers || []; IMAGES = r.images || []; if (r.imageMax) IMG_MAX = r.imageMax; if (r.imageBytes) IMG_BYTES = r.imageBytes;
|
||||
const pubd = PAGES.filter(p => p.status === 'published').length;
|
||||
CR.sub(PAGES.length + ' page' + (PAGES.length === 1 ? '' : 's') + ' · ' + pubd + ' live');
|
||||
const views = PAGES.reduce((n, p) => n + p.views, 0), leads = PAGES.reduce((n, p) => n + p.leads, 0), clicks = PAGES.reduce((n, p) => n + p.clicks, 0);
|
||||
@@ -45,7 +81,13 @@
|
||||
$('edPublish').textContent = p.status === 'published' ? 'Unpublish' : 'Publish'; $('edPreview').href = '/p/' + p.slug + '?preview=1';
|
||||
$('edUrl').hidden = p.status !== 'published'; $('edUrl').textContent = pageUrl(p);
|
||||
const c = p.content || {}; const v = k => k === 'ctaText' ? (c.cta && c.cta.text) || '' : k === 'ctaUrl' ? (c.cta && c.cta.url) || '' : Array.isArray(c[k]) ? c[k].join('\n') : (c[k] == null ? '' : c[k]);
|
||||
$('edFields').innerHTML = F[p.type].map(([k, label, ta]) => '<label class="lbl">' + esc(label) + (ta ? '<textarea class="field" id="f-' + k + '">' + esc(v(k)) + '</textarea>' : '<input class="field' + (/Url|image/i.test(k) ? ' mono' : '') + '" id="f-' + k + '" value="' + esc(v(k)) + '">') + '</label>').join('');
|
||||
$('edFields').innerHTML = F[p.type].map(([k, label, ta]) => '<label class="lbl">' + esc(label) + (ta ? '<textarea class="field" id="f-' + k + '">' + esc(v(k)) + '</textarea>' : '<input class="field' + (/Url|image/i.test(k) ? ' mono' : '') + '" id="f-' + k + '" value="' + esc(v(k)) + '">') + '</label>'
|
||||
// hosted images: an Upload button beside the image field (this image is the hero on bridge/review and the card image on squeeze) + the member's strip
|
||||
+ (k === 'image' ? '<div class="imgrow"><button class="btn sm" type="button" id="imgUpload">Upload image</button><input type="file" id="imgFile" accept="image/png,image/jpeg,image/webp" hidden><span class="muted" style="font-size:11px">PNG, JPG or WebP up to 2 MB. Uploading fills the URL above.</span></div><div class="imgstrip" id="imgStrip"></div>' : '')
|
||||
// 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(); }
|
||||
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); } };
|
||||
const ns = $('niche'); ns.innerHTML = '<option value="">None (set it yourself)</option>' + STYLES.niches.map(n => '<option value="' + n.key + '"' + (d.niche === n.key ? ' selected' : '') + '>' + esc(n.label) + ' \u00b7 ' + esc(n.blurb) + '</option>').join(''); ns.onchange = () => setLook({ niche: ns.value });
|
||||
|
||||
Reference in New Issue
Block a user