Skip to content

Commit

Permalink
allow to send files in Extra via /api/message
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Feb 27, 2023
1 parent 24f6747 commit d0a4c06
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bridge/api/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"encoding/base64"
"encoding/json"
"net/http"
"sync"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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, err = 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)
Expand Down

0 comments on commit d0a4c06

Please sign in to comment.