summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Rhymen/go-whatsapp/media.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/Rhymen/go-whatsapp/media.go')
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/media.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/media.go b/vendor/github.com/Rhymen/go-whatsapp/media.go
index 43ff424f..225eac8e 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/media.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/media.go
@@ -129,7 +129,17 @@ func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
return "", "", 0, fmt.Errorf("query media conn responded with %d", resp.Status)
}
- return resp.MediaConn.Hosts[0].Hostname, resp.MediaConn.Auth, resp.MediaConn.TTL, nil
+ var host string
+ for _, h := range resp.MediaConn.Hosts {
+ if h.Hostname!="" {
+ host = h.Hostname
+ break
+ }
+ }
+ if host == "" {
+ return "", "", 0, fmt.Errorf("query media conn responded with no host")
+ }
+ return host, resp.MediaConn.Auth, resp.MediaConn.TTL, nil
}
var mediaTypeMap = map[MediaType]string{
@@ -173,6 +183,10 @@ func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (downloadURL string
fileEncSha256 = sha.Sum(nil)
hostname, auth, _, err := wac.queryMediaConn()
+ if err != nil {
+ return "", nil, nil, nil, 0, err
+ }
+
token := base64.URLEncoding.EncodeToString(fileEncSha256)
q := url.Values{
"auth": []string{auth},