2022-09-29 11:50:23 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2024-10-28 20:54:17 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2022-09-29 11:50:23 +00:00
|
|
|
"github.com/status-im/status-go/images"
|
2024-10-28 20:54:17 +00:00
|
|
|
"github.com/status-im/status-go/logutils"
|
2022-09-29 11:50:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to close message asset http request body", zap.Error(err))
|
2022-09-29 11:50:23 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
contentType := res.Header.Get("Content-Type")
|
|
|
|
bodyBytes, err := ioutil.ReadAll(res.Body)
|
|
|
|
return bodyBytes, contentType, err
|
|
|
|
}
|