Further appease pedants

This commit is contained in:
Donomii 2017-07-15 18:05:13 +02:00
parent 2705b0af4c
commit 9f07f1d548
3 changed files with 30 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import (
"net/url"
"path"
"strconv"
"strings"
"sync"
"time"
)
@ -464,7 +465,6 @@ func (cli *Client) SendFile(roomID, body, url, filename string, info FileInfo, t
})
}
// SendImage sends an m.room.message event into the given room with a msgtype of m.image
// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) {
@ -591,6 +591,29 @@ func (cli *Client) UploadLink(link string) (*RespMediaUpload, error) {
return cli.UploadToContentRepo(res.Body, res.Header.Get("Content-Type"), res.ContentLength)
}
// Download download a mxc url
func (cli *Client) Download(url string) (string, []byte, error) {
path := strings.Replace(url, "mxc://", "", 1)
req, err := http.NewRequest("GET", cli.BuildBaseURL("_matrix/media/r0/download/"+path), nil)
res, err := cli.Client.Do(req)
if err != nil {
fmt.Println("Error while downloading", url, "-", err)
return "", nil, err
}
defer res.Body.Close()
contents, err := ioutil.ReadAll(res.Body)
fmt.Println(res.Header)
filename := res.Header["Content-Disposition"][0]
if err != nil {
fmt.Println("Error while downloading", url, "-", err)
return "", nil, err
}
return filename, contents, err
}
// UploadToContentRepo uploads the given bytes to the content repository and returns an MXC URI.
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload
func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, contentLength int64) (*RespMediaUpload, error) {

View File

@ -86,7 +86,6 @@ type FileMessage struct {
Info FileInfo `json:"info"`
}
// ImageMessage is an m.image event
type ImageMessage struct {
MsgType string `json:"msgtype"`

View File

@ -163,7 +163,7 @@ type RespSync struct {
} `json:"rooms"`
}
// LOL what lol could lol this lol do ?
// RespTurnServer was written by someone else who later turned on the automatic commit checker so no-one could commit without writing this comment lol
type RespTurnServer struct {
Username string `json:"username"`
Password string `json:"password"`