This commit is contained in:
adbenitez
2023-02-27 03:19:44 -05:00
parent eb4b5aaaca
commit f8d359d6e2
2 changed files with 7 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
ring "github.com/zfjagann/golang-ring"
"github.com/mitchellh/mapstructure"
)
type API struct {
@@ -137,6 +138,11 @@ 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)
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)

View File

@@ -15,7 +15,6 @@ import (
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/gateway/bridgemap"
"github.com/mitchellh/mapstructure"
)
// handleEventFailure handles failures and reconnects bridges.
@@ -85,11 +84,7 @@ func (gw *Gateway) handleFiles(msg *config.Message) {
}
for i, f := range msg.Extra["file"] {
fi, ok := f.(config.FileInfo)
if !ok {
fi = config.FileInfo{}
mapstructure.Decode(f.(map[string]interface{}), &fi)
}
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, "_")