From 2eb37cc7ac1909654235b40fcc2695fd5bc1496b Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Sun, 12 Jul 2026 19:25:07 +0300 Subject: [PATCH] Fixed image dimention error --- .../components/SendNotificationForm.tsx | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/pages/notifications/components/SendNotificationForm.tsx b/src/pages/notifications/components/SendNotificationForm.tsx index 52bad0f..bc5cb2c 100644 --- a/src/pages/notifications/components/SendNotificationForm.tsx +++ b/src/pages/notifications/components/SendNotificationForm.tsx @@ -70,6 +70,8 @@ export default function SendNotificationForm() { [departments], ) + const MAX_ASPECT_RATIO = 20 // Telegram Bot API ограничение + const handlePhotoChange = (file: File | null) => { if (!file) { setPhotoBase64(null) @@ -77,12 +79,29 @@ export default function SendNotificationForm() { setPhotoPreviewUrl(null) return } + const reader = new FileReader() reader.onload = () => { const result = reader.result as string - setPhotoBase64(result.split(',')[1] || '') - setPhotoFileName(file.name) - setPhotoPreviewUrl(result) + const img = new window.Image() + img.onload = () => { + const ratio = Math.max(img.width, img.height) / Math.min(img.width, img.height) + const sumDimensions = img.width + img.height + + if (ratio > MAX_ASPECT_RATIO || sumDimensions > 10000) { + notifications.show({ + title: 'Некорректное изображение', + message: `Telegram не примет это фото: слишком вытянутые пропорции (${img.width}×${img.height}). Соотношение сторон не должно превышать 20:1.`, + color: 'red', + }) + return + } + + setPhotoBase64(result.split(',')[1] || '') + setPhotoFileName(file.name) + setPhotoPreviewUrl(result) + } + img.src = result } reader.readAsDataURL(file) }