diff options
Diffstat (limited to 'nwcpush')
| -rw-r--r-- | nwcpush/server.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/nwcpush/server.js b/nwcpush/server.js index bdf30aa..7873a4e 100644 --- a/nwcpush/server.js +++ b/nwcpush/server.js @@ -694,6 +694,28 @@ const server = Bun.serve({ return json({ ok: true, devices: n }); } + // Server-to-server: an account was deleted at the registrar. Its devices' + // registrations go (found by the keys they asked to be told about, then + // the same devices' NWC wakes), and its scheduled posts. + if (url.pathname === '/forget' && req.method === 'POST') { + const body = await req.json().catch(() => null); + if (!CFG.notifyToken || body?.token !== CFG.notifyToken) return json({ error: 'forbidden' }, 403); + const pks = new Set((Array.isArray(body.pubkeys) ? body.pubkeys : []).filter((k) => /^[0-9a-f]{64}$/.test(k || ''))); + if (!pks.size) return json({ error: 'pubkeys required' }, 400); + const ids = new Set(); + for (const [id, r] of Object.entries(notifyRegs)) if ((r.ptags || []).some((k) => pks.has(k))) { ids.add(id); delete notifyRegs[id]; } + for (const pk of Object.keys(regs)) { + regs[pk] = regs[pk].filter((r) => !ids.has(r.id)); + if (!regs[pk].length) delete regs[pk]; + } + let posts = 0; + for (const [id, s2] of Object.entries(scheduled)) if (pks.has(s2.ev?.pubkey)) { delete scheduled[id]; posts++; } + if (ids.size) { persist(); resubscribe(); } + if (posts) persistScheduled(); + log(`forgot ${ids.size} device(s), ${posts} scheduled post(s)`); + return json({ ok: true, devices: ids.size, scheduled: posts }); + } + // Claim a pay request before spending on it. The first claimant (or the // same one again) gets ok:true; anyone else ok:false and stands down. if (url.pathname === '/claim' && req.method === 'POST') { |
