diff options
author | Wim <wim@42.be> | 2018-02-23 23:07:23 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-02-27 23:22:09 +0100 |
commit | bd2a672c1436737b285c3a05f85b2757887a181c (patch) | |
tree | 7b8334a4f09cd3529383c6cc107734a87f55358f /bridge/helper/helper.go | |
parent | 82396e73f5c4036862009306c0557c13f9cd14ab (diff) | |
download | matterbridge-msglm-bd2a672c1436737b285c3a05f85b2757887a181c.tar.gz matterbridge-msglm-bd2a672c1436737b285c3a05f85b2757887a181c.tar.bz2 matterbridge-msglm-bd2a672c1436737b285c3a05f85b2757887a181c.zip |
Refactor mattermost
Diffstat (limited to 'bridge/helper/helper.go')
-rw-r--r-- | bridge/helper/helper.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index 8bb105a4..907642c1 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "github.com/42wim/matterbridge/bridge/config" + log "github.com/sirupsen/logrus" "io" "net/http" "time" @@ -61,3 +62,22 @@ func GetAvatar(av map[string]string, userid string, general *config.Protocol) st } return "" } + +func HandleDownloadSize(flog *log.Entry, msg *config.Message, name string, size int64, general *config.Protocol) error { + flog.Debugf("Trying to download %#v with size %#v", name, size) + if int(size) > general.MediaDownloadSize { + msg.Event = config.EVENT_FILE_FAILURE_SIZE + msg.Extra[msg.Event] = append(msg.Extra[msg.Event], config.FileInfo{Name: name, Comment: msg.Text, Size: size}) + return fmt.Errorf("File %#v to large to download (%#v). MediaDownloadSize is %#v", name, size, general.MediaDownloadSize) + } + return nil +} + +func HandleDownloadData(flog *log.Entry, msg *config.Message, name, comment, url string, data *[]byte, general *config.Protocol) { + var avatar bool + flog.Debugf("Download OK %#v %#v", name, len(*data)) + if msg.Event == config.EVENT_AVATAR_DOWNLOAD { + avatar = true + } + msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: name, Data: data, URL: url, Comment: comment, Avatar: avatar}) +} |