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"
)
@ -460,11 +461,10 @@ func (cli *Client) SendFile(roomID, body, url, filename string, info FileInfo, t
Body: body,
URL: url,
FileName: filename,
Info: info,
Info: info,
})
}
// 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

@ -79,14 +79,13 @@ type VideoMessage struct {
// FileMessage is an m.file event
type FileMessage struct {
MsgType string `json:"msgtype"`
Body string `json:"body"`
URL string `json:"url"`
MsgType string `json:"msgtype"`
Body string `json:"body"`
URL string `json:"url"`
FileName string `json:"filename"`
Info FileInfo `json:"info"`
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"`