diff options
author | Wim <wim@42.be> | 2018-05-06 20:32:09 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2018-05-06 20:32:09 +0200 |
commit | c6c92e273dea524f029065516b23e6058bc39b9e (patch) | |
tree | ee842f021ee0f0a81fa91dbb3dd6b3f3858fde34 /gateway | |
parent | 467b373c43dfe5314d81a76032fbbf6b5f6917cc (diff) | |
download | matterbridge-msglm-c6c92e273dea524f029065516b23e6058bc39b9e.tar.gz matterbridge-msglm-c6c92e273dea524f029065516b23e6058bc39b9e.tar.bz2 matterbridge-msglm-c6c92e273dea524f029065516b23e6058bc39b9e.zip |
Use only alphanumeric for file uploads to mediaserver. Closes #416
Diffstat (limited to 'gateway')
-rw-r--r-- | gateway/gateway.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go index 42259d99..0dddf897 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -23,6 +23,7 @@ import ( "github.com/hashicorp/golang-lru" "github.com/peterhellberg/emojilib" "net/http" + "path/filepath" "regexp" "strings" "time" @@ -409,6 +410,7 @@ func (gw *Gateway) modifyMessage(msg *config.Message) { } func (gw *Gateway) handleFiles(msg *config.Message) { + reg := regexp.MustCompile("[^a-zA-Z0-9]+") // if we don't have a attachfield or we don't have a mediaserver configured return if msg.Extra == nil || gw.Config.General.MediaServerUpload == "" { return @@ -421,6 +423,10 @@ func (gw *Gateway) handleFiles(msg *config.Message) { } for i, f := range msg.Extra["file"] { fi := f.(config.FileInfo) + ext := filepath.Ext(fi.Name) + fi.Name = fi.Name[0 : len(fi.Name)-len(ext)] + fi.Name = reg.ReplaceAllString(fi.Name, "_") + fi.Name = fi.Name + ext sha1sum := fmt.Sprintf("%x", sha1.Sum(*fi.Data)) reader := bytes.NewReader(*fi.Data) url := gw.Config.General.MediaServerUpload + "/" + sha1sum + "/" + fi.Name |