Whiteboard: Pushover an alle Zugreifer wenn jemand speichert
This commit is contained in:
@@ -105,7 +105,7 @@ router.get('/:id/data', authenticate, (req, res) => {
|
||||
|
||||
// ── Canvas speichern ──────────────────────────────────────────────────────────
|
||||
// Feste Route vor :id-Routen
|
||||
router.post('/:id/save', authenticate, (req, res) => {
|
||||
router.post('/:id/save', authenticate, async (req, res) => {
|
||||
const me = uid(req);
|
||||
const role = access(req.params.id, me);
|
||||
if (!role || role === 'view') return res.status(403).json({ error: 'Kein Schreibzugriff' });
|
||||
@@ -115,6 +115,35 @@ router.post('/:id/save', authenticate, (req, res) => {
|
||||
`).run(JSON.stringify(elements || []), JSON.stringify(viewport || {x:0,y:0,zoom:1}), req.params.id);
|
||||
db.prepare("UPDATE whiteboards SET updated_at=datetime('now','localtime') WHERE id=?").run(req.params.id);
|
||||
res.json({ ok: true });
|
||||
|
||||
// Pushover an alle anderen mit Zugriff (fire & forget)
|
||||
try {
|
||||
const wb = db.prepare('SELECT * FROM whiteboards WHERE id=?').get(req.params.id);
|
||||
const saver = db.prepare('SELECT username FROM users WHERE id=?').get(me);
|
||||
const message = `${saver?.username || 'Jemand'} hat das Whiteboard "${wb?.title || ''}" gespeichert.`;
|
||||
|
||||
// Alle User mit Zugriff: Owner + alle Permissions — außer dem Speichernden selbst
|
||||
const notify = [];
|
||||
if (wb && wb.owner_id !== me) notify.push(wb.owner_id);
|
||||
const perms = db.prepare('SELECT user_id FROM whiteboard_permissions WHERE whiteboard_id=?').all(req.params.id);
|
||||
for (const p of perms) { if (p.user_id !== me) notify.push(p.user_id); }
|
||||
|
||||
for (const userId of [...new Set(notify)]) {
|
||||
const poCfg = db.prepare('SELECT user_key, app_token FROM pushover_settings WHERE user_id=?').get(userId);
|
||||
if (!poCfg?.app_token || !poCfg?.user_key) continue;
|
||||
fetch('https://api.pushover.net/1/messages.json', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
token: poCfg.app_token,
|
||||
user: poCfg.user_key,
|
||||
title: '🖊 Whiteboard aktualisiert',
|
||||
message,
|
||||
priority: 0,
|
||||
}),
|
||||
}).catch(() => {});
|
||||
}
|
||||
} catch {}
|
||||
});
|
||||
|
||||
// ── Berechtigungen: alle User für Share-Modal ─────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user