Files
martbost a428075330 Spot edits: unlimited, full link check on every one, every one logged; admin takedown and restore (Marty 2026-11-16)
Edits (POST /api/my/spot/<id>, /api/my/default, uploads): still any number of times. Every change now gets the full check:
checkLink, then (LINK_PROBE on) the link must answer (safety.probeLink, up to 3 redirects each checked) and an image address must
download as a real 468x60 image of 150 KB or less (safety.probeImage; the address is kept, a Banner Spin image rotates). The
Banner Spin image + click link LinkSpin just handed the member are not fetched (that would count a LinkSpin click). safety.js gains
privateIp + safeLookup with the Node 20 fix VBB/ViralAdBlitz needed (honors opts.all, answers an array). Every real change is
logged on the spot (or the default): old and new link and image, time, via edit/upload; the owner sees the newest 10. 120 changes
an hour per connection (each one fetches the link).

Admin takedown (the Viral Banner Blitz way, 8e6d2f9): /admin (new page) finds a spot by #number, wallet or network username;
POST /api/admin/spots/<id>/takedown {reason (required, the owner sees it), credit}. Hidden everywhere at once: the board shows a
house tile in its place (nobody else moves), the gate gives its step to a house site, /go/<id> goes home, its Network Ad Space
banner is paused (approved = 0) and no new one is placed. No views or clicks count while down. My Spots shows "Taken down" with
the reason and no edit controls. Restore (POST .../restore) reverses it (NAS resumed). Admin ledger: GET /api/admin/actions (who,
when, reason, credit decision). The contract is never touched.
CREDIT BACK IS NOT BUILT: a spot is a $5 on-chain purchase and this site has no free replacement spot or post credit, so
credit: "back" is refused with a note until Marty decides what it means here; takedowns are "no credit".
Chatbot: CANNED takedown + banner answer (unlimited checked, logged edits) + FACTS EDITS/TAKEDOWN lines, KNOWLEDGE_DATE 2026-11-16.
line.css?v=9, my.js?v=z3.
Tests: smoke section 10 (the lookup shape, edit log, unlimited edits, refusals: unreachable, 404, private address, http redirect,
shortener, bad image size/404/unreachable; redirect followed; same link logs nothing; upload logged; default checked + logged;
takedown: token, reason, credit choice, credit back refused, held house tile, image nowhere, /go home, gate, no views, owner view,
no edits while down, ledger, restore, /admin) against a stand-in internet preloaded into the app (qa/out/probe-stub.cjs, nothing
leaves the machine), plus phone renders of My Spots taken down and /admin: 193/193 with UI. chatbot.test 181/181.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 05:23:54 -06:00

75 lines
4.5 KiB
JavaScript

