337d4f9e8f
Public walls: profile fields (bio, avatar, socials, intro video) render only for a paying member (memberId > 0 or a registered position), on /api/wall and in the OG image; a free account's wall shows the name, the line's ads and the join call. The meta/og description is a fixed site sentence with the handle, never the bio. Outbound profile links are rel="sponsored ugc noopener" target="_blank". A deleted or unknown name is a real 404 with X-Robots-Tag noindex (was a bare "Banner wall" page at 200, a soft 404 that stayed indexed).
Policy (prohibited.js, byte-for-byte copy on LinkSpin): bios may not carry a URL or a domain token ("Links go in the social fields, not the bio"); gambling, adult, pharma, weapons and link-selling terms (Unicode aware, Vietnamese and Portuguese terms included) are refused in bios, social URLs, line banner targets, wall offers and every campaign field, with the refusal logged. lssync applies it on the way out and lsinbound on ingest.
Quarantine rule: a brand-new free account (no wallet, no sponsor, under 24 h) whose first profile save plants a link is saved with profileQuarantined (JSON + MySQL column), never rendered publicly, and told "Your profile links will appear after your first ad package"; the admin member card shows the flag.
Daily link-farm scan (spamscan.js, same copy on LinkSpin): in-app job at 06:30 Central, claimOnce per day, lists memberId-0 walletless accounts with a link plus a farm signal (prohibited term, sign-in over within 15 min, no sponsor), skips the spamScanAllow setting (seeded), writes DATA_DIR/wall-spam-scan.json and sends one Telegram to the private admin chat only when there are candidates. Admin > Members > Link-farm list: rows with "also on LinkSpin", Delete selected (existing DELETE /api/admin/member, on-chain refused, no cascade) and Allow.
Terms section 8 "Prohibited content", bio hint in the profile editor, chatbot canned answer "What content is not allowed?", KNOWLEDGE_DATE 2026-10-30. Test: qa/profile-policy.test.cjs (unit + local copy; runs in qa/run.sh member and policy).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2468 lines
166 KiB
JavaScript
2468 lines
166 KiB
JavaScript
// Ad engine v1 (spec §8b types 1-3). Dual-mode like accounts.js:
|
||
// MySQL (db.enabled) with guarded UPDATEs for the concurrent serving path,
|
||
// JSON volume file fallback for local dev.
|
||
// Spend accrues per campaign; burns queue for the engine signer to consume()
|
||
// on-chain (/api/admin/burns). All exported functions are async.
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
const crypto = require('crypto');
|
||
const db = require('./db');
|
||
const prohibited = require('./prohibited'); // 2026-10-30: gambling, adult, pharma, weapons, link-selling terms refused in every ad field
|
||
const nas = require('./nas'); // NAS syndication (inert unless NAS_DB_* env is set)
|
||
const adrevlnks = require('./adrevlnks'); // AdRevLinks popup syndication (inert unless ADREVLNKS_BRIDGE_* is set)
|
||
const dripoffers = require('./dripoffers'); // DripOffers paid-per-click syndication (inert unless DRIPOFFERS_BRIDGE_* is set)
|
||
|
||
let DATA_DIR = null;
|
||
let chain = null;
|
||
const RATES_FILE = () => path.join(DATA_DIR, 'adrates.json');
|
||
|
||
// REHEARSAL PLACEHOLDER RATES — admin-adjustable via /api/admin/rates.
|
||
// Admin house ads: owned by this pseudo-account, funded by nothing. They serve
|
||
// through every normal path but the spend is never charged to anyone; the
|
||
// budget only acts as a delivery cap (status flips to 'out' when it's reached).
|
||
const HOUSE_OWNER = 'house@instantadpay.com';
|
||
function rates() {
|
||
let saved = {};
|
||
try { saved = JSON.parse(fs.readFileSync(RATES_FILE(), 'utf8')); } catch (e) {}
|
||
return Object.assign({
|
||
bannerBatch: 10, bannerCreditsPerBatch: 2,
|
||
textBatch: 10, textCreditsPerBatch: 1,
|
||
// Login ads are a flat slot buy: one price, 30 days, unlimited impressions, no
|
||
// delivery guarantee. Same total as the old 100/day x 30, but with a known end and
|
||
// no daily drain against inventory that may not exist that day.
|
||
loginSlotCredits: 1000,
|
||
loginSlotDays: 30,
|
||
loginSlotsMax: 3, // member slots live at once; the sign-ins are shared, more slots = fewer views each
|
||
loginCreditsPerDay: 100, // legacy: only used to close out pre-slot campaigns
|
||
loginDwellSeconds: 10, // full-screen interstitial after sign-in
|
||
burnBatchMin: 50,
|
||
welcomeCredits: 25,
|
||
dailyViewTarget: 5, // ads to view for the daily claim (spec §8b attention-gated claim)
|
||
dailyClaimCredits: 5,
|
||
viewDwellSeconds: 10, // Marty 2026-09-09: at least 10s so people actually look
|
||
// onsite solo ads: full-message inbox delivery, charged per guaranteed recipient
|
||
soloCostPerRecipient: 5,
|
||
soloMinRecipients: 10,
|
||
soloReadCredits: 2, // earned by the reader per rewarded read
|
||
soloReadCapPerDay: 5,
|
||
soloReadDwellSeconds: 10,
|
||
// watch-to-earn video ads: advertiser picks a required watch length, which
|
||
// sets the per-view price; the viewer earns per completed watch
|
||
videoTiers: [
|
||
{ secs: 10, cost: 3, reward: 1 },
|
||
{ secs: 30, cost: 7, reward: 2 },
|
||
{ secs: 60, cost: 12, reward: 4 }
|
||
],
|
||
videoWatchCapPerDay: 8,
|
||
// featured rotation: your link runs in the featured strip for N days; the
|
||
// dilution (how many links share the rotation) is disclosed before you buy
|
||
featuredPerDay: 40, // credits per day
|
||
featuredDurations: [1, 2, 7],
|
||
featuredSlotsPerDay: 10, // cap on links sharing the rotation on any one day
|
||
featuredWindowDays: 7, // how far ahead a day can be booked
|
||
// verified visits: buy a pack of guaranteed unique human visits; each is a
|
||
// dwelled + captcha-verified visit by a distinct member (never a repeat)
|
||
visitCostPerVisit: 3, // credits the advertiser pays per delivered visit
|
||
visitMinPack: 20, // smallest pack
|
||
visitReward: 1, // credits the viewer earns per verified visit
|
||
visitDwellSeconds: 8,
|
||
visitCapPerDay: 20, // per-viewer daily cap on rewarded visits
|
||
refuelCapPerDay: 20, // per-player daily cap on Drip Runner refuel visits, separate from the Earn-tab cap (2026-09-30)
|
||
doorRepeatDays: 7, // a door may show a visit campaign again this many days after the member last visited it (Earn/refuel stay once-ever)
|
||
doorCapPerDay: 15, // per-player daily cap on Spooky Doors door visits, separate from refuels and the Earn-tab cap (2026-10-02)
|
||
// door packs + Golden Doors (Spooky Doors launch pack, 2026-10-02): a visits pack placed behind the doors only ('doors') or as a
|
||
// Golden Door ('golden'), charged per door up front like any visit pack. Served first on doors (golden, then doors), once per
|
||
// player per Central day, never on the Earn tab or refuels until sdSeasonEnd (a Central day, exclusive); from that day on
|
||
// they behave as placement 'all', so unused doors roll into normal visits.
|
||
doorPackCost: 4, // credits per door, placement 'doors'
|
||
goldenDoorCost: 6, // credits per door, placement 'golden'
|
||
goldenBonusCandy: 2, // extra candy on a Golden Door (sent to the game as `bonus`)
|
||
sdSeasonEnd: '2026-11-01',
|
||
// house ads for Spooky Doors (2026-10-02): when a door has no visit pack and no video left, one of Marty's own programs
|
||
// instead of "Nobody's home". ref = the program's own share link with {u} for the player's IAP username ('' = plain url).
|
||
// [] turns house doors off (back to none=1).
|
||
doorHouseAds: [
|
||
{ name: 'RM Circle', url: 'https://rmcircle.team/', title: 'RM Circle', ref: '' },
|
||
{ name: 'Drip Runner', url: 'https://driprunner.app/', title: 'Drip Runner', ref: 'https://driprunner.app/r/{u}' },
|
||
{ name: 'Gem Kingdom', url: 'https://gemkingdom.app/', title: 'Gem Kingdom', ref: 'https://gemkingdom.app/?ref={u}' },
|
||
{ name: 'PolHunter', url: 'https://polhunter.com/', title: 'PolHunter', ref: 'https://polhunter.com/?r={u}' }
|
||
],
|
||
// credit bonuses paid once when a member reaches each milestone (the same
|
||
// ladder as the Overview stepper). Keys: payouts / firstBuyer / level2 / level3
|
||
milestoneBonus: { payouts: 10, firstBuyer: 25, level2: 50, level3: 100 },
|
||
// SYNDICATED RATE (Marty, 2026-10-27, approved 4:1): delivery OFF instantadpay.com costs 1/synRateDivisor of the on-site
|
||
// rate. Network Ad Space impressions: 1 credit per (impressionsPerCredit x N) views; PassiveDrip visits: N partner visits
|
||
// use up one visit of the pack. Fractions are exact (the cumulative counters carry the remainder) and the budget is the
|
||
// limit. Going forward only: nothing already charged changes. 1 = the old rule (same rate as on-site).
|
||
synRateDivisor: 4
|
||
}, saved);
|
||
}
|
||
function setRates(patch) {
|
||
fs.writeFileSync(RATES_FILE(), JSON.stringify(Object.assign(rates(), patch), null, 2));
|
||
return rates();
|
||
}
|
||
|
||
const TYPES = ['banner', 'text', 'login', 'solo', 'video', 'featured', 'visits'];
|
||
// standard IAB sizes — ids map straight to NAS sponsorads width/height (pid 2)
|
||
const BANNER_SIZES = [
|
||
{ id: '728x90', w: 728, h: 90, label: 'Leaderboard 728×90' },
|
||
{ id: '300x250', w: 300, h: 250, label: 'Medium rectangle 300×250' },
|
||
{ id: '468x60', w: 468, h: 60, label: 'Banner 468×60' },
|
||
{ id: '160x600', w: 160, h: 600, label: 'Wide skyscraper 160×600' },
|
||
{ id: '120x600', w: 120, h: 600, label: 'Skyscraper 120×600' },
|
||
{ id: '320x50', w: 320, h: 50, label: 'Mobile leaderboard 320×50' },
|
||
{ id: '125x125', w: 125, h: 125, label: 'Square button 125×125' }
|
||
];
|
||
// solo bodies are member-authored rich text rendered in OTHER members'
|
||
// browsers: whitelist-sanitize server-side — known tags only, no attributes
|
||
// (except http(s) hrefs, rebuilt clean), every stray angle bracket escaped
|
||
const SOLO_TAGS = new Set(['b', 'strong', 'i', 'em', 'u', 's', 'p', 'br',
|
||
'ul', 'ol', 'li', 'h2', 'h3', 'h4', 'blockquote', 'div', 'span', 'figure']);
|
||
function sanitizeSolo(html) {
|
||
const src = String(html || '').replace(/ |