summaryrefslogtreecommitdiffstats
path: root/gateway/gateway.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-11-24 22:36:19 +0100
committerWim <wim@42.be>2017-11-24 22:36:19 +0100
commit1efe40add50a76b7a0ad95187f6034cc75845d16 (patch)
tree4a60722020653386e62a591ebc6b05d25622a865 /gateway/gateway.go
parentcbd73ee313df8d4e590835e451200e7bff24473f (diff)
downloadmatterbridge-msglm-1efe40add50a76b7a0ad95187f6034cc75845d16.tar.gz
matterbridge-msglm-1efe40add50a76b7a0ad95187f6034cc75845d16.tar.bz2
matterbridge-msglm-1efe40add50a76b7a0ad95187f6034cc75845d16.zip
Add initial support for an external mediaserver. #278
Add 2 extra options `MediaServerUpload` and `MediaServerDownload`, where the URL for upload and download can be specified. See https://github.com/42wim/matterbridge/wiki/Mediaserver-setup-%5Badvanced%5D for an example with caddy
Diffstat (limited to 'gateway/gateway.go')
-rw-r--r--gateway/gateway.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go
index e5d74ff2..8b1223f0 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -1,13 +1,16 @@
package gateway
import (
+ "bytes"
"fmt"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
log "github.com/Sirupsen/logrus"
// "github.com/davecgh/go-spew/spew"
+ "crypto/sha1"
"github.com/hashicorp/golang-lru"
"github.com/peterhellberg/emojilib"
+ "net/http"
"regexp"
"strings"
"time"
@@ -318,6 +321,34 @@ func (gw *Gateway) modifyMessage(msg *config.Message) {
msg.Gateway = gw.Name
}
+func (gw *Gateway) handleFiles(msg *config.Message) {
+ if msg.Extra == nil || gw.Config.General.MediaServerUpload == "" {
+ return
+ }
+ if len(msg.Extra["file"]) > 0 {
+ client := &http.Client{
+ Timeout: time.Second * 5,
+ }
+ for i, f := range msg.Extra["file"] {
+ fi := f.(config.FileInfo)
+ sha1sum := fmt.Sprintf("%x", sha1.Sum(*fi.Data))
+ reader := bytes.NewReader(*fi.Data)
+ url := gw.Config.General.MediaServerUpload + "/" + sha1sum + "/" + fi.Name
+ durl := gw.Config.General.MediaServerDownload + "/" + sha1sum + "/" + fi.Name
+ extra := msg.Extra["file"][i].(config.FileInfo)
+ extra.URL = durl
+ msg.Extra["file"][i] = extra
+ req, _ := http.NewRequest("PUT", url, reader)
+ req.Header.Set("Content-Type", "binary/octet-stream")
+ _, err := client.Do(req)
+ if err != nil {
+ log.Errorf("mediaserver upload failed: %#v", err)
+ }
+ log.Debugf("mediaserver download URL = %s", durl)
+ }
+ }
+}
+
func getChannelID(msg config.Message) string {
return msg.Channel + msg.Account
}