diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index 988e8b4..434e299 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -244,13 +244,16 @@ func (gc *GMClient) uploadMatrixMedia(ctx context.Context, content *event.Messag case event.MsgVideo, event.MsgAudio: var extension string mimeType, extension = mediaUploadType(content, mimeType) - var groupID, recipientID string + req := groupmeext.UploadRequest{SenderId: gc.Meta.GMID, Extension: extension} if portalType == PortalTypeDM { - recipientID = string(gmid) + req.RecipientId = string(gmid) } else { - groupID = string(gmid) + req.GroupId = string(gmid) } - uploaded, err := groupmeext.UploadMedia(ctx, gc.Meta.Token, gc.Meta.GMID, groupID, recipientID, data, extension, mimeType) + if content.MsgType == event.MsgVideo && content.Info != nil { + req.Width, req.Height = content.Info.Width, content.Info.Height + } + uploaded, err := groupmeext.UploadMedia(ctx, gc.Meta.Token, req, data, mimeType) if err != nil { return nil, wrapGroupMeError(err, "failed to upload media").WithIsCertain(true) } diff --git a/pkg/groupmeext/message.go b/pkg/groupmeext/message.go index 8c0cf0a..8eca085 100644 --- a/pkg/groupmeext/message.go +++ b/pkg/groupmeext/message.go @@ -115,12 +115,15 @@ func GetFileMetadata(ctx context.Context, groupID groupme.ID, fileID, token stri } // Upload sessions require a group ID or recipient ID, plus size and extension. -type createUploadRequest struct { +// GroupMe's clients also send the dimensions of videos. +type UploadRequest struct { FileSize int64 `json:"FileSize"` SenderId string `json:"SenderId"` Extension string `json:"Extension"` GroupId string `json:"groupId,omitempty"` RecipientId string `json:"recipientId,omitempty"` + Width int `json:"width,omitempty"` + Height int `json:"height,omitempty"` } // UploadURL is a temporary signed upload destination. The other URLs are @@ -133,16 +136,10 @@ type UploadedMedia struct { } // UploadMedia uploads a video or voice note: it creates a session, then PUTs -// bytes to its signed URL without GroupMe credentials. Exactly one of groupID -// and recipientID must be set. -func UploadMedia(ctx context.Context, token, senderID, groupID, recipientID string, data []byte, extension, mimeType string) (*UploadedMedia, error) { - reqBody, err := json.Marshal(createUploadRequest{ - FileSize: int64(len(data)), - SenderId: senderID, - Extension: extension, - GroupId: groupID, - RecipientId: recipientID, - }) +// bytes to its signed URL without GroupMe credentials. +func UploadMedia(ctx context.Context, token string, req UploadRequest, data []byte, mimeType string) (*UploadedMedia, error) { + req.FileSize = int64(len(data)) + reqBody, err := json.Marshal(req) if err != nil { return nil, fmt.Errorf("failed to build upload session request: %w", err) }