Allow specifying maximum download size of media using MediaDownloadSize (slack,telegram,matrix)

This commit is contained in:
Wim 2017-12-19 23:44:13 +01:00
parent 265457b451
commit d0c4fe78ee
5 changed files with 15 additions and 3 deletions

View File

@ -182,6 +182,9 @@ func NewConfig(cfgfile string) *Config {
if fail { if fail {
log.Fatalf("Fix your config. Please see changelog for more information") log.Fatalf("Fix your config. Please see changelog for more information")
} }
if cfg.General.MediaDownloadSize == 0 {
cfg.General.MediaDownloadSize = 1000000
}
return &cfg return &cfg
} }

View File

@ -175,7 +175,7 @@ func (b *Bmatrix) handlematrix() error {
size := info["size"].(float64) size := info["size"].(float64)
name := ev.Content["body"].(string) name := ev.Content["body"].(string)
flog.Debugf("trying to download %#v with size %#v", name, size) flog.Debugf("trying to download %#v with size %#v", name, size)
if size <= 1000000 { if size <= float64(b.General.MediaDownloadSize) {
data, err := helper.DownloadFile(url) data, err := helper.DownloadFile(url)
if err != nil { if err != nil {
flog.Errorf("download %s failed %#v", url, err) flog.Errorf("download %s failed %#v", url, err)

View File

@ -288,7 +288,7 @@ func (b *Bslack) handleSlack() {
// if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra // if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra
if message.Raw.File != nil { if message.Raw.File != nil {
// limit to 1MB for now // limit to 1MB for now
if message.Raw.File.Size <= 1000000 { if message.Raw.File.Size <= b.General.MediaDownloadSize {
comment := "" comment := ""
data, err := b.downloadFile(message.Raw.File.URLPrivateDownload) data, err := b.downloadFile(message.Raw.File.URLPrivateDownload)
if err != nil { if err != nil {

View File

@ -299,7 +299,7 @@ func (b *Btelegram) handleDownload(file interface{}, msg *config.Message) {
// if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra // if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra
// limit to 1MB for now // limit to 1MB for now
flog.Debugf("trying to download %#v fileid %#v with size %#v", name, fileid, size) flog.Debugf("trying to download %#v fileid %#v with size %#v", name, fileid, size)
if size <= 1000000 { if size <= b.General.MediaDownloadSize {
data, err := helper.DownloadFile(url) data, err := helper.DownloadFile(url)
if err != nil { if err != nil {
flog.Errorf("download %s failed %#v", url, err) flog.Errorf("download %s failed %#v", url, err)

View File

@ -1044,6 +1044,15 @@ MediaServerUpload="https://user:pass@yourserver.com/upload"
#OPTIONAL (default empty) #OPTIONAL (default empty)
MediaServerDownload="https://youserver.com/download" MediaServerDownload="https://youserver.com/download"
#MediaDownloadSize is the maximum size of attachments, videos, images
#matterbridge will download and upload this file to bridges that also support uploading files.
#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
#slack, telegram and matrix
#
#Optional (default 1000000 (1 megabyte))
MediaDownloadSize=1000000
################################################################### ###################################################################
#Gateway configuration #Gateway configuration