// All runtime config comes from env (Coolify sets these). Read once; the house-ad list can also be
// overridden by DATA_DIR/house.json so it changes without a redeploy.
const fs = require('fs');
const path = require('path');
const NETS = {
80002: { name: 'Polygon Amoy (testnet rehearsal)', explorer: 'https://amoy.polygonscan.com', rpcs: ['https://polygon-amoy-bor-rpc.publicnode.com', 'https://polygon-amoy.drpc.org'] },
// drpc first: publicnode refuses some log/archive queries (kept as fallback, InstantAdPay-style rotation)
137: { name: 'Polygon', explorer: 'https://polygonscan.com', rpcs: ['https://polygon.drpc.org', 'https://polygon-bor-rpc.publicnode.com', 'https://polygon-rpc.com'] },
31337: { name: 'Local anvil', explorer: '', rpcs: ['http://127.0.0.1:8545'] }
};
// Production default: the BannerLine contract on Polygon mainnet (deployed 2026-11-13, owner = Marty's Tangem,
// keeper 0xcAF8EF6eFDFC9597780Db5a1F6b2efE525868e37). Other chains (80002 Amoy, 31337 anvil) need CONTRACT_ADDRESS set.
const MAINNET = { contract: '0x6c77fc0664f58cf17e81966160fc80005a110f9b', deployBlock: 97245075 };
let cfg = null;
function get() {
if (cfg) return cfg;
const e = process.env;
const chainId = Number(e.CHAIN_ID || 137);
const main = chainId === 137;
const net = NETS[chainId] || NETS[137];
const list = s => String(s || '').split(',').map(x => x.trim()).filter(Boolean);
cfg = {
port: Number(e.PORT || 3000),
isProd: e.NODE_ENV === 'production',
site: e.SITE_HOST || 'downlinebanners.com',
dataDir: e.DATA_DIR || path.join(__dirname, 'data'),
contract: (e.CONTRACT_ADDRESS || (main ? MAINNET.contract : '')).trim(),
chainId,
chainName: e.CHAIN_NAME || net.name,
explorer: e.EXPLORER_URL !== undefined ? e.EXPLORER_URL : net.explorer,
rpcs: list(e.RPC_URLS).length ? list(e.RPC_URLS) : net.rpcs,
publicRpc: e.PUBLIC_RPC || (list(e.RPC_URLS)[0] || net.rpcs[0]), // handed to the wallet for add/switch chain
deployBlock: Number(e.START_BLOCK || e.DEPLOY_BLOCK || (main && String(e.CONTRACT_ADDRESS || MAINNET.contract).trim().toLowerCase() === MAINNET.contract ? MAINNET.deployBlock : 0)),
confirmations: Number(e.CONFIRMATIONS !== undefined ? e.CONFIRMATIONS : (chainId === 31337 ? 0 : 3)),
pollMs: Number(e.POLL_MS || 20000),
priceFeed: (e.PRICE_FEED || '').trim(),
allowStaleFeed: e.ALLOW_STALE_FEED === '1',
walletConnectProjectId: (e.WALLETCONNECT_PROJECT_ID || '').trim(),
// board + gate
viewsOwed: 300, spotDays: 30, boardSlots: Number(e.BOARD_SLOTS || 12),
gateVisitSeconds: 9, gateBoardSeconds: 10,
// every edit of a spot's (or the default's) link and image gets the full check (2026-11-16): the link must answer, an image
// address must download as a real 468x60 image. LINK_PROBE=0 turns the network part off (local smoke only).
linkProbe: e.LINK_PROBE !== '0',
// keeper (fund buys). KEEPER_KEY is never stored in cfg: keeper.js reads it from env at signing time only.
keeperEnabled: e.KEEPER_ENABLED === '1',
keeperStallHours: Number(e.KEEPER_STALL_HOURS || 4),
keeperMaxPerDay: Number(e.KEEPER_MAX_PER_DAY || 12),
keeperEveryMs: Number(e.KEEPER_EVERY_MIN || 15) * 60000,
iapBase: String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, ''),
lsBase: String(e.LS_URL || 'https://linkspin.app').replace(/\/+$/, ''),
// network usernames: ?u=<username> -> {address, username}, ?a=<wallet> -> the same (InstantAdPay today, the network hub later)
networkLookupUrl: (e.NETWORK_LOOKUP_URL || String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, '') + '/api/network/member').trim()
};
return cfg;
}
// House ads fill empty board slots. Order of fill: member LinkSpin Banner Spins (hook in board.js), then these.
// Image paths avoid ad-blocker patterns (no size tokens, no /banners/ folder).
const HOUSE_DEFAULT = [
{ key: 'iap', title: 'InstantAdPay', img: '/art/house-iap.svg', link: 'https://instantadpay.com/', note: 'Ad credits buy advertising, not income.' },
{ key: 'linkspin', title: 'LinkSpin', img: '/art/house-linkspin.svg', link: 'https://linkspin.app/' },
{ key: 'games', title: 'Network games', img: '/art/house-games.svg', link: 'https://enjoybestgames.com/' },
{ key: 'self', title: 'Downline Banners', img: '/art/house-line.svg', link: '/join' }
];
function house() {
try { const h = JSON.parse(fs.readFileSync(path.join(get().dataDir, 'house.json'), 'utf8')); if (Array.isArray(h) && h.length) return h; } catch (e) {}
return HOUSE_DEFAULT;
}
module.exports = { get, house, reset: () => { cfg = null; } };