Admin member card: Message (inbox + email) button (Marty 2026-11-12). POST /api/admin/member/message puts a broadcast in the member's inbox and emails it through the site mailer (opt-outs and unsubscribe link kept); reports when email is skipped. admin.js?v=20261112msg; qa member passed; local route test passed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-12 06:47:52 -06:00
parent 3eae242dc3
commit db1ab8359c
3 changed files with 31 additions and 1 deletions
+21
View File
@@ -3204,6 +3204,27 @@ const server = http.createServer(async (req, res) => {
// -- link-farm scan (2026-10-30): last result + allowlist, run now (no Telegram), allow / unallow an email
if (p === '/api/admin/spamscan' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, spamscan.view()); }
if (p === '/api/admin/spamscan/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); await spamscan.run({ manual: true, quiet: true }); return json(res, 200, spamscan.view()); }
// admin -> one member: inbox message + email (Marty 2026-11-12: "no way to send them an inbox message that would email them as well")
if (p === '/api/admin/member/message' && req.method === 'POST') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); const acct = e && await accounts.byEmail(e);
if (!acct) return json(res, 404, { error: 'No such member.' });
const subject = String(b.subject || '').trim().slice(0, 150), text = String(b.text || '').trim().slice(0, 8000);
if (!subject || !text) return json(res, 400, { error: 'Subject and message are both needed.' });
const escH = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
const html = text.split(/\n{2,}/).map(par => '<p>' + escH(par).replace(/\n/g, '<br>') + '</p>').join('');
await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [e], subject, html, 'broadcast');
let emailed = false, emailSkipped = '';
if (!mailer.hasKey()) emailSkipped = 'mail is not set up on this server';
else {
const hello = acct.username ? 'Hi @' + acct.username + ',\n\n' : 'Hi,\n\n';
const tail = '\n\nYou can reply from your member inbox: https://instantadpay.com/my\n\nMarty Bostick, InstantAdPay';
try { emailed = (await mailer.send(e, subject, hello + text + tail, '<div style="font-family:Arial,sans-serif;font-size:15px;line-height:1.5">' + '<p>' + escH(hello.trim()) + '</p>' + html + '<p>You can reply from your member inbox: <a href="https://instantadpay.com/my">instantadpay.com/my</a></p><p>Marty Bostick, InstantAdPay</p></div>')) !== false; if (!emailed) emailSkipped = 'they unsubscribed from email'; }
catch (err) { emailSkipped = 'the mail service failed (' + String(err.message || err).slice(0, 80) + ')'; }
}
console.log('admin message', e.replace(/^(.).*(@.*)$/, '$1***$2'), 'inbox ok', emailed ? 'emailed' : 'email skipped: ' + emailSkipped);
return json(res, 200, { ok: true, inbox: true, emailed, emailSkipped });
}
if (p === '/api/admin/spamscan/allow' && req.method === 'POST') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); if (!e) return json(res, 400, { error: 'Which email?' });