diff options
author | Tadeo Kondrak <me@tadeo.ca> | 2021-02-15 14:34:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-15 22:34:14 +0100 |
commit | c147ba1da1d4d5f181c4de796e414a72248447cc (patch) | |
tree | c1ca3e66f1a29c5820b8c17da098570344a9caa7 /bridge/helper | |
parent | 10f044c3dd971868523459b708a5bcbf81611df7 (diff) | |
download | matterbridge-msglm-c147ba1da1d4d5f181c4de796e414a72248447cc.tar.gz matterbridge-msglm-c147ba1da1d4d5f181c4de796e414a72248447cc.tar.bz2 matterbridge-msglm-c147ba1da1d4d5f181c4de796e414a72248447cc.zip |
Handle Rocket.Chat attachments (#1395)
Diffstat (limited to 'bridge/helper')
-rw-r--r-- | bridge/helper/helper.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index cbb319ac..2d16dc93 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -51,6 +51,30 @@ func DownloadFileAuth(url string, auth string) (*[]byte, error) { return &data, nil } +// DownloadFileAuthRocket downloads the given URL using the specified Rocket user ID and authentication token. +func DownloadFileAuthRocket(url, token, userID string) (*[]byte, error) { + var buf bytes.Buffer + client := &http.Client{ + Timeout: time.Second * 5, + } + req, err := http.NewRequest("GET", url, nil) + + req.Header.Add("X-Auth-Token", token) + req.Header.Add("X-User-Id", userID) + + if err != nil { + return nil, err + } + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + _, err = io.Copy(&buf, resp.Body) + data := buf.Bytes() + return &data, err +} + // GetSubLines splits messages in newline-delimited lines. If maxLineLength is // specified as non-zero GetSubLines will also clip long lines to the maximum // length and insert a warning marker that the line was clipped. |