return who opened the door
All checks were successful
Build and push image for doorman / docker (push) Successful in 3m19s

This commit is contained in:
Martin Dimitrov 2024-02-27 19:00:38 -08:00
parent 7366bcbec0
commit 938213634d

View File

@ -7,10 +7,11 @@ const router = express.Router();
const client = await getRedisClient(); const client = await getRedisClient();
router.get('/:id/status', async(req, res) => { router.get('/:id/status', async(req, res) => {
const isOpen = await client.getClient().exists(doorStatusKey(req.params.id)); const isOpen = await client.get(doorStatusKey(req.params.id));
if (isOpen) { if (isOpen) {
res.status(200).json({ status: 'open' }); const fingerprint = JSON.parse(isOpen);
res.status(200).json({ status: 'open', fingerprint });
return; return;
} }
@ -19,13 +20,15 @@ router.get('/:id/status', async(req, res) => {
router.delete('/:id/status', async(req, res) => { router.delete('/:id/status', async(req, res) => {
await client.remove(doorStatusKey(req.params.id)); await client.remove(doorStatusKey(req.params.id));
res.status(200).json({ msg: 'Cleared status' }); res.status(200).json({ msg: `Closed the door ${req.params.id}` });
}); });
router.all('/:id/auth', ValidQueryParamAuth, async(req, res) => { router.all('/:id/auth', ValidQueryParamAuth, async(req, res) => {
const statusKey = doorStatusKey(req.params.id); const statusKey = doorStatusKey(req.params.id);
await client.put(statusKey, JSON.stringify((req as any).fingerprint)); const fingerprint = (req as any).fingerprint;
await client.put(statusKey, JSON.stringify(fingerprint));
await client.getClient().expire(statusKey, Bun.env.DOOR_OPEN_TIMEOUT); await client.getClient().expire(statusKey, Bun.env.DOOR_OPEN_TIMEOUT);
res.status(200).json({ msg: `Opened the door "${req.params.id}" for ${Bun.env.DOOR_OPEN_TIMEOUT}s` }); res.status(200).json({ msg: `Opened the door "${req.params.id}" for ${Bun.env.DOOR_OPEN_TIMEOUT}s` });
}); });