Skip to content

Commit

Permalink
connector/matrix: force .jpg suffix on image filenames without extens…
Browse files Browse the repository at this point in the history
…ions

Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Nov 18, 2024
1 parent 1f22aa2 commit dd64d2c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/connector/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit dd64d2c

Please sign in to comment.