Fixed image dimention error
Deploy Frontend / build-and-deploy (push) Has been cancelled
Details
Deploy Frontend / build-and-deploy (push) Has been cancelled
Details
This commit is contained in:
parent
13bc512e66
commit
2eb37cc7ac
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue