From bd2a672c1436737b285c3a05f85b2757887a181c Mon Sep 17 00:00:00 2001 From: Wim Date: Fri, 23 Feb 2018 23:07:23 +0100 Subject: Refactor mattermost --- bridge/helper/helper.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'bridge/helper/helper.go') 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}) +} -- cgit v1.2.3