Promo tools > Stack POL: 'Show my Stack POL page' switch (GET/POST /api/my/stackpol, DATA_DIR/stack-optin.json read by the stackpol.com indexer); chatbot knows Stack POL (KNOWLEDGE_DATE 2026-11-09); my.js v=20261109sp

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-09 14:39:25 -06:00
parent 03284aa281
commit 2aa98bdbd2
4 changed files with 48 additions and 3 deletions
+14
View File
@@ -5152,6 +5152,20 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, Object.assign(r, { status: await ads.visitStatus(s.email) }));
}
// -- onsite solo ads: member inbox with read rewards
// Stack POL page switch (Marty 2026-11-09): a member opts in to a public page at stackpol.com/<username>. The list lives in
// DATA_DIR/stack-optin.json { users: { username: true|false } }; the Stack POL indexer on core reads it every 5 minutes.
if (p === '/api/my/stackpol' && (req.method === 'GET' || req.method === 'POST')) {
const s = await auth.fromRequest(req);
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const acct = await accounts.byEmail(s.email); const un = String((acct && acct.username) || '').toLowerCase();
if (!un) return json(res, 400, { error: 'Pick a username first (Profile), then switch on your Stack POL page.' });
const F = path.join(DATA_DIR, 'stack-optin.json'); let so = { users: {} }; try { so = JSON.parse(fs.readFileSync(F, 'utf8')); if (!so.users) so.users = {}; } catch (e) {}
if (req.method === 'POST') {
const b = await readBody(req); so.users[un] = !!b.on; so.updatedAt = Date.now();
const tmp = F + '.tmp'; fs.writeFileSync(tmp, JSON.stringify(so)); fs.renameSync(tmp, F);
}
return json(res, 200, { on: !!so.users[un], username: un, url: 'https://stackpol.com/' + un, wallet: !!(acct && acct.address) });
}
if (p === '/api/my/inbox' && req.method === 'GET') {
const s = await auth.fromRequest(req);
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });