57dc91585d
Internal SmartGift build of a Claude Code monitoring dashboard. Lanes: a durable unit of parallel agent work, one per working directory, tracked across session restarts. Managed lanes are git worktrees the dashboard provisions and can reset or remove behind a three-check destroy guard and a counted preflight; adopted lanes are directories you already own and are never destroyable. Pipelines: a lane moves through pipeline stages. A stage the agent declares with evidence renders green; a stage inferred from the tool-event stream renders dashed amber and never counts as done. Detection is forward-only within a 30-minute window, and never writes the declared stage. Workspace: one page at /run with a lane grid, the selected lane's pipeline, and a full Claude console behind a disclosure.
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
/**
|
|
* @file Express router for managing push notifications, providing endpoints to retrieve the VAPID public key, subscribe/unsubscribe to push notifications, and send push notifications to all subscribers. It interacts with the database to store subscription details and uses a push library to send notifications.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const { Router } = require("express");
|
|
const { getPublicKey, sendPushToAll } = require("../lib/push");
|
|
const { db } = require("../db");
|
|
|
|
const router = Router();
|
|
|
|
router.get("/vapid-public-key", (_req, res) => {
|
|
res.json({ publicKey: getPublicKey() });
|
|
});
|
|
|
|
router.post("/subscribe", (req, res) => {
|
|
const { endpoint, keys } = req.body;
|
|
if (!endpoint || !keys?.p256dh || !keys?.auth) {
|
|
return res.status(400).json({ error: { message: "Missing required fields" } });
|
|
}
|
|
db.prepare(
|
|
"INSERT OR REPLACE INTO push_subscriptions (endpoint, p256dh, auth) VALUES (?, ?, ?)"
|
|
).run(endpoint, keys.p256dh, keys.auth);
|
|
res.json({ ok: true });
|
|
});
|
|
|
|
router.delete("/subscribe", (req, res) => {
|
|
const { endpoint } = req.body;
|
|
if (!endpoint) {
|
|
return res.status(400).json({ error: { message: "Missing endpoint" } });
|
|
}
|
|
db.prepare("DELETE FROM push_subscriptions WHERE endpoint = ?").run(endpoint);
|
|
res.json({ ok: true });
|
|
});
|
|
|
|
router.post("/send", async (req, res) => {
|
|
const { title, body } = req.body;
|
|
if (!title || !body) {
|
|
return res.status(400).json({ error: { message: "Missing title or body" } });
|
|
}
|
|
try {
|
|
// `result` tells the caller which surfaces actually fired:
|
|
// { native: true|false, pushed: <count>, failed: <count> }
|
|
// so a silent "no subscribers, no Electron host" no-op stops looking like
|
|
// success on the client side.
|
|
const result = await sendPushToAll(db, title, body);
|
|
res.json({ ok: true, ...result });
|
|
} catch (err) {
|
|
res.status(500).json({ error: { message: err.message } });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|