Admin Member content pane: every page, link, source, zone, ad, postback, upload, profile, broadcast, audience and video members made, in one list
- GET /api/admin/content?type=&q=&from=&to=&flagged=1&page=&per=&fresh=1 (admin only, read-only): content.js normalizes rows from each module's own adminAll() (new one-pass accessors in pages, rotator, sources, zones, postbacks, audiences, messages.adminBroadcasts, videomaker.adminJobs) plus ads.adminList and accounts.listAll; owner shown as @username, email and member #; created in Central time; totals per type; busiest hosts in the current view - Flags: open member reports on an ad, dead or parked destinations, burned link domains, failing postbacks, admin-paused zones, home-page demo links. No deny list exists yet - Row actions only reuse existing moderation routes (campaign pause/resume, zone pause/resume); "Open member" jumps to the member card; page Preview works for drafts and is never counted (admin allowed on ?preview=1) - Uploads: /uploads files now recorded with their uploader in uploads-index.json; older files get the owner from whatever uses them (campaign creative, profile, wall offer) - Credits > Your purchases: buys made from linked positions are included, labelled "Position N" - Cache tags: admin.css 20261018a, admin.js 20261018b, credits-screen.js 20261018b Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+3
-1
@@ -97,4 +97,6 @@ function prune() {
|
||||
// per-request closure for ads.js: opts.audienceHas(id)
|
||||
function matcher(req) { const vid = cookieVid(req), soft = softKey(req); return { vid, soft, audienceHas: id => has(id, vid, soft) }; }
|
||||
|
||||
module.exports = { init, list, create, rename, remove, owns, get, nameOf, defaultFor, hit, has, prune, flush, isId, cookieVid, newVid, cookieHeader, softKey, matcher };
|
||||
// admin Member content (2026-10-18): the audiences members made by hand (every member has an automatic one, not listed)
|
||||
function adminAll() { return Object.values(load().audiences).filter(a => !a.auto).map(a => Object.assign({}, a, sizes(a.id))); }
|
||||
module.exports = { init, adminAll, list, create, rename, remove, owns, get, nameOf, defaultFor, hit, has, prune, flush, isId, cookieVid, newVid, cookieHeader, softKey, matcher };
|
||||
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
// Member content (admin, Marty 2026-10-18): "in the admin view, I need to be able to see all the pages that are created
|
||||
// and anything else that's created by a member." One read-only list across every module that stores member-made things:
|
||||
// pages, links (rotations + destinations), traffic sources, zones, ad campaigns, postbacks, uploads, profiles (bio, avatar,
|
||||
// line banner, wall offers), sponsor broadcasts, hand-made audiences and Video Maker renders. Each module hands over its
|
||||
// own records (adminAll and friends); this file only turns them into one row shape, flags what looks wrong, and filters /
|
||||
// pages the result for GET /api/admin/content. Moderation stays where it already lives (campaign pause/resume, zone
|
||||
// pause/resume); a row only points at those routes.
|
||||
// Uploads in /uploads had no owner record before 2026-10-18: the owner is inferred from whatever references the file
|
||||
// (a campaign creative, a profile avatar or line banner, a wall offer). New uploads are noted in DATA_DIR/uploads-index.json.
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
let R = null; // { dataDir, uploadsDir, accounts, pages, rotator, sources, zones, ads, postbacks, audiences, messages, videomaker, reports, domains, adminEmail, houseOwner, linkHost(), pagesHost(), siteHost }
|
||||
function init(refs) { R = refs; }
|
||||
|
||||
const TYPES = [
|
||||
{ key: 'page', label: 'Pages' }, { key: 'link', label: 'Links' }, { key: 'source', label: 'Sources' }, { key: 'zone', label: 'Zones' },
|
||||
{ key: 'ad', label: 'Ads' }, { key: 'postback', label: 'Postbacks' }, { key: 'upload', label: 'Uploads' }, { key: 'profile', label: 'Profiles' },
|
||||
{ key: 'message', label: 'Broadcasts' }, { key: 'audience', label: 'Audiences' }, { key: 'video', label: 'Videos' }
|
||||
];
|
||||
const CT_FMT = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Chicago', year: 'numeric', month: '2-digit', day: '2-digit' });
|
||||
const ctDay = ts => ts ? CT_FMT.format(new Date(Number(ts))) : '';
|
||||
const hostOf = u => { try { return new URL(String(u || '')).hostname.toLowerCase().replace(/^www\./, ''); } catch (e) { return ''; } };
|
||||
const strip = s => String(s || '').replace(/<style[\s\S]*?<\/style>|<script[\s\S]*?<\/script>/gi, ' ').replace(/<[^>]+>/g, ' ').replace(/ /g, ' ').replace(/&/g, '&').replace(/\s+/g, ' ').trim();
|
||||
const urlsIn = s => (String(s || '').match(/https?:\/\/[^\s"'<>)]+/gi) || []).slice(0, 20);
|
||||
const UP_RE = /\/uploads\/([a-z0-9]{24}\.(?:png|jpg|webp|gif|mp4|webm))/gi;
|
||||
const parse = s => { if (!s) return null; if (typeof s === 'object') return s; try { return JSON.parse(s); } catch (e) { return null; } };
|
||||
|
||||
// -- upload index (who uploaded which /uploads file), written by server.js handleUpload from 2026-10-18 on
|
||||
const IDX = () => path.join(R.dataDir, 'uploads-index.json');
|
||||
function readIdx() { try { return JSON.parse(fs.readFileSync(IDX(), 'utf8')) || {}; } catch (e) { return {}; } }
|
||||
function noteUpload(name, who, size, type, url) {
|
||||
try { const i = readIdx(); i[String(name)] = { who: String(who || '').toLowerCase(), size: Number(size) || 0, type: type || '', url: url || '', ts: Date.now() }; fs.writeFileSync(IDX(), JSON.stringify(i)); } catch (e) {}
|
||||
}
|
||||
|
||||
// -- collect: every row, cached briefly so paging and typing in the search box stay quick
|
||||
let cache = null;
|
||||
async function collect(fresh) {
|
||||
if (!fresh && cache && Date.now() - cache.ts < 15000) return cache.rows;
|
||||
const accts = await R.accounts.listAll(1000000);
|
||||
const byEmail = {}; for (const a of accts) byEmail[String(a.email || '').toLowerCase()] = a;
|
||||
const admin = String(R.adminEmail || '').toLowerCase(), house = String(R.houseOwner || '').toLowerCase();
|
||||
const ownerOf = email => {
|
||||
const e = String(email || '').toLowerCase();
|
||||
if (e.startsWith('demo:')) return { email: '', username: '', memberId: 0, demo: true };
|
||||
const a = byEmail[e]; return { email: e, username: a && a.username || '', memberId: a && a.memberId || 0 };
|
||||
};
|
||||
const burned = h => { try { return !!h && !!R.domains.isBurned(h); } catch (e) { return false; } };
|
||||
const linkHost = R.linkHost() || R.siteHost; const pagesHost = R.pagesHost();
|
||||
const rows = [];
|
||||
const add = r => {
|
||||
r.owner = ownerOf(r.ownerEmail); delete r.ownerEmail;
|
||||
r.flags = r.flags || []; r.actions = r.actions || []; r.counts = r.counts || {};
|
||||
r.hosts = Array.from(new Set((r.hosts || []).filter(Boolean)));
|
||||
for (const h of r.hosts) if (burned(h)) r.flags.push({ k: 'burned', t: h + ' is a burned link domain' });
|
||||
r.day = ctDay(r.created);
|
||||
r.text = [r.type, r.id, r.owner.email, r.owner.username, r.owner.username ? '@' + r.owner.username : '', r.owner.memberId ? '#' + r.owner.memberId : '', r.title, r.url, r.status].concat(r.hosts, r.search || []).join(' ').toLowerCase();
|
||||
delete r.search; rows.push(r);
|
||||
};
|
||||
|
||||
// pages
|
||||
for (const p of R.pages.adminAll()) add({ type: 'page', id: p.id, ownerEmail: p.owner, title: p.title, created: p.created, updated: p.updated,
|
||||
status: p.status === 'published' ? 'live' : 'draft', live: p.status === 'published',
|
||||
url: pagesHost ? 'https://' + pagesHost + '/' + p.slug : 'https://' + linkHost + '/p/' + p.slug, open: '/p/' + p.slug + '?preview=1',
|
||||
detail: { kind: p.type, slug: p.slug, headline: p.headline, sub: p.sub, ctaUrl: p.ctaUrl, ctaText: p.ctaText, image: p.image, formProvider: p.formProvider, scanUrl: p.scanUrl, body: p.body.slice(0, 280) },
|
||||
counts: { views: p.views, uniques: p.uniques, clicks: p.clicks, leads: p.leads }, hosts: [hostOf(p.ctaUrl), hostOf(p.scanUrl)],
|
||||
search: [p.slug, p.headline, p.sub, p.body, p.bonus, p.angle, p.ctaUrl, p.scanUrl, p.image] });
|
||||
|
||||
// links (rotations)
|
||||
for (const r of R.rotator.adminAll()) {
|
||||
const flags = [];
|
||||
const sick = r.destinations.filter(d => d.autoPaused || (d.health && (d.health.state === 'dead' || d.health.state === 'parked')));
|
||||
if (sick.length) flags.push({ k: 'health', t: sick.length + ' destination' + (sick.length > 1 ? 's' : '') + ' dead or parked' });
|
||||
if (r.demo) flags.push({ k: 'demo', t: 'Home-page demo spin (no account yet)' });
|
||||
const live = !r.paused && (r.destinations.some(d => d.active) || !!r.fallback);
|
||||
add({ type: 'link', id: String(r.id), ownerEmail: r.owner, title: r.name, created: r.created, status: r.paused ? 'paused' : live ? 'live' : 'empty', live,
|
||||
url: 'https://' + linkHost + '/r/' + r.code, open: null,
|
||||
detail: { code: r.code, fallback: r.fallback, dayparted: r.dayparted, sourceId: r.sourceId, expires: r.expires, destinations: r.destinations.map(d => ({ url: d.url, label: d.label, weight: d.weight, active: d.active, autoPaused: !!d.autoPaused, health: d.health ? d.health.state : '' })) },
|
||||
counts: { clicks7: r.hits7, clicks: r.hits, bots: r.bots, conversions: r.conversions }, hosts: r.destinations.map(d => hostOf(d.url)).concat(hostOf(r.fallback)), flags,
|
||||
search: [r.code].concat(r.destinations.map(d => d.url + ' ' + (d.label || '')), r.fallback) });
|
||||
}
|
||||
|
||||
// traffic sources
|
||||
for (const s of R.sources.adminAll()) add({ type: 'source', id: s.id, ownerEmail: s.owner, title: s.name, created: s.created, status: s.enabled ? 'live' : 'off', live: !!s.enabled, url: s.site ? 'https://' + s.site : '', open: null,
|
||||
detail: { template: s.template, site: s.site, costModel: s.costModel, postbackUrl: s.postbackUrl, method: s.method, events: s.events, params: (s.params || []).length, lastStatus: s.lastStatus },
|
||||
counts: { sent: s.sent, fails: s.fails }, hosts: [hostOf(s.postbackUrl)], search: [s.template, s.site, s.postbackUrl] });
|
||||
|
||||
// zones (moderation: the existing admin pause / resume)
|
||||
for (const z of R.zones.adminAll()) add({ type: 'zone', id: z.id, ownerEmail: z.owner, title: z.name, created: z.created, status: z.paused ? 'paused' : !z.active ? 'off' : z.status, live: z.active && !z.paused,
|
||||
url: 'https://' + z.site, open: 'https://' + z.site,
|
||||
detail: { site: z.site, size: z.size, tier: z.tier, statusLabel: z.statusLabel, note: z.note, lastSeen: z.lastSeen },
|
||||
counts: { views30: z.views30, viewablePct: z.viewablePct, clicks30: z.clicks30, offsite30: z.offsite30, credits: z.credits }, hosts: [z.site],
|
||||
flags: z.paused ? [{ k: 'paused', t: 'Paused by admin' + (z.note ? ': ' + z.note : '') }] : [],
|
||||
actions: [z.paused ? { label: 'Resume zone', path: '/api/admin/zones/' + z.id, body: { paused: false, note: '' } } : { label: 'Pause zone', path: '/api/admin/zones/' + z.id, body: { paused: true, note: 'Paused from Member content ' + ctDay(Date.now()) }, warn: 'Pause this zone? It will serve the house banner only and earn nothing.' }],
|
||||
search: [z.site, z.size, z.note] });
|
||||
|
||||
// ad campaigns (member campaigns only; house ads are the admin's own); open member reports flag the row
|
||||
const open = {}; try { for (const x of await R.reports.list(5000)) if (!x.resolved) (open[x.campaignId] = open[x.campaignId] || []).push(x); } catch (e) {}
|
||||
for (const c of await R.ads.adminList(1000000)) {
|
||||
if (c.house || String(c.owner || '').toLowerCase() === house) continue;
|
||||
const reps = open[c.id] || []; const flags = reps.length ? [{ k: 'reported', t: reps.length + ' open report' + (reps.length > 1 ? 's' : '') + ': ' + Array.from(new Set(reps.map(x => x.reason))).join(', ') }] : [];
|
||||
const body = strip(c.body).slice(0, 300);
|
||||
add({ type: 'ad', id: String(c.id), ownerEmail: c.owner, title: c.name, created: c.created, status: c.scheduled ? 'scheduled' : c.status, live: c.status === 'active' && !c.scheduled, url: c.targetUrl, open: c.targetUrl,
|
||||
detail: { adType: c.type, imageUrl: c.imageUrl, title: c.title, body, width: c.width, height: c.height, budget: c.budget, spent: c.spent, starts: c.starts, expires: c.expires, geo: c.geo, dailyCap: c.dailyCap, audience: c.audience },
|
||||
counts: { imps: c.imps, impsNas: c.impsNas, clicks: c.clicks }, hosts: [hostOf(c.targetUrl)].concat(urlsIn(c.body).map(hostOf)), flags,
|
||||
actions: c.status === 'active' ? [{ label: 'Pause ad', path: '/api/admin/campaigns/' + c.id + '/pause', body: {}, warn: 'Pause campaign #' + c.id + '? It stops serving until resumed.' }] : c.status === 'paused' ? [{ label: 'Resume ad', path: '/api/admin/campaigns/' + c.id + '/resume', body: {} }] : [],
|
||||
search: [c.type, c.targetUrl, c.imageUrl, c.title, body] });
|
||||
}
|
||||
|
||||
// postbacks
|
||||
for (const p of R.postbacks.adminAll()) add({ type: 'postback', id: p.id, ownerEmail: p.owner, title: p.name, created: p.created, status: p.enabled ? 'live' : 'off', live: !!p.enabled, url: '', open: null,
|
||||
detail: { postbackUrl: p.url, method: p.method, events: p.events, lastStatus: p.lastStatus, lastAt: p.lastAt },
|
||||
counts: { sent: p.sent, fails: p.fails }, hosts: [hostOf(p.url)], flags: p.fails >= 5 ? [{ k: 'failing', t: p.fails + ' failed deliveries in a row' }] : [], search: [p.url] });
|
||||
|
||||
// profiles: bio, avatar, socials, line banner, wall offers (public on the member's wall and welcome tours)
|
||||
const refs = {}; const ref = (name, email, where) => { const k = name.toLowerCase(); const o = refs[k] = refs[k] || { email, where: [] }; if (!o.email) o.email = email; if (o.where.length < 6) o.where.push(where); };
|
||||
for (const a of accts) {
|
||||
const socials = parse(a.socials) || {}; const offers = (parse(a.wallOffers) || []).filter(Boolean);
|
||||
const blob = JSON.stringify([a.avatarUrl, a.lineBannerUrl, offers]); let m; UP_RE.lastIndex = 0; while ((m = UP_RE.exec(blob))) ref(m[1], a.email, 'profile of ' + (a.username ? '@' + a.username : a.email));
|
||||
if (!(a.bio || a.avatarUrl || Object.keys(socials).length || a.lineBannerUrl || a.lineTargetUrl || offers.length)) continue;
|
||||
const who = a.username || a.code || '';
|
||||
add({ type: 'profile', id: a.email, ownerEmail: a.email, title: (a.username ? '@' + a.username : a.email) + ' profile', created: a.created, status: 'live', live: true, url: who ? 'https://' + R.siteHost + '/wall/' + who : '', open: who ? '/wall/' + who : null,
|
||||
detail: { bio: String(a.bio || '').slice(0, 600), avatarUrl: a.avatarUrl, socials, lineBannerUrl: a.lineBannerUrl, lineTargetUrl: a.lineTargetUrl, wallOffers: offers },
|
||||
hosts: [hostOf(a.lineTargetUrl), socials.website ? hostOf(socials.website) : ''].concat(offers.map(o => hostOf(o.targetUrl))),
|
||||
search: [a.bio, a.lineTargetUrl, a.lineBannerUrl].concat(Object.values(socials), offers.map(o => (o.title || '') + ' ' + o.targetUrl)) });
|
||||
}
|
||||
|
||||
// uploads: page images (pages index knows the owner) + /uploads files (owner from the upload index or from what uses them)
|
||||
for (const i of R.pages.adminImages()) add({ type: 'upload', id: i.id, ownerEmail: i.owner, title: 'Page image ' + i.id, created: i.ts, status: 'stored', live: true, url: i.path, open: i.path,
|
||||
detail: { file: i.path, size: i.size, mime: i.type, store: 'Page images', image: true }, search: [i.path] });
|
||||
try {
|
||||
const camps = await R.ads.adminList(1000000);
|
||||
for (const c of camps) { if (c.house) continue; const blob = JSON.stringify([c.imageUrl, c.body]); let m; UP_RE.lastIndex = 0; while ((m = UP_RE.exec(blob))) ref(m[1], c.owner, 'campaign #' + c.id + ' (' + c.type + ')'); }
|
||||
} catch (e) {}
|
||||
const idx = readIdx();
|
||||
let files = []; try { files = fs.readdirSync(R.uploadsDir).filter(f => /^[a-z0-9]{24}\.(png|jpg|webp|gif|mp4|webm)$/i.test(f)); } catch (e) {}
|
||||
const seenUp = new Set();
|
||||
for (const f of files) {
|
||||
let st = null; try { st = fs.statSync(path.join(R.uploadsDir, f)); } catch (e) { continue; }
|
||||
const k = f.toLowerCase(); seenUp.add(k); const ix = idx[f] || {}; const rf = refs[k];
|
||||
if (ix.who === 'admin' && !rf) continue; // house-ad creative the admin uploaded
|
||||
const owner = ix.who && ix.who !== 'admin' ? ix.who : rf ? rf.email : '';
|
||||
const isVid = /\.(mp4|webm)$/i.test(f);
|
||||
add({ type: 'upload', id: f, ownerEmail: owner, title: (isVid ? 'Video ' : 'Image ') + f, created: ix.ts || st.mtimeMs, status: rf ? 'in use' : 'unused', live: !!rf, url: '/uploads/' + f, open: '/uploads/' + f,
|
||||
detail: { file: '/uploads/' + f, size: st.size, mime: isVid ? 'video' : 'image', store: 'Uploads', image: !isVid, usedBy: rf ? rf.where : [], ownerGuess: !ix.who && !!rf },
|
||||
search: [f].concat(rf ? rf.where : []) });
|
||||
}
|
||||
for (const [f, ix] of Object.entries(idx)) { // videos that went to Spaces (no local file)
|
||||
if (seenUp.has(f.toLowerCase()) || !ix.url || !/^https?:/i.test(ix.url) || ix.who === 'admin') continue;
|
||||
add({ type: 'upload', id: f, ownerEmail: ix.who, title: 'Video ' + f, created: ix.ts, status: 'stored', live: true, url: ix.url, open: ix.url, detail: { file: ix.url, size: ix.size, mime: 'video', store: 'Spaces', image: false }, search: [ix.url] });
|
||||
}
|
||||
|
||||
// sponsor broadcasts (members writing to their line); system senders left out
|
||||
try {
|
||||
for (const b of await R.messages.adminBroadcasts(3000)) {
|
||||
if (!b.fromEmail || b.fromEmail === admin || b.fromEmail === house) continue;
|
||||
const body = strip(b.body);
|
||||
add({ type: 'message', id: b.fromEmail + ':' + b.sent, ownerEmail: b.fromEmail, title: b.subject || '(no subject)', created: b.sent, status: 'sent', live: true, url: '', open: null,
|
||||
detail: { body: body.slice(0, 600), recipients: b.recipients }, counts: { recipients: b.recipients }, hosts: urlsIn(b.body).map(hostOf), search: [body] });
|
||||
}
|
||||
} catch (e) { console.error('content broadcasts', e.message); }
|
||||
|
||||
// audiences made by hand
|
||||
for (const a of R.audiences.adminAll()) add({ type: 'audience', id: a.id, ownerEmail: a.owner, title: a.name, created: a.created, status: 'live', live: true, url: '', open: null,
|
||||
detail: { audienceId: a.id, pixel: '<script src="https://' + R.siteHost + '/p.js" data-aud="' + a.id + '"></script>' }, counts: { size30: a.size30, size7: a.size7 }, search: [a.id] });
|
||||
|
||||
// Video Maker renders (the company promo with the member's own end card)
|
||||
for (const j of R.videomaker.adminJobs()) add({ type: 'video', id: j.id, ownerEmail: j.email, title: j.title, created: j.at, status: j.status, live: j.status === 'done', url: j.url || '', open: j.url || null,
|
||||
detail: { slug: j.slug, username: j.username, error: j.error || '', doneAt: j.doneAt || 0 }, search: [j.slug, j.username] });
|
||||
|
||||
cache = { ts: Date.now(), rows }; return rows;
|
||||
}
|
||||
|
||||
// -- the API: GET /api/admin/content?type=&q=&from=&to=&flagged=1&page=&per=&fresh=1
|
||||
async function query(o) {
|
||||
o = o || {};
|
||||
const rows = await collect(!!o.fresh);
|
||||
const totals = {}; for (const t of TYPES) totals[t.key] = { n: 0, live: 0, flagged: 0 };
|
||||
let flaggedAll = 0; for (const r of rows) { const t = totals[r.type]; if (!t) continue; t.n++; if (r.live) t.live++; if (r.flags.length) { t.flagged++; flaggedAll++; } }
|
||||
const type = TYPES.some(t => t.key === o.type) ? o.type : 'all';
|
||||
const day = s => /^\d{4}-\d{2}-\d{2}$/.test(String(s || '')) ? String(s) : '';
|
||||
const from = day(o.from), to = day(o.to);
|
||||
const terms = String(o.q || '').toLowerCase().split(/\s+/).filter(Boolean).slice(0, 8);
|
||||
let list = rows.filter(r => (type === 'all' || r.type === type) && (!o.flagged || r.flags.length) && (!from || (r.day && r.day >= from)) && (!to || (r.day && r.day <= to)) && terms.every(t => r.text.includes(t)));
|
||||
list.sort((a, b) => (Number(b.created) || 0) - (Number(a.created) || 0));
|
||||
const hc = {}; for (const r of list) for (const h of r.hosts) hc[h] = (hc[h] || 0) + 1;
|
||||
const hosts = Object.entries(hc).sort((a, b) => b[1] - a[1]).slice(0, 15).map(([host, n]) => ({ host, n, burned: (() => { try { return !!R.domains.isBurned(host); } catch (e) { return false; } })() }));
|
||||
const per = Math.max(10, Math.min(200, Number(o.per) || 50)); const pages = Math.max(1, Math.ceil(list.length / per));
|
||||
const page = Math.max(1, Math.min(pages, Number(o.page) || 1));
|
||||
const items = list.slice((page - 1) * per, page * per).map(r => { const x = Object.assign({}, r); delete x.text; return x; });
|
||||
return { types: TYPES, type, totals, all: rows.length, flaggedAll, matched: list.length, page, pages, per, items, hosts, denyList: false, generated: cache ? cache.ts : Date.now() };
|
||||
}
|
||||
function invalidate() { cache = null; }
|
||||
module.exports = { init, TYPES, query, collect, invalidate, noteUpload };
|
||||
+13
-1
@@ -197,5 +197,17 @@ async function reclassifyCarryNotices(fromEmail) {
|
||||
if (n) J.save();
|
||||
return n;
|
||||
}
|
||||
module.exports = { init, lastFrom, lastBroadcastAt, deliver, inbox, unreadCount, newestUnread, markRead,
|
||||
// admin Member content (2026-10-18): the broadcasts members wrote, one row per send (deliver() stores one row per recipient).
|
||||
// Human broadcasts only: system notices / alerts and the private 1:1 chats are left out.
|
||||
async function adminBroadcasts(limit) {
|
||||
const lim = Math.max(1, Math.min(5000, Number(limit) || 2000));
|
||||
if (db.enabled()) {
|
||||
const rows = await db.q("SELECT from_member, from_email, subject, MAX(body) body, sent, COUNT(*) n FROM sponsor_messages WHERE (kind='broadcast' OR kind IS NULL) GROUP BY from_member, from_email, subject, sent ORDER BY sent DESC LIMIT ?", [lim]);
|
||||
return rows.map(r => ({ fromMember: Number(r.from_member) || 0, fromEmail: String(r.from_email || '').toLowerCase(), subject: r.subject || '', body: String(r.body || ''), sent: Number(r.sent) || 0, recipients: Number(r.n) || 0 }));
|
||||
}
|
||||
if (!J.db) J.load(); const g = new Map();
|
||||
for (const i of J.db.items) { if ((i.kind || 'broadcast') !== 'broadcast') continue; const k = (i.fromEmail || '') + '\u0000' + (i.subject || '') + '\u0000' + i.sent; const o = g.get(k); if (o) o.recipients++; else g.set(k, { fromMember: Number(i.fromMember) || 0, fromEmail: String(i.fromEmail || '').toLowerCase(), subject: i.subject || '', body: String(i.body || ''), sent: i.sent || 0, recipients: 1 }); }
|
||||
return Array.from(g.values()).sort((a, b) => b.sent - a.sent).slice(0, lim);
|
||||
}
|
||||
module.exports = { init, adminBroadcasts, lastFrom, lastBroadcastAt, deliver, inbox, unreadCount, newestUnread, markRead,
|
||||
sendChat, thread, markChatRead, chatUnread, threadList, reclassifyCarryNotices };
|
||||
|
||||
@@ -253,4 +253,14 @@ async function removeImage(owner, id) {
|
||||
}
|
||||
// the file behind /u/pages/<hash>/<id>.<ext>, only when the index knows it (never a raw directory read)
|
||||
function imageFile(hash, id, ext) { const i = J.db.images.find(x => x.h === String(hash) && x.id === String(id) && x.ext === String(ext)); return i ? { file: path.join(DATA_DIR, 'uploads', 'pages', i.h, i.id + '.' + i.ext), mime: i.mime } : null; }
|
||||
module.exports = { init, TYPES, list, get, bySlug, create, update, html, view, lead, leads, csv, scan, write, totals, summary, readUpload, uploadImage, images, removeImage, imageFile, IMG_MAX, IMG_BYTES, providers: () => formrestyle.PROVIDERS, provider: formrestyle.provider };
|
||||
// -- admin Member content (2026-10-18): every page and every hosted image, all owners; counts in one pass over the views
|
||||
function adminAll() {
|
||||
const by = {}; for (const v of J.db.views) { const o = by[v.p] = by[v.p] || { views: 0, u: new Set(), clicks: 0 }; if (v.k === 'cta') o.clicks++; else { o.views++; o.u.add(v.v); } }
|
||||
const ld = {}; for (const l of J.db.leads) ld[l.p] = (ld[l.p] || 0) + 1;
|
||||
return J.db.pages.map(p => { const o = by[p.id] || { views: 0, u: new Set(), clicks: 0 }; const c = p.content || {};
|
||||
return { id: p.id, owner: p.owner, slug: p.slug, type: p.type, title: p.title, status: p.status, created: p.created, updated: p.updated, angle: p.angle || '', scanUrl: p.scan && p.scan.url || '',
|
||||
headline: c.headline || '', sub: c.sub || '', body: String(c.body || '').slice(0, 600), ctaUrl: c.cta && c.cta.url || '', ctaText: c.cta && c.cta.text || '', image: c.image || '', bonus: String(c.bonus || '').slice(0, 300),
|
||||
formProvider: p.type === 'squeeze' && c.formEmbed ? formrestyle.provider(c.formEmbed) : null, views: o.views, uniques: o.u.size, clicks: o.clicks, leads: ld[p.id] || 0 }; });
|
||||
}
|
||||
function adminImages() { return J.db.images.map(i => Object.assign(pubImage(i), { owner: i.owner })); }
|
||||
module.exports = { init, TYPES, list, get, bySlug, create, update, html, view, lead, leads, csv, scan, write, totals, summary, readUpload, uploadImage, images, removeImage, imageFile, IMG_MAX, IMG_BYTES, providers: () => formrestyle.PROVIDERS, provider: formrestyle.provider, adminAll, adminImages };
|
||||
|
||||
+3
-1
@@ -150,4 +150,6 @@ async function inbound(key, body) {
|
||||
try { await fire(owner, event, ctx); } catch (e) {}
|
||||
return { ok: true, recorded: event, lsid };
|
||||
}
|
||||
module.exports = { init, EVENTS, validateUrl, fill, deliver, list, create, update, logFor, logForSource, partnerKey, rotateKey, bindClick, clickOf, fire, test, convertFor, inbound };
|
||||
// admin Member content (2026-10-18): every postback of every owner
|
||||
function adminAll() { return J.db.items.map(p => Object.assign(pubItem(p), { owner: p.owner })); }
|
||||
module.exports = { init, adminAll, EVENTS, validateUrl, fill, deliver, list, create, update, logFor, logForSource, partnerKey, rotateKey, bindClick, clickOf, fire, test, convertFor, inbound };
|
||||
|
||||
+23
-2
@@ -9,7 +9,7 @@
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261018c">
|
||||
<style>@import url("/assets/site.css?v=ls20260916a") layer(legacy);</style>
|
||||
<link rel="stylesheet" href="/assets/tools.css?v=20261008a">
|
||||
<link rel="stylesheet" href="/assets/admin.css?v=20261012a">
|
||||
<link rel="stylesheet" href="/assets/admin.css?v=20261018a">
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
@@ -44,6 +44,7 @@
|
||||
<button data-pane="house" class="nb" type="button" title="House ads"><svg viewBox="0 0 24 24"><path d="M3 11l14-5v12L3 13v-2z"/><path d="M17 8a4 4 0 0 1 0 8M7 13v5a2 2 0 0 0 4 0v-3"/></svg><span class="lbl">House ads</span></button>
|
||||
<button data-pane="campaigns" class="nb" type="button" title="All campaigns"><svg viewBox="0 0 24 24"><path d="M4 6h16M4 12h16M4 18h10"/></svg><span class="lbl">All campaigns</span></button>
|
||||
<button data-pane="members" class="nb" type="button" title="Members"><svg viewBox="0 0 24 24"><circle cx="12" cy="7" r="3.2"/><circle cx="5" cy="17" r="2.6"/><circle cx="19" cy="17" r="2.6"/><path d="M12 10v3M12 13l-5 2M12 13l5 2"/></svg><span class="lbl">Members</span></button>
|
||||
<button data-pane="content" class="nb" type="button" title="Member content"><svg viewBox="0 0 24 24"><path d="M12 3l9 5-9 5-9-5z"/><path d="M3 13l9 5 9-5"/><path d="M3 17.5l9 5 9-5" opacity=".55"/></svg><span class="lbl">Member content</span><span class="pill" id="ctBadge" hidden></span></button>
|
||||
<button data-pane="reports" class="nb" type="button" title="Reports"><svg viewBox="0 0 24 24"><path d="M12 3l9 16H3z"/><path d="M12 10v4M12 17v.5"/></svg><span class="lbl">Reports</span><span class="pill" id="repBadge" hidden></span></button>
|
||||
<button data-pane="traffic" class="nb" type="button" title="Traffic"><svg viewBox="0 0 24 24"><path d="M3 17l6-6 4 4 8-8"/><path d="M14 7h7v7"/></svg><span class="lbl">Traffic</span></button>
|
||||
<button data-pane="zones" class="nb" type="button" title="Zones"><svg viewBox="0 0 24 24"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 10h18M8 15h8"/></svg><span class="lbl">Zones</span></button>
|
||||
@@ -216,6 +217,26 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pane" id="pane-content" hidden>
|
||||
<div class="ct-totals" id="ctTotals"></div>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Everything members made</h3><span class="sub" id="ctSub">newest first</span></div>
|
||||
<div class="ct-tabs" id="ctTabs" role="tablist" aria-label="Content type"></div>
|
||||
<div class="ct-filters">
|
||||
<input id="ctQ" type="search" autocomplete="off" placeholder="Search owner, @username, member #, URL, domain or text">
|
||||
<label class="small">From <input type="date" id="ctFrom"></label>
|
||||
<label class="small">To <input type="date" id="ctTo"></label>
|
||||
<label class="ct-chk small"><input type="checkbox" id="ctFlagged"> Flagged only</label>
|
||||
<button type="button" class="btn small sec" id="ctClear">Clear</button>
|
||||
<button type="button" class="btn small sec" id="ctRefresh">Refresh</button>
|
||||
</div>
|
||||
<p class="small muted" id="ctNote" style="margin:8px 0 6px">Dates are Central time. Flags: open member reports on an ad, a destination that failed its health check, a host that is one of our burned link domains, failing postbacks, admin-paused zones and home-page demo links. LinkSpin has no destination deny list yet, so the busiest hosts below are the quickest way to spot a cluster: click one to filter by it. Opening a short link counts as a click on it; page previews are never counted.</p>
|
||||
<div class="ct-hosts" id="ctHosts"></div>
|
||||
<div class="tablewrap"><table class="adm-table ct-table" id="ctTable"></table></div>
|
||||
<div class="ct-pager" id="ctPager"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pane" id="pane-reports" hidden>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Counters audit</h3><span class="sub" id="audSub">views vs delivery logs, charges vs shows</span></div>
|
||||
@@ -451,6 +472,6 @@
|
||||
</div>
|
||||
|
||||
<script src="/assets/common.js?v=20261016a"></script>
|
||||
<script src="/assets/admin.js?v=20261018a"></script>
|
||||
<script src="/assets/admin.js?v=20261018b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -130,6 +130,42 @@ textarea.json{font-family:var(--mono);font-size:12px;width:100%;min-height:260px
|
||||
.kv-row input[type=checkbox]{width:auto;justify-self:start}
|
||||
.ed-bar button{font-size:12px}
|
||||
|
||||
/* member content (2026-10-18): type tiles, tabs, filters, busiest hosts, one row per item */
|
||||
.ct-totals{display:grid;grid-template-columns:repeat(auto-fill,minmax(132px,1fr));gap:10px;margin:0 0 16px}
|
||||
.ct-tile{text-align:left;cursor:pointer;font:inherit;color:inherit;display:block;width:100%}
|
||||
.ct-tile .nv{font-size:22px;font-weight:700;font-family:var(--display);color:var(--ink)}
|
||||
.ct-tile .lb{font-size:12px;font-weight:700;color:var(--ink-2);margin:2px 0}
|
||||
.ct-tile:hover{border-color:var(--accent)}
|
||||
.ct-tile.on{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent-soft)}
|
||||
.ct-tabs{display:flex;gap:6px;flex-wrap:wrap;margin:0 0 10px}
|
||||
.ct-filters{display:flex;gap:8px 10px;flex-wrap:wrap;align-items:center}
|
||||
.ct-filters #ctQ{flex:1 1 260px;min-width:0}
|
||||
.ct-filters label.small{display:flex;align-items:center;gap:6px;font-weight:600;color:var(--ink-2)}
|
||||
.ct-filters input[type=date]{width:auto}
|
||||
.ct-filters .ct-chk input{width:auto;margin:0}
|
||||
.ct-hosts{display:flex;gap:6px;flex-wrap:wrap;align-items:center;margin:0 0 10px}
|
||||
.ct-hosts .chip-t{font-family:var(--mono);text-transform:none;letter-spacing:0;font-size:11px}
|
||||
.ct-hosts .chip-t.bad{border-color:rgba(185,28,28,.5);color:var(--bad);background:var(--bad-soft)}
|
||||
.ct-table .ct-type{font:700 10.5px var(--mono);letter-spacing:.06em;text-transform:uppercase;color:var(--accent-hi);white-space:nowrap}
|
||||
.ct-table .ct-title{font-weight:700;margin:0 0 3px;overflow-wrap:anywhere}
|
||||
.ct-table td{overflow-wrap:anywhere}
|
||||
.ct-table .ct-l{font-size:12.5px;color:var(--ink-2);margin:2px 0;line-height:1.45}
|
||||
.ct-table .ct-flags{margin:2px 0 4px;display:flex;gap:4px;flex-wrap:wrap}
|
||||
.ct-table .ct-flags .st{text-transform:none;letter-spacing:0;font-family:var(--body);font-size:11px}
|
||||
.ct-table tr.ct-flagged td{background:rgba(185,28,28,.035)}
|
||||
.ct-table .ct-nums div{white-space:nowrap}
|
||||
.ct-table td[data-l="Status"] .st{white-space:nowrap}
|
||||
.ct-table .ct-mem{font-weight:700}
|
||||
.ct-table td[data-l="Owner"]{min-width:180px;overflow-wrap:break-word}
|
||||
.ct-table .ct-dest{display:inline-block;margin:0 8px 2px 0;font-size:12px}
|
||||
.ct-table .ct-dest.off a{text-decoration:line-through;opacity:.7}
|
||||
.ct-table .bad{color:var(--bad)}
|
||||
.ct-thumb{display:inline-block;vertical-align:middle;border:1px solid var(--line);border-radius:4px;overflow:hidden;background:var(--panel-2);line-height:0}
|
||||
.ct-thumb img{max-height:40px;max-width:90px;display:block}
|
||||
.ct-thumb.big img{max-height:64px;max-width:240px}
|
||||
.ct-pager{display:flex;gap:12px;align-items:center;justify-content:center;margin:12px 0 0}
|
||||
.ct-pager:empty{display:none}
|
||||
|
||||
/* phone: the rail is a scrolling bottom bar with icon + label (twelve admin panes do not fit side by side) */
|
||||
@media (max-width:760px){
|
||||
.adm .rail{justify-content:flex-start;overflow-x:auto;overflow-y:hidden;gap:2px;scrollbar-width:none}
|
||||
@@ -149,4 +185,17 @@ textarea.json{font-family:var(--mono);font-size:12px;width:100%;min-height:260px
|
||||
.kv-row{grid-template-columns:1fr} .kv-row .btn{justify-self:start}
|
||||
.adm .pane [style*="grid-template-columns:1fr 1fr"]{grid-template-columns:1fr!important}
|
||||
.trunc{max-width:160px}
|
||||
.ct-totals{grid-template-columns:repeat(3,minmax(0,1fr));gap:6px}
|
||||
.ct-tile.statx{padding:8px 10px} .ct-tile .nv{font-size:17px} .ct-tile .lb{font-size:10.5px}
|
||||
.ct-table,.ct-table tbody,.ct-table tr,.ct-table td{display:block;width:100%}
|
||||
.ct-table tr:first-child{display:none}
|
||||
.ct-table tr{border-bottom:1px solid var(--line);padding:8px 0}
|
||||
.ct-table td{border:0;padding:3px 12px}
|
||||
.ct-table td[data-l]::before{content:attr(data-l);display:block;font:700 9.5px var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--muted)}
|
||||
.ct-table td[data-l="Type"]::before{display:none}
|
||||
.ct-table td.act{width:auto}
|
||||
.ct-table .ct-nums{display:flex;flex-wrap:wrap;gap:2px 12px}
|
||||
.ct-table .ct-nums::before{flex-basis:100%}
|
||||
.ct-filters label.small{flex:1 1 140px}
|
||||
.ct-filters input[type=date]{flex:1;min-width:0}
|
||||
}
|
||||
|
||||
+121
-2
@@ -44,8 +44,8 @@
|
||||
});
|
||||
|
||||
// ── panes ──
|
||||
const TITLES = { overview: 'Overview', house: 'House ads', campaigns: 'All campaigns', members: 'Members', reports: 'Reports', zones: 'Zones', domains: 'Link domains', traffic: 'Traffic', blog: 'Blog', releases: 'Releases and roadmap', pnl: 'Profit and loss', settings: 'Settings' };
|
||||
const loaders = { overview: loadOverview, house: loadHouse, campaigns: loadCampaigns, members: loadMembers, reports: loadReports, zones: loadZones, domains: loadDomains, traffic: loadTraffic, blog: loadBlog, releases: loadReleases, pnl: loadPnl, settings: loadSettings };
|
||||
const TITLES = { overview: 'Overview', house: 'House ads', campaigns: 'All campaigns', members: 'Members', content: 'Member content', reports: 'Reports', zones: 'Zones', domains: 'Link domains', traffic: 'Traffic', blog: 'Blog', releases: 'Releases and roadmap', pnl: 'Profit and loss', settings: 'Settings' };
|
||||
const loaders = { overview: loadOverview, house: loadHouse, campaigns: loadCampaigns, members: loadMembers, content: loadContent, reports: loadReports, zones: loadZones, domains: loadDomains, traffic: loadTraffic, blog: loadBlog, releases: loadReleases, pnl: loadPnl, settings: loadSettings };
|
||||
function setPane(name) {
|
||||
if (!TITLES[name]) name = 'overview';
|
||||
document.querySelectorAll('.pane').forEach(p => { p.hidden = p.id !== 'pane-' + name; });
|
||||
@@ -503,6 +503,125 @@
|
||||
try { await api('/api/admin/zones/' + s.dataset.zntier + '/tier', { tier: s.value }, 'POST'); IAP.status('Tier saved: ' + s.value, 'ok'); loadZones(); } catch (e) { IAP.status(e.message, 'bad'); loadZones(); }
|
||||
}));
|
||||
}
|
||||
// ── member content (Marty, 2026-10-18): everything members made in one list, newest first. Read-only: the only
|
||||
// buttons are the moderation routes that already exist (campaign pause / resume, zone pause / resume) ──
|
||||
const CT = { type: 'all', page: 1, data: null, timer: 0 };
|
||||
const ctN = v => Number(v || 0).toLocaleString();
|
||||
const ctWhen = ts => ts ? new Date(Number(ts)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : '';
|
||||
const ctSize = b => (b || 0) >= 1048576 ? (b / 1048576).toFixed(1) + ' MB' : Math.max(1, Math.round((b || 0) / 1024)) + ' KB';
|
||||
const ctSafe = u => /^(https?:\/\/|\/(?!\/))/i.test(String(u || '')) ? String(u) : ''; // member URLs: http(s) or our own paths, never javascript:
|
||||
const ctA = (u, text) => { const h = ctSafe(u); return h ? '<a href="' + esc(h) + '" target="_blank" rel="noopener noreferrer">' + esc(text == null ? h : text) + '</a>' : (u ? esc(text == null ? u : text) : ''); };
|
||||
const ctImg = (u, big) => { const h = ctSafe(u); return h ? '<a href="' + esc(h) + '" target="_blank" rel="noopener noreferrer" class="ct-thumb' + (big ? ' big' : '') + '"><img src="' + esc(h) + '" alt="" loading="lazy" referrerpolicy="no-referrer"></a>' : ''; };
|
||||
const ctHost = u => { try { return new URL(u, location.origin).hostname.replace(/^www\./, ''); } catch (e) { return ''; } };
|
||||
const ctCut = (s, n) => { s = String(s || ''); return s.length > n ? s.slice(0, n - 1) + '…' : s; };
|
||||
const ctLabel = k => ((CT.data && CT.data.types) || []).reduce((m, t) => t.key === k ? t.label : m, k);
|
||||
const CT_ONE = { page: 'Page', link: 'Link', source: 'Source', zone: 'Zone', ad: 'Ad', postback: 'Postback', upload: 'Upload', profile: 'Profile', message: 'Broadcast', audience: 'Audience', video: 'Video' };
|
||||
function ctDetail(r) {
|
||||
const d = r.detail || {}; const L = [];
|
||||
const line = h => { if (h) L.push('<div class="ct-l">' + h + '</div>'); };
|
||||
if (r.type === 'page') {
|
||||
line('<span class="chip-t">' + esc(d.kind) + '</span> ' + ctA(r.url, ctCut(r.url, 70)) + (r.open ? ' · <a href="' + esc(r.open) + '" target="_blank" rel="noopener">Preview</a>' : ''));
|
||||
if (d.headline) line('<b>' + esc(ctCut(d.headline, 140)) + '</b>');
|
||||
line('Button: ' + (d.ctaUrl ? ctA(d.ctaUrl, ctCut(d.ctaUrl, 80)) : (d.formProvider ? 'form (' + esc(d.formProvider) + ')' : '<span class="muted">not set</span>')) + (d.scanUrl && d.scanUrl !== d.ctaUrl ? ' · scanned ' + ctA(d.scanUrl, ctHost(d.scanUrl)) : ''));
|
||||
if (d.image) line(ctImg(d.image));
|
||||
} else if (r.type === 'link') {
|
||||
const ds = d.destinations || [];
|
||||
line(ctA(r.url, ctCut(r.url, 60)) + ' · <span class="mono">' + esc(d.code) + '</span> · ' + ds.length + ' destination' + (ds.length === 1 ? '' : 's') + (d.dayparted ? ' · dayparted' : '') + (d.expires ? ' · demo expires ' + ctWhen(d.expires) : ''));
|
||||
line(ds.slice(0, 6).map(x => '<span class="ct-dest' + (x.active ? '' : ' off') + '">' + ctA(x.url, ctHost(x.url) || x.url) + (x.weight > 1 ? ' ×' + x.weight : '') + (!x.active ? ' <span class="muted">' + (x.autoPaused ? 'auto-paused' : 'paused') + '</span>' : '') + (x.health && x.health !== 'ok' && x.health !== 'live' ? ' <span class="bad">' + esc(x.health) + '</span>' : '') + '</span>').join(' ') + (ds.length > 6 ? ' <span class="muted">+' + (ds.length - 6) + ' more</span>' : ''));
|
||||
if (d.fallback) line('Fallback: ' + ctA(d.fallback, ctCut(d.fallback, 70)));
|
||||
} else if (r.type === 'source') {
|
||||
line(esc(d.template === 'custom' ? 'Custom source' : 'Template ' + d.template) + (d.site ? ' · ' + ctA('https://' + d.site, d.site) : '') + (d.costModel ? ' · ' + esc(d.costModel) : '') + ' · ' + ctN(d.params) + ' params');
|
||||
line(d.postbackUrl ? 'Postback (' + esc(d.method) + ', ' + esc((d.events || []).join(', ')) + '): <span class="mono small">' + esc(ctCut(d.postbackUrl, 90)) + '</span>' : '<span class="muted">No postback</span>');
|
||||
} else if (r.type === 'zone') {
|
||||
line(ctA(r.url, d.site) + ' · ' + esc(d.size) + ' · ' + esc(d.tier) + ' · <span class="mono small">' + esc(r.id) + '</span>');
|
||||
line(esc(d.statusLabel) + (d.lastSeen ? ' · last view ' + ctWhen(d.lastSeen) : ' · <span class="muted">never seen</span>'));
|
||||
} else if (r.type === 'ad') {
|
||||
line('<span class="chip-t">' + esc(d.adType) + '</span> #' + esc(r.id) + ' · target ' + ctA(r.url, ctCut(r.url, 70)));
|
||||
if (d.imageUrl) line(ctImg(d.imageUrl, true) + (d.width ? ' <span class="muted small">' + d.width + '×' + d.height + '</span>' : ''));
|
||||
if (d.title || d.body) line((d.title ? '<b>' + esc(ctCut(d.title, 100)) + '</b> ' : '') + esc(ctCut(d.body, 200)));
|
||||
line('Budget ' + ctN(d.budget) + ' · spent ' + ctN(d.spent) + ' · left ' + ctN(Math.max(0, (d.budget || 0) - (d.spent || 0))) + (d.dailyCap ? ' · cap ' + ctN(d.dailyCap) + '/day' : '') + (d.geo ? ' · tiers ' + esc(d.geo) : '') + (d.starts ? ' · starts ' + ctWhen(d.starts) : '') + (d.expires ? ' · ends ' + ctWhen(d.expires) : ''));
|
||||
} else if (r.type === 'postback') {
|
||||
line('<span class="mono small">' + esc(ctCut(d.postbackUrl, 110)) + '</span>');
|
||||
line(esc(d.method) + ' · ' + esc((d.events || []).join(', ')) + (d.lastStatus ? ' · last ' + esc(d.lastStatus) + ' ' + ctWhen(d.lastAt) : ''));
|
||||
} else if (r.type === 'upload') {
|
||||
line((d.image ? ctImg(r.url) + ' ' : '') + ctA(r.url, ctCut(d.file, 60)) + ' · ' + ctSize(d.size) + ' · ' + esc(d.store));
|
||||
if (d.usedBy && d.usedBy.length) line('Used by ' + d.usedBy.map(esc).join(', ') + (d.ownerGuess ? ' <span class="muted">(owner taken from that use)</span>' : ''));
|
||||
else if (d.store === 'Uploads') line('<span class="muted">Not used by any campaign or profile right now</span>');
|
||||
} else if (r.type === 'profile') {
|
||||
line((d.avatarUrl ? ctImg(d.avatarUrl) + ' ' : '') + (d.bio ? esc(ctCut(d.bio, 220)) : '<span class="muted">No bio</span>') + (r.url ? ' · ' + ctA(r.url, 'Wall') : ''));
|
||||
if (d.lineTargetUrl || d.lineBannerUrl) line('Line banner: ' + (d.lineBannerUrl ? ctImg(d.lineBannerUrl) + ' ' : '') + ctA(d.lineTargetUrl, ctCut(d.lineTargetUrl, 70)));
|
||||
if (d.wallOffers && d.wallOffers.length) line('Wall offers: ' + d.wallOffers.map(o => (o.bannerUrl ? ctImg(o.bannerUrl) + ' ' : '') + ctA(o.targetUrl, (o.title ? o.title + ' · ' : '') + ctHost(o.targetUrl))).join(' · '));
|
||||
const so = Object.entries(d.socials || {}); if (so.length) line(so.map(([k, v]) => ctA(v, k)).join(' · '));
|
||||
} else if (r.type === 'message') {
|
||||
line(esc(ctCut(d.body, 320)));
|
||||
} else if (r.type === 'audience') {
|
||||
line('<span class="mono small">' + esc(d.audienceId) + '</span> · pixel <code>' + esc(d.pixel) + '</code>');
|
||||
} else if (r.type === 'video') {
|
||||
line((r.url ? ctA(r.url, 'Watch the render') : '<span class="muted">No file yet</span>') + (d.username ? ' · end card for @' + esc(d.username) : '') + (d.error ? ' · <span class="bad">' + esc(ctCut(d.error, 140)) + '</span>' : ''));
|
||||
}
|
||||
return L.join('');
|
||||
}
|
||||
function ctNums(r) {
|
||||
const c = r.counts || {}; const d = r.detail || {}; const k = (n, l) => '<div><b>' + (n == null ? '-' : n) + '</b> <span class="muted">' + l + '</span></div>';
|
||||
if (r.type === 'page') return k(ctN(c.views), 'views') + k(ctN(c.uniques), 'uniques') + k(ctN(c.clicks), 'clicks out') + k(ctN(c.leads), 'leads');
|
||||
if (r.type === 'link') return k(ctN(c.clicks7), 'clicks 7d') + k(ctN(c.clicks), 'all time') + (c.conversions ? k(ctN(c.conversions), 'conversions') : '') + (c.bots ? k(ctN(c.bots), 'bots') : '');
|
||||
if (r.type === 'zone') return k(ctN(c.views30), 'imps 30d') + k(c.viewablePct == null ? '-' : c.viewablePct + '%', 'viewable') + k(ctN(c.clicks30), 'clicks') + k(ctN(c.credits), 'credits paid');
|
||||
if (r.type === 'ad') return k(ctN(d.spent) + ' / ' + ctN(d.budget), 'spent') + k(ctN(c.imps) + (c.impsNas ? ' +' + ctN(c.impsNas) : ''), 'views') + k(ctN(c.clicks), 'clicks');
|
||||
if (r.type === 'source' || r.type === 'postback') return k(ctN(c.sent), 'sent') + k(ctN(c.fails), 'fails');
|
||||
if (r.type === 'audience') return k(ctN(c.size30), 'people 30d') + k(ctN(c.size7), '7d');
|
||||
if (r.type === 'message') return k(ctN(c.recipients), 'recipients');
|
||||
return '<span class="muted">-</span>';
|
||||
}
|
||||
function ctOwner(o) {
|
||||
if (!o || o.demo) return '<span class="muted">demo visitor</span>';
|
||||
if (!o.email) return '<span class="muted">unknown</span>';
|
||||
return (o.username ? '<b>@' + esc(o.username) + '</b><br>' : '') + '<span class="small">' + esc(o.email) + '</span><br><span class="muted small">' + (o.memberId ? 'member #' + o.memberId : 'free member') + '</span>'
|
||||
+ '<br><a href="#members" class="small ct-mem" data-ctmember="' + esc(o.email) + '">Open member</a>';
|
||||
}
|
||||
function drawContent() {
|
||||
const d = CT.data; if (!d) return;
|
||||
$('ctTotals').innerHTML = d.types.map(t => { const x = d.totals[t.key] || {}; return '<button type="button" class="statx ct-tile' + (CT.type === t.key ? ' on' : '') + '" data-cttype="' + t.key + '"><div class="nv">' + ctN(x.n) + '</div><div class="lb">' + esc(t.label) + '</div><div class="small muted">' + ctN(x.live) + ' live' + (x.flagged ? ' · <span class="bad">' + ctN(x.flagged) + ' flagged</span>' : '') + '</div></button>'; }).join('');
|
||||
$('ctTabs').innerHTML = '<button type="button" class="chip-t' + (CT.type === 'all' ? ' on' : '') + '" data-cttype="all" role="tab">All, newest first (' + ctN(d.all) + ')</button>'
|
||||
+ d.types.map(t => '<button type="button" class="chip-t' + (CT.type === t.key ? ' on' : '') + '" data-cttype="' + t.key + '" role="tab">' + esc(t.label) + ' (' + ctN((d.totals[t.key] || {}).n) + ')</button>').join('');
|
||||
$('ctSub').textContent = ctN(d.matched) + ' match' + (d.matched === 1 ? '' : 'es') + ' of ' + ctN(d.all) + ' · ' + ctN(d.flaggedAll) + ' flagged · as of ' + ctWhen(d.generated);
|
||||
$('ctBadge').hidden = !d.flaggedAll; $('ctBadge').textContent = d.flaggedAll || '';
|
||||
$('ctHosts').innerHTML = d.hosts.length ? '<span class="small muted">Busiest hosts in this view:</span> ' + d.hosts.map(h => '<button type="button" class="chip-t' + (h.burned ? ' bad' : '') + '" data-cthost="' + esc(h.host) + '">' + esc(h.host) + ' <b>' + h.n + '</b></button>').join('') : '';
|
||||
$('ctTable').innerHTML = '<tr><th>Type</th><th>Item</th><th>Owner</th><th>Created</th><th>Status</th><th>Numbers</th><th></th></tr>'
|
||||
+ (d.items.length ? d.items.map((r, i) => '<tr' + (r.flags.length ? ' class="ct-flagged"' : '') + '>'
|
||||
+ '<td data-l="Type"><span class="ct-type">' + esc(CT_ONE[r.type] || r.type) + '</span></td>'
|
||||
+ '<td data-l="Item"><div class="ct-title">' + esc(r.title || '(untitled)') + '</div>' + (r.flags.length ? '<div class="ct-flags">' + r.flags.map(f => '<span class="st rejected" title="' + esc(f.t) + '">' + esc(f.t) + '</span>').join(' ') + '</div>' : '') + ctDetail(r) + '</td>'
|
||||
+ '<td data-l="Owner">' + ctOwner(r.owner) + '</td>'
|
||||
+ '<td data-l="Created" class="small when">' + ctWhen(r.created) + '</td>'
|
||||
+ '<td data-l="Status"><span class="st ' + esc(r.live ? 'active' : (r.status === 'draft' || r.status === 'paused' ? r.status : 'out')) + '">' + esc(r.status) + '</span></td>'
|
||||
+ '<td data-l="Numbers" class="small ct-nums">' + ctNums(r) + '</td>'
|
||||
+ '<td class="act">' + (r.actions || []).map((a, j) => '<button type="button" class="btn small ' + (/^Pause/.test(a.label) ? 'sec' : '') + '" data-ctact="' + i + ':' + j + '">' + esc(a.label) + '</button>').join('') + (r.open && r.type !== 'page' ? ctA(r.open, 'Open') : '') + '</td></tr>').join('')
|
||||
: '<tr><td colspan="7" class="muted">Nothing matches.</td></tr>');
|
||||
$('ctPager').innerHTML = d.pages > 1 ? '<button type="button" class="btn small sec" data-ctpage="' + (d.page - 1) + '"' + (d.page <= 1 ? ' disabled' : '') + '>← Newer</button><span class="small muted">Page ' + d.page + ' of ' + d.pages + ' · ' + d.per + ' per page</span><button type="button" class="btn small sec" data-ctpage="' + (d.page + 1) + '"' + (d.page >= d.pages ? ' disabled' : '') + '>Older →</button>' : '';
|
||||
}
|
||||
async function loadContent(fresh) {
|
||||
const sp = new URLSearchParams({ type: CT.type, page: String(CT.page), per: '50' });
|
||||
const q = $('ctQ').value.trim(); if (q) sp.set('q', q);
|
||||
if ($('ctFrom').value) sp.set('from', $('ctFrom').value); if ($('ctTo').value) sp.set('to', $('ctTo').value);
|
||||
if ($('ctFlagged').checked) sp.set('flagged', '1'); if (fresh === true) sp.set('fresh', '1');
|
||||
CT.data = await api('/api/admin/content?' + sp.toString()); drawContent();
|
||||
}
|
||||
const ctReload = (fresh) => loadContent(fresh).catch(e => IAP.status(e.message, 'bad'));
|
||||
$('ctQ').addEventListener('input', () => { clearTimeout(CT.timer); CT.timer = setTimeout(() => { CT.page = 1; ctReload(); }, 250); });
|
||||
['ctFrom', 'ctTo', 'ctFlagged'].forEach(id => $(id).addEventListener('change', () => { CT.page = 1; ctReload(); }));
|
||||
$('ctClear').addEventListener('click', () => { $('ctQ').value = ''; $('ctFrom').value = ''; $('ctTo').value = ''; $('ctFlagged').checked = false; CT.type = 'all'; CT.page = 1; ctReload(); });
|
||||
$('ctRefresh').addEventListener('click', busy($('ctRefresh'), () => loadContent(true)));
|
||||
$('pane-content').addEventListener('click', async e => {
|
||||
const t = e.target.closest('[data-cttype]'); if (t) { CT.type = t.dataset.cttype; CT.page = 1; return ctReload(); }
|
||||
const h = e.target.closest('[data-cthost]'); if (h) { $('ctQ').value = h.dataset.cthost; CT.page = 1; return ctReload(); }
|
||||
const pg = e.target.closest('[data-ctpage]'); if (pg && !pg.disabled) { CT.page = Number(pg.dataset.ctpage) || 1; await ctReload(); $('ctTable').scrollIntoView({ block: 'start', behavior: 'smooth' }); return; }
|
||||
const m = e.target.closest('[data-ctmember]'); if (m) { e.preventDefault(); setPane('members'); return openMember(m.dataset.ctmember); }
|
||||
const b = e.target.closest('[data-ctact]'); if (!b || b.disabled) return;
|
||||
const [i, j] = b.dataset.ctact.split(':').map(Number); const r = CT.data && CT.data.items[i]; const a = r && r.actions[j]; if (!a) return;
|
||||
if (a.warn && !await IAP.confirmBox(a.warn, { title: a.label, ok: a.label, cancel: 'Cancel' })) return;
|
||||
b.disabled = true;
|
||||
try { await api(a.path, a.body || {}, 'POST'); IAP.status(a.label + ': done.', 'ok'); await loadContent(true); } catch (err) { IAP.status(err.message, 'bad'); b.disabled = false; }
|
||||
});
|
||||
|
||||
// ── link domains: channel per domain, last safety check, burned flag; check now / clear / pull (2026-10-10) ──
|
||||
async function loadDomains() {
|
||||
const d = await api('/api/admin/domains');
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
$('buysMeta').textContent = buys.length + (buys.length === 1 ? ' purchase' : ' purchases') + ' · every row links to the transaction';
|
||||
$('buyRows').innerHTML = buys.length ? buys.slice(0, 50).map(x => {
|
||||
const ts = Number(x.ts || x.time || 0); const when = ts ? new Date(ts * (ts > 1e12 ? 1 : 1000)).toLocaleString() : '';
|
||||
const pkg = x.priceCents ? usd(x.priceCents) : (x.package || x.product || ('#' + (x.productId || '')));
|
||||
const pkg = (x.priceCents ? usd(x.priceCents) : (x.package || x.product || ('#' + (x.productId || '')))) + (x.position ? ' · Position ' + x.position : ''); // bought from a linked position (2026-10-18)
|
||||
const paid = x.amountWei || x.valueWei || x.paidWei ? pol(x.amountWei || x.valueWei || x.paidWei) + ' POL' : '';
|
||||
const tx = x.tx || x.hash || '';
|
||||
return '<div class="rw"><span class="mono muted" style="font-size:12px">' + esc(when) + '</span><span class="num">' + esc(String(pkg)) + '</span><span class="mono">' + esc(paid) + '</span><span>' + (tx ? '<a class="mono" href="' + esc((CFG && CFG.explorer) || 'https://polygonscan.com') + '/tx/' + esc(tx) + '" target="_blank" rel="noopener">' + esc(tx.slice(0, 10)) + '…' + esc(tx.slice(-6)) + '</a>' : '') + '</span></div>';
|
||||
|
||||
+1
-1
@@ -83,6 +83,6 @@
|
||||
<script src="/assets/common.js?v=20261016a"></script>
|
||||
<script src="/assets/wallet.js?v=20261018a"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261018c"></script>
|
||||
<script src="/assets/credits-screen.js?v=20261018a"></script>
|
||||
<script src="/assets/credits-screen.js?v=20261018b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+11
-1
@@ -282,5 +282,15 @@ function servedToday() {
|
||||
const rawRotations = () => J.db.rotations;
|
||||
const save = () => J.save();
|
||||
const findMine = (owner, id) => J.db.rotations.find(r => r.id === Number(id) && r.owner === norm(owner)) || null;
|
||||
module.exports = { init, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary, createDemo, claim, sweepDemos, servedToday,
|
||||
// admin Member content (2026-10-18): every rotation of every owner, click counts in ONE pass over the hits (pub() per rotation is O(rotations x hits))
|
||||
function adminAll() {
|
||||
const since7 = Date.now() - 7 * DAY; const by = {}, cv = {};
|
||||
for (const h of J.db.hits) { const o = by[h.r] = by[h.r] || { hits: 0, hits7: 0, bots: 0 }; if (h.bot) { o.bots++; continue; } o.hits++; if (h.ts >= since7) o.hits7++; }
|
||||
for (const c of J.db.conv) cv[c.r] = (cv[c.r] || 0) + 1;
|
||||
return J.db.rotations.map(r => { const o = by[r.id] || { hits: 0, hits7: 0, bots: 0 };
|
||||
return { id: r.id, code: r.code, name: r.name, owner: r.owner, created: r.created, paused: !!r.paused, demo: !!r.demo, expires: r.expires || 0, fallback: r.fallback || '', sourceId: r.sourceId || '', dayparted: !!r.hours,
|
||||
destinations: (r.destinations || []).map(d => ({ id: d.id, url: d.url, label: d.label || '', weight: d.weight, active: !!d.active, autoPaused: d.autoPaused || 0, health: d.health ? { state: d.health.state, note: d.health.note || '', checkedAt: d.health.checkedAt || 0 } : null })),
|
||||
hits: o.hits, hits7: o.hits7, bots: o.bots, conversions: cv[r.id] || 0 }; });
|
||||
}
|
||||
module.exports = { init, adminAll, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary, createDemo, claim, sweepDemos, servedToday,
|
||||
pub, rawRotations, save, findMine, PRESETS, cleanHours, cleanTz, cellAt, zoneFor, isOn, COUNTRY_TZ, sourceCounts, detachSource };
|
||||
|
||||
@@ -53,6 +53,7 @@ const audiences = require('./audiences'); // first-party retargeting (2026-10-08
|
||||
const MEMBER_AD_TYPES = ['banner', 'text', 'login']; // the formats LinkSpin members can buy (video, visits, featured, solo stay off) // the rotator: rotations, weighted destinations, /r/<code>
|
||||
const snapshot = require('./snapshot'); // daily growth snapshot -> Telegram payments feed (Marty, 2026-09-15)
|
||||
const pipeline = require('./pipeline'); // sponsor follow-up board (coming soon until site setting pipelineMode = on) (Marty, 2026-09-15)
|
||||
const content = require('./content'); // admin Member content: one read-only list of everything members create (2026-10-18)
|
||||
const videomaker = require('./videomaker'); // Circuit tool: promo videos with the member's own end card (ffmpeg in the image) // badge-gated promo toolkit + AI Copy Engine (Surge and up) (Marty, 2026-09-14) // referral contest: /leaderboard, Overview card, weekly + monthly winners (Marty, 2026-09-14) // release notes + roadmap: /whats-new, Overview card, Admin > Releases (Marty, 2026-09-14) // blog -> Blotato -> X + Instagram on publish (Marty, 2026-09-13) // admin member card: search, drilldown, edits (Marty, 2026-09-13) // admin-written coaching articles, server-rendered public /blog with SEO metadata (Marty, 2026-09-12)
|
||||
const TRAFFIC_PAGES = new Set(['/', '/ledger', '/contract', '/shorts', '/plays', '/wallets', '/launch', '/partners', '/publishers', '/earning', '/blog', '/whats-new', '/leaderboard']);
|
||||
let tankWaitCache = null; // dashboard: who is waiting for a sponsor (refreshed every minute)
|
||||
@@ -376,10 +377,12 @@ async function handleUpload(req, res, who) {
|
||||
if (isVideo && spaces.enabled()) {
|
||||
try {
|
||||
const url = await spaces.put('iap-uploads/' + name, buf, ct);
|
||||
content.noteUpload(name, who, buf.length, ct, url); // who uploaded what (admin Member content)
|
||||
return json(res, 200, { url, type: 'video' });
|
||||
} catch (e) { console.error('spaces put', e.message); /* fall through to volume */ }
|
||||
}
|
||||
fs.writeFileSync(path.join(UPLOADS_DIR, name), buf);
|
||||
content.noteUpload(name, who, buf.length, ct, '');
|
||||
return json(res, 200, { url: '/uploads/' + name, type: isVideo ? 'video' : 'image' });
|
||||
}
|
||||
// lead-capture page hooks (og tags + copy live in public/assets/join.js too)
|
||||
@@ -497,6 +500,7 @@ async function boot() {
|
||||
audit.init({ dataDir: DATA_DIR, notify: text => { const sc = siteConfig(); if (sc.telegramBotToken && sc.telegramAdminChatId) telegramSend(sc.telegramAdminChatId, text).catch(() => {}); else if (ADMIN_EMAIL && mailer.hasKey()) mailer.send(ADMIN_EMAIL, 'LinkSpin: counter audit', text).catch(() => {}); } });
|
||||
setTimeout(() => audit.dailyTick(), 5 * 60 * 1000); setInterval(() => audit.dailyTick(), 24 * 60 * 60 * 1000);
|
||||
videomaker.init({ dataDir: DATA_DIR, spaces, accounts });
|
||||
content.init({ dataDir: DATA_DIR, uploadsDir: UPLOADS_DIR, accounts, pages, rotator, sources, zones, ads, postbacks, audiences, messages, videomaker, reports, domains, adminEmail: ADMIN_EMAIL, houseOwner: ads.HOUSE_OWNER, siteHost: SITE_HOST, linkHost: () => domains.live()[0] || SITE_HOST, pagesHost });
|
||||
leaderboard.init({ chain, accounts, ads, dataDir: DATA_DIR, siteConfig, pushFeed, adminEmail: ADMIN_EMAIL,
|
||||
notify: async text => { const sc = siteConfig(); if (!sc.telegramBotToken || !sc.telegramEchoChatId) return; await telegramSend(sc.telegramEchoChatId, text, sc.telegramEchoTopicId); if (String(sc.leaderboardAnnounceGeneral || '1') !== '0') await telegramSend(sc.telegramEchoChatId, text, null); } });
|
||||
setTimeout(() => leaderboard.rolloverTick().catch(e => console.error('leaderboard rollover', e.message)), 90 * 1000);
|
||||
@@ -1031,7 +1035,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const pg = pages.bySlug(pm[1]);
|
||||
const preview = u.searchParams.get('preview') === '1';
|
||||
if (!pg || (pg.status !== 'published' && !preview)) { res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end(isLinkHost(req) ? linkSitePage(reqHost(req), 'gone') : '<!doctype html><title>Not found</title><p style="font-family:system-ui;padding:40px">That page is not live.</p>'); }
|
||||
if (preview) { const sess = await auth.fromRequest(req); if (!sess || !sess.email || String(sess.email).toLowerCase() !== pg.owner) { res.writeHead(404, { 'Content-Type': 'text/plain' }); return res.end('Not found'); } }
|
||||
if (preview) { if (!isAdmin(req)) { const sess = await auth.fromRequest(req); if (!sess || !sess.email || String(sess.email).toLowerCase() !== pg.owner) { res.writeHead(404, { 'Content-Type': 'text/plain' }); return res.end('Not found'); } } } // the owner, or the admin (Member content); a preview is never counted
|
||||
else pages.view(pg, req, 'view');
|
||||
const lsid = String(u.searchParams.get('lsid') || '');
|
||||
const hdr = { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin',
|
||||
@@ -2124,6 +2128,13 @@ const server = http.createServer(async (req, res) => {
|
||||
inviteTokens.set(token, { email: e, exp: Date.now() + 24 * 3600 * 1000, next: /^\/[a-z]/.test(String(b.next || '')) ? String(b.next) : '/ads' });
|
||||
return json(res, 200, { ok: true, url: 'https://' + SITE_HOST + '/welcome/' + token, created: !!r.created });
|
||||
}
|
||||
// -- admin Member content (2026-10-18): every page, link, source, zone, ad, postback, upload, profile, broadcast, audience and
|
||||
// video members made, newest first; read-only (rows point at the existing campaign / zone pause routes)
|
||||
if (p === '/api/admin/content' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const sp = u.searchParams;
|
||||
return json(res, 200, await content.query({ type: sp.get('type') || '', q: (sp.get('q') || '').slice(0, 200), from: sp.get('from') || '', to: sp.get('to') || '', flagged: sp.get('flagged') === '1', page: sp.get('page'), per: sp.get('per'), fresh: sp.get('fresh') === '1' }), { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
if (p === '/api/admin/zones' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'Admin only.' });
|
||||
return json(res, 200, { zones: await zones.adminList(), totals: zones.totals(), publishers: zones.publisherTotals(7), rates: zones.settings(), tiers: zones.TIERS, warmup: zones.WARMUP, holdRatio: zones.HOLD_RATIO }, { 'Cache-Control': 'no-store' });
|
||||
@@ -2959,7 +2970,12 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, {
|
||||
memberId: id,
|
||||
earnings: await attachNames(evs.filter(e => (e.type === 'TierPaid' && e.recipientId === id) || (e.type === 'AwardPaid' && e.toId === id))),
|
||||
purchases: await attachNames(evs.filter(e => e.type === 'Purchase' && e.buyerId === id)),
|
||||
// buys from the member's linked positions count too (Marty's #353 bought a package that Credits never showed, 2026-10-18);
|
||||
// position = 2, 3 ... in the order the positions were added, null = the main wallet
|
||||
purchases: await (async () => {
|
||||
const posOf = {}; try { if (s.email) (await accounts.positions(s.email)).forEach((ps, i) => { if (ps.memberId && ps.memberId !== id) posOf[ps.memberId] = i + 2; }); } catch (e) {}
|
||||
return attachNames(evs.filter(e => e.type === 'Purchase' && (e.buyerId === id || posOf[e.buyerId])).map(e => Object.assign({}, e, { position: e.buyerId === id ? null : posOf[e.buyerId] })));
|
||||
})(),
|
||||
referrals: await attachNames(evs.filter(e => (e.type === 'MemberActivated' && e.sponsorId === id) || (e.type === 'BuyerCounted' && e.sponsorId === id)))
|
||||
});
|
||||
}
|
||||
|
||||
+3
-1
@@ -138,4 +138,6 @@ function forFire(owner, id) { const s = find(owner, id); return s && s.enabled &
|
||||
function save() { J.save(); }
|
||||
// name + placement key per source, for rotator.summary
|
||||
function meta(owner) { const m = {}; for (const s of mine(owner)) m[s.id] = { name: s.name, placementKey: placementKey(s), site: s.site || '' }; return m; }
|
||||
module.exports = { init, catalog, list, create, update, get, urlFor, test, find, forFire, save, meta, KEYS, PLACEMENT_KEYS, LIMITS };
|
||||
// admin Member content (2026-10-18): every source of every owner
|
||||
function adminAll() { return J.db.items.map(s => Object.assign(pub(s), { owner: s.owner })); }
|
||||
module.exports = { init, adminAll, catalog, list, create, update, get, urlFor, test, find, forFire, save, meta, KEYS, PLACEMENT_KEYS, LIMITS };
|
||||
|
||||
+3
-1
@@ -144,4 +144,6 @@ async function render(job) {
|
||||
return await R.spaces.put(key, fs.readFileSync(outFile), 'video/mp4');
|
||||
} finally { try { fs.rmSync(dir, { recursive: true, force: true }); } catch (e) {} }
|
||||
}
|
||||
module.exports = { init, list, enqueue, available, SOURCES };
|
||||
// admin Member content (2026-10-18): every render job (the file keeps the newest 500)
|
||||
function adminJobs() { return jobs().map(j => Object.assign({}, j, { title: (SOURCES.find(s => s.slug === j.slug) || {}).title || j.slug })); }
|
||||
module.exports = { init, adminJobs, list, enqueue, available, SOURCES };
|
||||
|
||||
@@ -131,6 +131,14 @@ async function adminSet(id, body) {
|
||||
if (body.tier != null) { const t = String(body.tier).toLowerCase(); if (!TIERS.includes(t)) return { error: 'Tier is standard or verified.' }; z.tier = t; }
|
||||
J.save(); return { ok: true, zone: Object.assign(pubZone(z), { owner: z.owner, note: z.adminNote || '' }) };
|
||||
}
|
||||
// admin Member content (2026-10-18): every zone with the same 30-day numbers, imps grouped in ONE pass (pubZone filters all imps per zone)
|
||||
function adminAll() {
|
||||
const since30 = Date.now() - 30 * DAY; const g = {}, last = {};
|
||||
for (const i of J.db.imps) { last[i.z] = i.ts; if (i.ts >= since30 && !i.bot) (g[i.z] = g[i.z] || []).push(i); }
|
||||
return J.db.zones.map(z => { const imps = g[z.id] || []; const st = statusOf(z, imps); const seen = imps.filter(i => i.ok).length;
|
||||
return { id: z.id, name: z.name, site: z.site, size: z.size, tier: tierOf(z), active: !!z.active, paused: !!z.adminPaused, note: z.adminNote || '', owner: z.owner, created: z.created,
|
||||
views30: imps.length, viewable30: seen, viewablePct: imps.length ? Math.round(seen / imps.length * 100) : null, clicks30: imps.filter(i => i.k).length, offsite30: imps.filter(i => i.off).length, credits: z.credits || 0, status: st.state, statusLabel: st.label, lastSeen: last[z.id] || 0 }; });
|
||||
}
|
||||
function totals() { const since = Date.now() - 30 * DAY; const imps = J.db.imps.filter(i => i.ts >= since && !i.bot); return { zones: J.db.zones.length, views30: imps.length, viewable30: imps.filter(i => i.ok).length, clicks30: imps.filter(i => i.k).length, nas30: imps.filter(i => i.nas).length, credits: J.db.zones.reduce((n, z) => n + (z.credits || 0), 0) }; }
|
||||
// -- publisher program totals (Reports screen + the public strip): the last N days, Central days, per day and per zone.
|
||||
// "live" = switched on, not admin-paused, and seen by a real visitor inside the window. Credits are read from the pay log
|
||||
@@ -156,4 +164,4 @@ function publisherPublic() {
|
||||
rates: { viewsPerCredit: s.viewsPerCredit, nasViewsPerCredit: s.nasViewsPerCredit, nasViewsPerCreditVerified: s.nasViewsPerCreditVerified, capPerVisitorDay: s.capPerVisitorDay }, warmup: WARMUP, holdRatio: HOLD_RATIO, updated: Date.now() };
|
||||
pubCache = { ts: Date.now(), data }; return data;
|
||||
}
|
||||
module.exports = { init, SIZES, NAS_SIZES, TIERS, WARMUP, HOLD_RATIO, settings, tierOf, rateFor, nasFrame, list, create, update, tag, serve, seen, click, totals, publisherTotals, publisherPublic, adminList, adminSet };
|
||||
module.exports = { init, SIZES, NAS_SIZES, TIERS, WARMUP, HOLD_RATIO, settings, tierOf, rateFor, nasFrame, list, create, update, tag, serve, seen, click, totals, publisherTotals, publisherPublic, adminList, adminSet, adminAll };
|
||||
|
||||
Reference in New Issue
Block a user