feat: only attempt to parse image attachments

This commit is contained in:
Johan Fagerberg 2026-02-25 21:52:51 +01:00 committed by Manuel Rüger
parent 6f18a47ed0
commit 9795f74f0f

View File

@ -222,10 +222,14 @@ func prepareAttachment(opener vfs.Opener, base, name string) (Attachment, error)
Replace: name, Replace: name,
} }
// Try to detect image dimensions // Try to detect image dimensions if it's an image attachment
if config, _, err := image.DecodeConfig(bytes.NewReader(fileBytes)); err == nil { ext := strings.ToLower(filepath.Ext(name))
attachment.Width = strconv.Itoa(config.Width) switch ext {
attachment.Height = strconv.Itoa(config.Height) case ".jpg", ".jpeg", ".png", ".gif":
if config, _, err := image.DecodeConfig(bytes.NewReader(fileBytes)); err == nil {
attachment.Width = strconv.Itoa(config.Width)
attachment.Height = strconv.Itoa(config.Height)
}
} }
return attachment, nil return attachment, nil