This commit is contained in:
parent
0348dda5cd
commit
bb305eab9e
7 changed files with 29 additions and 8 deletions
|
|
@ -334,7 +334,7 @@ func (s *service) getMerchImage(ctx context.Context, userUuid, merchUuid, imageT
|
|||
}
|
||||
|
||||
return ImageLink{
|
||||
Link: link.String(),
|
||||
Link: link,
|
||||
ETag: etag,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
type MediaStorage interface {
|
||||
CheckBucketExists(bucketName string) (bool, error)
|
||||
Upload(ctx context.Context, bucket, object string, reader io.Reader, size int64) error
|
||||
Get(ctx context.Context, bucket, object string, expires time.Duration, params url.Values) (*url.URL, error)
|
||||
Get(ctx context.Context, bucket, object string, expires time.Duration, params url.Values) (string, error)
|
||||
Delete(ctx context.Context, bucket, object string) error
|
||||
GetObjectEtag(ctx context.Context, bucketName, object string) (string, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ type Deps struct {
|
|||
Port string
|
||||
User string
|
||||
Password string
|
||||
Domain string
|
||||
Secure string
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +41,6 @@ func NewHandler(deps Deps) *Handler {
|
|||
}).Debug("Media storage | Created minio client")
|
||||
|
||||
return &Handler{
|
||||
newService(minioClient),
|
||||
newService(minioClient, deps.Domain, endpoint),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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