This commit is contained in:
parent
f3d123ee3b
commit
947220b65c
5 changed files with 11 additions and 38 deletions
4
api.env
4
api.env
|
|
@ -8,11 +8,9 @@ APP_ALLOWED_ORIGINS=http://localhost:5173,
|
|||
GRPC_SERVER_PORT=9050
|
||||
GRPC_CLIENT_PORT=9060
|
||||
|
||||
MEDIA_STORAGE_ENDPOINT=
|
||||
MEDIA_STORAGE_USER=
|
||||
MEDIA_STORAGE_PASSWORD=
|
||||
MEDIA_STORAGE_HOST=
|
||||
MEDIA_STORAGE_PORT=
|
||||
MEDIA_STORAGE_DOMAIN=
|
||||
MEDIA_STORAGE_SECURE=false
|
||||
|
||||
DB_HOST=
|
||||
|
|
|
|||
|
|
@ -52,15 +52,13 @@ func main() {
|
|||
log.Debug("Utils provider initialized")
|
||||
|
||||
mediaProvider := mediaStorage.NewHandler(mediaStorage.Deps{
|
||||
Host: c.MediaConf.Host,
|
||||
Port: c.MediaConf.Port,
|
||||
Endpoint: c.MediaConf.Endpoint,
|
||||
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,
|
||||
"endpoint": c.MediaConf.Endpoint,
|
||||
"provider": mediaProvider,
|
||||
}).Debug("Media storage | Minio client created")
|
||||
|
||||
|
|
|
|||
|
|
@ -42,11 +42,9 @@ type GrpcConfig struct {
|
|||
}
|
||||
|
||||
type MediaConfig struct {
|
||||
Host string
|
||||
Port string
|
||||
Endpoint string
|
||||
User string
|
||||
Password string
|
||||
Domain string
|
||||
Secure string
|
||||
}
|
||||
|
||||
|
|
@ -84,11 +82,9 @@ func NewConfig() *Config {
|
|||
},
|
||||
|
||||
MediaConf: MediaConfig{
|
||||
Host: getEnv("MEDIA_STORAGE_HOST", ""),
|
||||
Port: getEnv("MEDIA_STORAGE_PORT", ""),
|
||||
Endpoint: getEnv("MEDIA_STORAGE_ENDPOINT", ""),
|
||||
User: getEnv("MEDIA_STORAGE_USER", ""),
|
||||
Password: getEnv("MEDIA_STORAGE_PASSWORD", ""),
|
||||
Domain: getEnv("MEDIA_STORAGE_DOMAIN", ""),
|
||||
Secure: getEnv("MEDIA_STORAGE_SECURE", ""),
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package mediaStorage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
@ -12,8 +11,7 @@ type Handler struct {
|
|||
}
|
||||
|
||||
type Deps struct {
|
||||
Host string
|
||||
Port string
|
||||
Endpoint string
|
||||
User string
|
||||
Password string
|
||||
Domain string
|
||||
|
|
@ -26,8 +24,7 @@ func NewHandler(deps Deps) *Handler {
|
|||
secureMode = true
|
||||
}
|
||||
|
||||
endpoint := fmt.Sprintf("%s:%s", deps.Host, deps.Port)
|
||||
minioClient, err := minio.New(endpoint, &minio.Options{
|
||||
minioClient, err := minio.New(deps.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(deps.User, deps.Password, ""),
|
||||
Secure: secureMode,
|
||||
})
|
||||
|
|
@ -36,11 +33,11 @@ func NewHandler(deps Deps) *Handler {
|
|||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"endpoint": endpoint,
|
||||
"endpoint": deps.Endpoint,
|
||||
"secure": secureMode,
|
||||
}).Debug("Media storage | Created minio client")
|
||||
|
||||
return &Handler{
|
||||
newService(minioClient, deps.Domain, endpoint),
|
||||
newService(minioClient),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package mediaStorage
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/minio/minio-go/v7"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
|
|
@ -16,10 +15,9 @@ type Service struct {
|
|||
endpoint string
|
||||
}
|
||||
|
||||
func newService(client *minio.Client, domain, endpoint string) *Service {
|
||||
func newService(client *minio.Client) *Service {
|
||||
return &Service{
|
||||
client: client,
|
||||
domain: domain,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,21 +43,7 @@ func (s *Service) Get(ctx context.Context, bucket, object string, expires time.D
|
|||
return "", err
|
||||
}
|
||||
|
||||
u, err := url.Parse(presigned.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if s.domain != "" {
|
||||
domainURL, err := url.Parse(s.domain)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("invalid domain URL: %w", err)
|
||||
}
|
||||
u.Scheme = domainURL.Scheme
|
||||
u.Host = domainURL.Host
|
||||
}
|
||||
|
||||
return u.String(), nil
|
||||
return presigned.String(), nil
|
||||
}
|
||||
|
||||
func (s *Service) Delete(ctx context.Context, bucket, object string) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue