return who opened the door
All checks were successful
Build and push image for doorman / docker (push) Successful in 3m19s
All checks were successful
Build and push image for doorman / docker (push) Successful in 3m19s
This commit is contained in:
parent
7366bcbec0
commit
938213634d
@ -7,10 +7,11 @@ const router = express.Router();
|
||||
const client = await getRedisClient();
|
||||
|
||||
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) {
|
||||
res.status(200).json({ status: 'open' });
|
||||
const fingerprint = JSON.parse(isOpen);
|
||||
res.status(200).json({ status: 'open', fingerprint });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -19,13 +20,15 @@ router.get('/:id/status', async(req, res) => {
|
||||
|
||||
router.delete('/:id/status', async(req, res) => {
|
||||
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) => {
|
||||
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);
|
||||
res.status(200).json({ msg: `Opened the door "${req.params.id}" for ${Bun.env.DOOR_OPEN_TIMEOUT}s` });
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user