diff options
Diffstat (limited to 'mxlib')
-rw-r--r-- | mxlib/client.go | 6 | ||||
-rw-r--r-- | mxlib/mediaobject.go | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/mxlib/client.go b/mxlib/client.go index 6d87663..d8237d1 100644 --- a/mxlib/client.go +++ b/mxlib/client.go @@ -280,6 +280,11 @@ func (mx *Client) RoomTopicAs(room string, topic string, as_user string) error { } func (mx *Client) UploadMedia(m connector.MediaObject) (*MediaObject, error) { + // Return early if this is already a Matrix media object + if mxm, ok := m.(*MediaObject); ok { + return mxm, nil + } + reader, err := m.Read() if err != nil { return nil, err @@ -308,6 +313,7 @@ func (mx *Client) UploadMedia(m connector.MediaObject) (*MediaObject, error) { filename: m.Filename(), size: m.Size(), mimetype: m.Mimetype(), + imageSize: m.ImageSize(), MxcServer: mxc[0], MxcMediaId: mxc[1], } diff --git a/mxlib/mediaobject.go b/mxlib/mediaobject.go index 8a730d2..1c35187 100644 --- a/mxlib/mediaobject.go +++ b/mxlib/mediaobject.go @@ -5,6 +5,8 @@ import ( "fmt" "net/url" "net/http" + + "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) type MediaObject struct { @@ -12,6 +14,7 @@ type MediaObject struct { filename string size int64 mimetype string + imageSize *connector.ImageSize MxcServer string MxcMediaId string } @@ -28,6 +31,10 @@ func (m *MediaObject) Mimetype() string { return m.mimetype } +func (m *MediaObject) ImageSize() *connector.ImageSize { + return m.imageSize +} + func (m *MediaObject) Read() (io.ReadCloser, error) { req, err := http.NewRequest("GET", m.URL(), nil) if err != nil { |