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
|
GRPC_CLIENT_PORT=9060
|
||||||
|
|
||||||
MEDIA_STORAGE_USER=
|
MEDIA_STORAGE_USER=
|
||||||
MEDIA_STORAGE_PASS=
|
MEDIA_STORAGE_PASSWORD=
|
||||||
MEDIA_STORAGE_HOST=
|
MEDIA_STORAGE_HOST=
|
||||||
MEDIA_STORAGE_PORT=
|
MEDIA_STORAGE_PORT=
|
||||||
|
MEDIA_STORAGE_DOMAIN=
|
||||||
MEDIA_STORAGE_SECURE=false
|
MEDIA_STORAGE_SECURE=false
|
||||||
|
|
||||||
DB_HOST=
|
DB_HOST=
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ func main() {
|
||||||
Port: c.MediaConf.Port,
|
Port: c.MediaConf.Port,
|
||||||
User: c.MediaConf.User,
|
User: c.MediaConf.User,
|
||||||
Password: c.MediaConf.Password,
|
Password: c.MediaConf.Password,
|
||||||
|
Domain: c.MediaConf.Domain,
|
||||||
|
Secure: c.MediaConf.Secure,
|
||||||
})
|
})
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"address": c.MediaConf.Host + ":" + c.MediaConf.Port,
|
"address": c.MediaConf.Host + ":" + c.MediaConf.Port,
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ type MediaConfig struct {
|
||||||
Port string
|
Port string
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
|
Domain string
|
||||||
Secure string
|
Secure string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +88,7 @@ func NewConfig() *Config {
|
||||||
Port: getEnv("MEDIA_STORAGE_PORT", ""),
|
Port: getEnv("MEDIA_STORAGE_PORT", ""),
|
||||||
User: getEnv("MEDIA_STORAGE_USER", ""),
|
User: getEnv("MEDIA_STORAGE_USER", ""),
|
||||||
Password: getEnv("MEDIA_STORAGE_PASSWORD", ""),
|
Password: getEnv("MEDIA_STORAGE_PASSWORD", ""),
|
||||||
|
Domain: getEnv("MEDIA_STORAGE_DOMAIN", ""),
|
||||||
Secure: getEnv("MEDIA_STORAGE_SECURE", ""),
|
Secure: getEnv("MEDIA_STORAGE_SECURE", ""),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ func (s *service) getMerchImage(ctx context.Context, userUuid, merchUuid, imageT
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImageLink{
|
return ImageLink{
|
||||||
Link: link.String(),
|
Link: link,
|
||||||
ETag: etag,
|
ETag: etag,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type MediaStorage interface {
|
type MediaStorage interface {
|
||||||
CheckBucketExists(bucketName string) (bool, error)
|
CheckBucketExists(bucketName string) (bool, error)
|
||||||
Upload(ctx context.Context, bucket, object string, reader io.Reader, size int64) 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
|
Delete(ctx context.Context, bucket, object string) error
|
||||||
GetObjectEtag(ctx context.Context, bucketName, object string) (string, error)
|
GetObjectEtag(ctx context.Context, bucketName, object string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ type Deps struct {
|
||||||
Port string
|
Port string
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
|
Domain string
|
||||||
Secure string
|
Secure string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,6 +41,6 @@ func NewHandler(deps Deps) *Handler {
|
||||||
}).Debug("Media storage | Created minio client")
|
}).Debug("Media storage | Created minio client")
|
||||||
|
|
||||||
return &Handler{
|
return &Handler{
|
||||||
newService(minioClient),
|
newService(minioClient, deps.Domain, endpoint),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,25 @@ package mediaStorage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
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{
|
return &Service{
|
||||||
client: client,
|
client: client,
|
||||||
|
domain: domain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,8 +40,18 @@ func (s *Service) Upload(ctx context.Context, bucket, object string, reader io.R
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Get(ctx context.Context, bucket, object string, expires time.Duration, params url.Values) (*url.URL, error) {
|
func (s *Service) Get(ctx context.Context, bucket, object string, expires time.Duration, params url.Values) (string, error) {
|
||||||
return s.client.PresignedGetObject(ctx, bucket, object, expires, params)
|
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 {
|
func (s *Service) Delete(ctx context.Context, bucket, object string) error {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue