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],
|
[departments],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MAX_ASPECT_RATIO = 20 // Telegram Bot API ограничение
|
||||||
|
|
||||||
const handlePhotoChange = (file: File | null) => {
|
const handlePhotoChange = (file: File | null) => {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
setPhotoBase64(null)
|
setPhotoBase64(null)
|
||||||
|
|
@ -77,12 +79,29 @@ export default function SendNotificationForm() {
|
||||||
setPhotoPreviewUrl(null)
|
setPhotoPreviewUrl(null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
const result = reader.result as string
|
const result = reader.result as string
|
||||||
setPhotoBase64(result.split(',')[1] || '')
|
const img = new window.Image()
|
||||||
setPhotoFileName(file.name)
|
img.onload = () => {
|
||||||
setPhotoPreviewUrl(result)
|
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)
|
reader.readAsDataURL(file)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue