fix: opravy po review
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 21s
CI / Generate TypeScript types (pull_request) Successful in 47s
CI / Build server (push) Successful in 27s
CI / Server unit tests (pull_request) Successful in 20s
CI / Build server (pull_request) Successful in 27s
CI / Build client (pull_request) Successful in 40s
CI / Playwright E2E tests (pull_request) Successful in 1m20s
CI / Build and push Docker image (pull_request) Has been skipped
CI / Notify (pull_request) Has been skipped
CI / Build client (push) Successful in 4m13s
CI / Playwright E2E tests (push) Successful in 6m7s
CI / Build and push Docker image (push) Has been skipped
CI / Notify (push) Successful in 6s

This commit is contained in:
2026-05-07 08:56:49 +02:00
parent 21d7224fb4
commit 5f03471541
14 changed files with 359 additions and 88 deletions
+15
View File
@@ -1,4 +1,5 @@
import webpush from 'web-push';
import crypto from 'crypto';
import getStorage from './storage';
import { getClientData, getToday } from './service';
import { getIsWeekend } from './utils';
@@ -65,6 +66,19 @@ export function getVapidPublicKey(): string | undefined {
return process.env.VAPID_PUBLIC_KEY;
}
function generateQuickChoiceToken(login: string): string {
const today = new Date().toISOString().slice(0, 10);
const secret = process.env.JWT_SECRET ?? '';
return crypto.createHmac('sha256', secret).update(`${login}:${today}`).digest('hex');
}
/** Ověří jednorázový token z push notifikace. */
export function verifyQuickChoiceToken(login: string, token: string): boolean {
if (!login || !token || token.length !== 64) return false;
const expected = generateQuickChoiceToken(login);
return crypto.timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(token, 'hex'));
}
/** Zkontroluje a odešle připomínky uživatelům, kteří si nezvolili oběd. */
async function checkAndSendReminders(): Promise<void> {
@@ -115,6 +129,7 @@ async function checkAndSendReminders(): Promise<void> {
title: 'Luncher',
body: 'Ještě nemáte zvolený oběd!',
login,
token: generateQuickChoiceToken(login),
})
);
lastReminded.set(login, Date.now());