diff --git a/api.env b/api.env index 563fd50..8bb1d03 100644 --- a/api.env +++ b/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= diff --git a/cmd/main.go b/cmd/main.go index d5e74cc..3fb0010 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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") diff --git a/config/config.go b/config/config.go index 0e71b33..5f2d4d5 100644 --- a/config/config.go +++ b/config/config.go @@ -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", ""), }, } diff --git a/internal/mediaStorage/handler.go b/internal/mediaStorage/handler.go index e6293ba..c1586eb 100644 --- a/internal/mediaStorage/handler.go +++ b/internal/mediaStorage/handler.go @@ -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), } } diff --git a/internal/mediaStorage/service.go b/internal/mediaStorage/service.go index 3a3d7c5..6c4b03a 100644 --- a/internal/mediaStorage/service.go +++ b/internal/mediaStorage/service.go @@ -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 {