forked from jshiffer/matterbridge
Download files and reupload to supported bridges (mattermost). Closes #357
This commit is contained in:
parent
da908c438a
commit
169c614489
@ -287,8 +287,24 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) {
|
|||||||
m.Event = config.EVENT_MSG_DELETE
|
m.Event = config.EVENT_MSG_DELETE
|
||||||
}
|
}
|
||||||
if len(message.Post.FileIds) > 0 {
|
if len(message.Post.FileIds) > 0 {
|
||||||
for _, link := range b.mc.GetFileLinks(message.Post.FileIds) {
|
for _, id := range message.Post.FileIds {
|
||||||
m.Text = m.Text + "\n" + link
|
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
|
mchan <- m
|
||||||
|
@ -1053,7 +1053,7 @@ MediaServerDownload="https://youserver.com/download"
|
|||||||
#eg downloading from slack to upload it to mattermost
|
#eg downloading from slack to upload it to mattermost
|
||||||
#
|
#
|
||||||
#It will only download from bridges that don't have public links available, which are for the moment
|
#It will only download from bridges that don't have public links available, which are for the moment
|
||||||
#slack, telegram and matrix
|
#slack, telegram, matrix and mattermost
|
||||||
#
|
#
|
||||||
#Optional (default 1000000 (1 megabyte))
|
#Optional (default 1000000 (1 megabyte))
|
||||||
MediaDownloadSize=1000000
|
MediaDownloadSize=1000000
|
||||||
|
Loading…
Reference in New Issue
Block a user