summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsiel Díaz Benítez <adbenitez@nauta.cu>2023-03-11 16:34:27 -0500
committerGitHub <noreply@github.com>2023-03-11 22:34:27 +0100
commit0917e173831e20f54fe08b1bb6442a0fdeb07776 (patch)
tree1150397834f28ccab663cc373d3c8f00c28e44c5
parent8587fa85854b8ba14a171edf1c9c7e8f066eb6fb (diff)
downloadmatterbridge-msglm-0917e173831e20f54fe08b1bb6442a0fdeb07776.tar.gz
matterbridge-msglm-0917e173831e20f54fe08b1bb6442a0fdeb07776.tar.bz2
matterbridge-msglm-0917e173831e20f54fe08b1bb6442a0fdeb07776.zip
Allow to send files in Extra via /api/message (api) (#1993)
-rw-r--r--bridge/api/api.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/bridge/api/api.go b/bridge/api/api.go
index 9e7679d3..c0bef0e2 100644
--- a/bridge/api/api.go
+++ b/bridge/api/api.go
@@ -1,6 +1,7 @@
package api
import (
+ "encoding/base64"
"encoding/json"
"net/http"
"sync"
@@ -12,6 +13,7 @@ import (
"github.com/42wim/matterbridge/bridge/config"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
+ "github.com/mitchellh/mapstructure"
ring "github.com/zfjagann/golang-ring"
)
@@ -137,6 +139,15 @@ func (b *API) handlePostMessage(c echo.Context) error {
message.Account = b.Account
message.ID = ""
message.Timestamp = time.Now()
+ for i, f := range message.Extra["file"] {
+ fi := config.FileInfo{}
+ mapstructure.Decode(f.(map[string]interface{}), &fi)
+ var data []byte
+ // mapstructure doesn't decode base64 into []byte, so it must be done manually for fi.Data
+ data, _ = base64.StdEncoding.DecodeString(f.(map[string]interface{})["Data"].(string))
+ fi.Data = &data
+ message.Extra["file"][i] = fi
+ }
b.Log.Debugf("Sending message from %s on %s to gateway", message.Username, "api")
b.Remote <- message
return c.JSON(http.StatusOK, message)