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) }