fix: opravy generování QR kódů, zobrazení také na stránce objednání
CI / Generate TypeScript types (push) Successful in 14s
CI / Server unit tests (push) Successful in 21s
CI / Build server (push) Successful in 25s
CI / Build client (push) Successful in 34s
CI / Playwright E2E tests (push) Successful in 1m18s
CI / Build and push Docker image (push) Successful in 49s
CI / Notify (push) Successful in 3s
CI / Generate TypeScript types (push) Successful in 14s
CI / Server unit tests (push) Successful in 21s
CI / Build server (push) Successful in 25s
CI / Build client (push) Successful in 34s
CI / Playwright E2E tests (push) Successful in 1m18s
CI / Build and push Docker image (push) Successful in 49s
CI / Notify (push) Successful in 3s
This commit is contained in:
+19
-5
@@ -44,6 +44,24 @@ function createStorageKey(customerName: string, id: string): string {
|
||||
return `qr_${nameHash}_${id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Očistí zprávu (účel platby) pro QR platbu:
|
||||
* - transliteruje diakritiku na základní písmena (š→s, č→c, ř→r, ...)
|
||||
* - odstraní zbylé znaky mimo ISO 8859-1
|
||||
* - odstraní '*', který v QR platbě slouží jako oddělovač polí
|
||||
* - ořízne na max. 60 znaků
|
||||
*
|
||||
* @param message původní zpráva
|
||||
* @returns očištěná zpráva vhodná pro QR platbu
|
||||
*/
|
||||
export function sanitizeQrMessage(message: string): string {
|
||||
const sanitized = message
|
||||
.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // diakritika → základní písmeno
|
||||
.replace(/[^\x00-\xff]/g, '') // znaky mimo ISO 8859-1
|
||||
.replace(/\*/g, ''); // '*' je v QR platbě oddělovač
|
||||
return sanitized.length > 60 ? sanitized.substring(0, 60) : sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vygeneruje a uloží obrázek platebního QR kódu do storage (Redis/JSON).
|
||||
* Data přežijí redeploy — není třeba persistentní filesystém.
|
||||
@@ -56,11 +74,7 @@ function createStorageKey(customerName: string, id: string): string {
|
||||
* @param id unikátní identifikátor (UUID) tohoto QR kódu
|
||||
*/
|
||||
export async function generateQr(customerName: string, bankAccountNumber: string, bankAccountHolder: string, amount: number, message: string, id: string): Promise<void> {
|
||||
// Zpráva nesmí obsahovat '*' a znaky mimo ISO 8859-1; délka max. 60 znaků
|
||||
message = message.replace(/[^\x00-\xff]/g, '').replace(/\*/g, '');
|
||||
if (message.length > 60) {
|
||||
message = message.substring(0, 60);
|
||||
}
|
||||
message = sanitizeQrMessage(message);
|
||||
const payload = {
|
||||
iban: convertBbanToIban(bankAccountNumber),
|
||||
amount,
|
||||
|
||||
Reference in New Issue
Block a user