diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/commands.go | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/ui/commands.go b/ui/commands.go index 0cbf2b0..6e9d3b7 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -309,26 +309,18 @@ func uploadImage(cmd *Command, filePath string, fileName string) { } fileSize := len(fileData) - imageMetadata, _, err := image.DecodeConfig(bytes.NewReader(fileData)) + imageMetadata, format, err := image.DecodeConfig(bytes.NewReader(fileData)) if err != nil { cmd.Reply("Failed to decode image") return } - var imageType string - // TODO: Detect all types matrix supports - if fileSize >= 4 && fileData[0] == 0xFF && fileData[1] == 0xD8 && fileData[fileSize-2] == 0xFF && fileData[fileSize-1] == 0xD9 { - imageType = "jpeg" - } else if fileSize >= 8 && string(fileData[0:8]) == "\211PNG\r\n\032\n" { - imageType = "png" - } - - if imageType == "" { - cmd.Reply("Only jpeg, png, webm and mp4 files are supported") + if format == "" { + cmd.Reply("Unknown image format for file: %s", filePath) return } - imageMimeType := fmt.Sprintf("image/%s", imageType) + imageMimeType := fmt.Sprintf("image/%s", format) resp, err := cmd.Matrix.Client().UploadBytesWithName(fileData, imageMimeType, fileName) if err != nil { |