status-go/protocol/discord/assets.go

37 lines
791 B
Go
Raw Normal View History

2022-09-29 11:50:23 +00:00
package discord
import (
"io/ioutil"
"net/http"
"time"
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/images"
)
func DownloadAvatarAsset(url string) ([]byte, error) {
imgs, err := images.GenerateIdentityImagesFromURL(url)
if err != nil {
return nil, err
}
payload := imgs[0].Payload
return payload, nil
}
func DownloadAsset(url string) ([]byte, string, error) {
client := http.Client{Timeout: time.Minute}
res, err := client.Get(url)
if err != nil {
return nil, "", err
}
defer func() {
if err := res.Body.Close(); err != nil {
log.Error("failed to close message asset http request body", "err", err)
}
}()
contentType := res.Header.Get("Content-Type")
bodyBytes, err := ioutil.ReadAll(res.Body)
return bodyBytes, contentType, err
}