Merge pull request 'Added image extension detecting' (#58) from fix-permissions into main
Deploy / deploy (push) Failing after 35s Details

Reviewed-on: https://72.56.235.246.nip.io/gitea/romanskijdev/ruspet_portal_back/pulls/58
This commit is contained in:
romanskijdev 2026-07-12 19:18:34 +03:00
commit 72eaf50ec3
1 changed files with 18 additions and 1 deletions

View File

@ -11,6 +11,22 @@ import (
"github.com/sirupsen/logrus"
)
func detectImageExtension(data []byte) string {
contentType := http.DetectContentType(data)
switch contentType {
case "image/png":
return "photo.png"
case "image/jpeg":
return "photo.jpg"
case "image/webp":
return "photo.webp"
case "image/gif":
return "photo.gif"
default:
return "photo.jpg"
}
}
// SendPhoto отправляет фото по URL, пути к файлу или base64
func (c *Client) SendPhoto(chatID int64, source string, caption string, opts ...MessageOptions) (*SentMessage, error) {
var photo tgbotapi.RequestFileData
@ -23,7 +39,8 @@ func (c *Client) SendPhoto(chatID int64, source string, caption string, opts ...
if err != nil {
return nil, fmt.Errorf("tgkit: decode base64: %w", err)
}
photo = tgbotapi.FileBytes{Name: "photo.jpg", Bytes: data}
fileName := detectImageExtension(data)
photo = tgbotapi.FileBytes{Name: fileName, Bytes: data}
default:
photo = tgbotapi.FilePath(source)
}