diff --git a/storage/minio.go b/storage/minio.go index d0f0922..367a58b 100644 --- a/storage/minio.go +++ b/storage/minio.go @@ -114,7 +114,7 @@ func (s *Minio) List(objectPrefix string) ([]string, error) { return result, nil } -func (s *Minio) Url(objectName string, expire time.Duration) string { +func (s *Minio) Url(objectName string, expire time.Duration, https ...bool) string { if err := s.Init(); err != nil { return err.Error() } @@ -122,11 +122,19 @@ func (s *Minio) Url(objectName string, expire time.Duration) string { if expire > time.Hour*24*7 || expire == -1 { expire = time.Hour * 24 * 7 } + + baseUrl := s.config.BaseUrl + if len(https) > 1 && https[0] { + if strings.HasPrefix(baseUrl, "http://") { + baseUrl = "https://" + strings.TrimPrefix(baseUrl, "http://") + } + } + var params url.Values u, err := s.client.PresignedGetObject(s.config.Bucket, objectName, expire, params) if err != nil { log.Errorf("error:%s", err.Error()) - return fmt.Sprintf("%s/%s/%s", s.config.BaseUrl, s.config.Bucket, objectName) + return fmt.Sprintf("%s/%s/%s", baseUrl, s.config.Bucket, objectName) } return u.String() diff --git a/storage/qiniu.go b/storage/qiniu.go index 97ab69c..2791b36 100644 --- a/storage/qiniu.go +++ b/storage/qiniu.go @@ -155,7 +155,7 @@ func (s *Qiniu) Get(objectName, fileName string) error { return Download(url, fileName) } -func (s *Qiniu) Url(objectName string, expire time.Duration) string { +func (s *Qiniu) Url(objectName string, expire time.Duration, https ...bool) string { mac := qbox.NewMac(s.config.AK, s.config.SK) cfg := storage.Config{ UseHTTPS: false, @@ -169,8 +169,10 @@ func (s *Qiniu) Url(objectName string, expire time.Duration) string { if len(domains) <= 0 { return "" } - - domain := "https://" + domains[0].Domain + domain := "http://" + domains[0].Domain + if len(https) > 0 && https[0] { + domain = "https://" + domains[0].Domain + } if expire == 0 { return storage.MakePublicURLv2(domain, objectName) diff --git a/storage/storage.go b/storage/storage.go index 41f1483..22436bb 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -13,7 +13,7 @@ type Storage interface { Put(fileName, objectName string, onProcess func(fsize, uploaded int64)) error Get(objectName, fileName string) error Del(objectName string) error - Url(objectName string, expire time.Duration) string + Url(objectName string, expire time.Duration, https ...bool) string //https参数是否生成https参数 Stat(objectName string) (*ObjectInfo, error) List(objectPrefix string) ([]string, error) Fetch(url, objectName string, local ...bool) error //local参数决定是否先下载到本地在上传,七牛云下载企业微信的文件需要不能直接下载