This commit is contained in:
parent
0348dda5cd
commit
bb305eab9e
7 changed files with 29 additions and 8 deletions
3
api.env
3
api.env
|
|
@ -9,9 +9,10 @@ GRPC_SERVER_PORT=9050
|
|||
GRPC_CLIENT_PORT=9060
|
||||
|
||||
MEDIA_STORAGE_USER=
|
||||
MEDIA_STORAGE_PASS=
|
||||
MEDIA_STORAGE_PASSWORD=
|
||||
MEDIA_STORAGE_HOST=
|
||||
MEDIA_STORAGE_PORT=
|
||||
MEDIA_STORAGE_DOMAIN=
|
||||
MEDIA_STORAGE_SECURE=false
|
||||
|
||||
DB_HOST=
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ func main() {
|
|||
Port: c.MediaConf.Port,
|
||||
User: c.MediaConf.User,
|
||||
Password: c.MediaConf.Password,
|
||||
Domain: c.MediaConf.Domain,
|
||||
Secure: c.MediaConf.Secure,
|
||||
})
|
||||
log.WithFields(log.Fields{
|
||||
"address": c.MediaConf.Host + ":" + c.MediaConf.Port,
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ type MediaConfig struct {
|
|||
Port string
|
||||
User string
|
||||
Password string
|
||||
Domain string
|
||||
Secure string
|
||||
}
|
||||
|
||||
|
|
@ -87,6 +88,7 @@ func NewConfig() *Config {
|
|||
Port: getEnv("MEDIA_STORAGE_PORT", ""),
|
||||
User: getEnv("MEDIA_STORAGE_USER", ""),
|
||||
Password: getEnv("MEDIA_STORAGE_PASSWORD", ""),
|
||||
Domain: getEnv("MEDIA_STORAGE_DOMAIN", ""),
|
||||
Secure: getEnv("MEDIA_STORAGE_SECURE", ""),
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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