aboutsummaryrefslogtreecommitdiff
path: root/connector/mediaobject.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-21 15:57:53 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-21 15:57:53 +0100
commitddd5936fb1f92432123a9a30d1d3a1fa644a4f8e (patch)
tree6a06aac9b5e676a2987f4bf612abea5500155ea2 /connector/mediaobject.go
parent92d380aa86dfd3e60f5b8d826ec96c0fbc17614a (diff)
downloadeasybridge-ddd5936fb1f92432123a9a30d1d3a1fa644a4f8e.tar.gz
easybridge-ddd5936fb1f92432123a9a30d1d3a1fa644a4f8e.zip
Files&images Mattermost->Matrix works
Diffstat (limited to 'connector/mediaobject.go')
-rw-r--r--connector/mediaobject.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/connector/mediaobject.go b/connector/mediaobject.go
index 75635ee..c6634b7 100644
--- a/connector/mediaobject.go
+++ b/connector/mediaobject.go
@@ -1,6 +1,7 @@
package connector
import (
+ "bytes"
"io"
"net/http"
"os"
@@ -41,6 +42,11 @@ func (m *FileMediaObject) Mimetype() string {
return http.DetectContentType(buffer)
}
+func (m *FileMediaObject) ImageSize() *ImageSize {
+ // TODO but not really usefull
+ return nil
+}
+
func (m *FileMediaObject) Read() (io.ReadCloser, error) {
return os.Open(m.Path)
}
@@ -48,3 +54,82 @@ func (m *FileMediaObject) Read() (io.ReadCloser, error) {
func (m *FileMediaObject) URL() string {
return ""
}
+
+// ----
+
+type UrlMediaObject struct {
+ ObjectFilename string
+ ObjectSize int64
+ ObjectMimetype string
+ ObjectURL string
+ ObjectImageSize *ImageSize
+}
+
+func (m *UrlMediaObject) Filename() string {
+ return m.ObjectFilename
+}
+
+func (m *UrlMediaObject) Size() int64 {
+ return m.ObjectSize
+}
+
+func (m *UrlMediaObject) Mimetype() string {
+ return m.ObjectMimetype
+}
+
+func (m *UrlMediaObject) ImageSize() *ImageSize {
+ return m.ObjectImageSize
+}
+
+func (m *UrlMediaObject) Read() (io.ReadCloser, error) {
+ resp, err := http.Get(m.ObjectURL)
+ if err != nil {
+ return nil, err
+ }
+ return resp.Body, nil
+}
+
+func (m *UrlMediaObject) URL() string {
+ return m.ObjectURL
+}
+
+// ----
+
+type BlobMediaObject struct {
+ ObjectFilename string
+ ObjectSize int64
+ ObjectMimetype string
+ ObjectImageSize *ImageSize
+ ObjectData []byte
+}
+
+func (m *BlobMediaObject) Filename() string {
+ return m.ObjectFilename
+}
+
+func (m *BlobMediaObject) Size() int64 {
+ return m.ObjectSize
+}
+
+func (m *BlobMediaObject) Mimetype() string {
+ return m.ObjectMimetype
+}
+
+func (m *BlobMediaObject) ImageSize() *ImageSize {
+ return m.ObjectImageSize
+}
+
+func (m *BlobMediaObject) Read() (io.ReadCloser, error) {
+ return nullCloseReader{bytes.NewBuffer(m.ObjectData)}, nil
+}
+
+func (m *BlobMediaObject) URL() string {
+ return ""
+}
+
+type nullCloseReader struct {
+ io.Reader
+}
+func (ncr nullCloseReader) Close() error {
+ return nil
+}