summaryrefslogtreecommitdiffstats
path: root/bridge/mattermost/mattermost.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-02-02 20:23:55 +0100
committerWim <wim@42.be>2018-02-02 20:23:55 +0100
commit169c614489d34d282f814967e252d5630dc9ea9e (patch)
tree2aa0b6f49bcef4f50c80faeba29b5902d0f48e58 /bridge/mattermost/mattermost.go
parentda908c438a03bb0d575f05cbd42bfd0b3bd304c0 (diff)
downloadmatterbridge-msglm-169c614489d34d282f814967e252d5630dc9ea9e.tar.gz
matterbridge-msglm-169c614489d34d282f814967e252d5630dc9ea9e.tar.bz2
matterbridge-msglm-169c614489d34d282f814967e252d5630dc9ea9e.zip
Download files and reupload to supported bridges (mattermost). Closes #357
Diffstat (limited to 'bridge/mattermost/mattermost.go')
-rw-r--r--bridge/mattermost/mattermost.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index e84e61f1..7f5b6f8e 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -287,8 +287,24 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) {
m.Event = config.EVENT_MSG_DELETE
}
if len(message.Post.FileIds) > 0 {
- for _, link := range b.mc.GetFileLinks(message.Post.FileIds) {
- m.Text = m.Text + "\n" + link
+ for _, id := range message.Post.FileIds {
+ url, _ := b.mc.Client.GetFileLink(id)
+ finfo, resp := b.mc.Client.GetFileInfo(id)
+ if resp.Error != nil {
+ continue
+ }
+ flog.Debugf("trying to download %#v fileid %#v with size %#v", finfo.Name, finfo.Id, finfo.Size)
+ if int(finfo.Size) > b.General.MediaDownloadSize {
+ flog.Errorf("File %#v to large to download (%#v). MediaDownloadSize is %#v", finfo.Name, finfo.Size, b.General.MediaDownloadSize)
+ continue
+ }
+ data, resp := b.mc.Client.DownloadFile(id, true)
+ if resp.Error != nil {
+ flog.Errorf("download %s failed %#v", finfo.Name, resp.Error)
+ continue
+ }
+ flog.Debugf("download OK %#v %#v", finfo.Name, len(data))
+ m.Extra["file"] = append(m.Extra["file"], config.FileInfo{Name: finfo.Name, Data: &data, URL: url, Comment: message.Text})
}
}
mchan <- m