This commit is contained in:
parent
0348dda5cd
commit
bb305eab9e
7 changed files with 29 additions and 8 deletions
|
|
@ -2,20 +2,25 @@ package mediaStorage
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/minio/minio-go/v7"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
client *minio.Client
|
||||
client *minio.Client
|
||||
domain string
|
||||
endpoint string
|
||||
}
|
||||
|
||||
func newService(client *minio.Client) *Service {
|
||||
func newService(client *minio.Client, domain, endpoint string) *Service {
|
||||
return &Service{
|
||||
client: client,
|
||||
domain: domain,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,8 +40,18 @@ func (s *Service) Upload(ctx context.Context, bucket, object string, reader io.R
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *Service) Get(ctx context.Context, bucket, object string, expires time.Duration, params url.Values) (*url.URL, error) {
|
||||
return s.client.PresignedGetObject(ctx, bucket, object, expires, params)
|
||||
func (s *Service) Get(ctx context.Context, bucket, object string, expires time.Duration, params url.Values) (string, error) {
|
||||
presigned, err := s.client.PresignedGetObject(ctx, bucket, object, expires, params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
link := presigned.String()
|
||||
if s.domain != "" {
|
||||
link = strings.Replace(link, fmt.Sprintf("http://%s", s.endpoint), s.domain, 1)
|
||||
}
|
||||
|
||||
return link, nil
|
||||
}
|
||||
|
||||
func (s *Service) Delete(ctx context.Context, bucket, object string) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue