connector/matrix: force .jpg suffix on image filenames without extensions
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
+13
-3
@@ -33,12 +33,22 @@ import (
|
||||
"go.mau.fi/mautrix-telegram/pkg/connector/waveform"
|
||||
)
|
||||
|
||||
func getMediaFilename(content *event.MessageEventContent) string {
|
||||
func getMediaFilename(content *event.MessageEventContent) (filename string) {
|
||||
if content.FileName != "" {
|
||||
return content.FileName
|
||||
filename = content.FileName
|
||||
} else {
|
||||
return content.Body
|
||||
filename = content.Body
|
||||
}
|
||||
if filename == "" {
|
||||
return "image.jpg" // Assume it's a JPEG image
|
||||
}
|
||||
if content.MsgType == event.MsgImage && (!strings.HasSuffix(filename, ".jpg") && !strings.HasSuffix(filename, ".jpeg") && !strings.HasSuffix(filename, ".png")) {
|
||||
if content.Info != nil && content.Info.MimeType != "" {
|
||||
return filename + strings.TrimPrefix(content.Info.MimeType, "image/")
|
||||
}
|
||||
return filename + ".jpg" // Assume it's a JPEG
|
||||
}
|
||||
return filename
|
||||
}
|
||||
|
||||
func (t *TelegramClient) transferMediaToTelegram(ctx context.Context, content *event.MessageEventContent, sticker bool) (tg.InputMediaClass, error) {
|
||||
|
||||
Reference in New Issue
Block a user