mirror of https://github.com/matrix-org/gomatrix
Further appease pedants
This commit is contained in:
parent
2705b0af4c
commit
9f07f1d548
25
client.go
25
client.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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
|
// 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
|
// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
|
||||||
func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) {
|
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)
|
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.
|
// 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
|
// 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) {
|
func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, contentLength int64) (*RespMediaUpload, error) {
|
||||||
|
|
|
@ -86,7 +86,6 @@ type FileMessage struct {
|
||||||
Info FileInfo `json:"info"`
|
Info FileInfo `json:"info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ImageMessage is an m.image event
|
// ImageMessage is an m.image event
|
||||||
type ImageMessage struct {
|
type ImageMessage struct {
|
||||||
MsgType string `json:"msgtype"`
|
MsgType string `json:"msgtype"`
|
||||||
|
|
|
@ -163,7 +163,7 @@ type RespSync struct {
|
||||||
} `json:"rooms"`
|
} `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 {
|
type RespTurnServer struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
|
Loading…
Reference in New Issue