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_SERVER_PORT=9050
|
||||||
GRPC_CLIENT_PORT=9060
|
GRPC_CLIENT_PORT=9060
|
||||||
|
|
||||||
|
MEDIA_STORAGE_ENDPOINT=
|
||||||
MEDIA_STORAGE_USER=
|
MEDIA_STORAGE_USER=
|
||||||
MEDIA_STORAGE_PASSWORD=
|
MEDIA_STORAGE_PASSWORD=
|
||||||
MEDIA_STORAGE_HOST=
|
|
||||||
MEDIA_STORAGE_PORT=
|
|
||||||
MEDIA_STORAGE_DOMAIN=
|
|
||||||
MEDIA_STORAGE_SECURE=false
|
MEDIA_STORAGE_SECURE=false
|
||||||
|
|
||||||
DB_HOST=
|
DB_HOST=
|
||||||
|
|
|
||||||
|
|
@ -52,15 +52,13 @@ func main() {
|
||||||
log.Debug("Utils provider initialized")
|
log.Debug("Utils provider initialized")
|
||||||
|
|
||||||
mediaProvider := mediaStorage.NewHandler(mediaStorage.Deps{
|
mediaProvider := mediaStorage.NewHandler(mediaStorage.Deps{
|
||||||
Host: c.MediaConf.Host,
|
Endpoint: c.MediaConf.Endpoint,
|
||||||
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,
|
Secure: c.MediaConf.Secure,
|
||||||
})
|
})
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"address": c.MediaConf.Host + ":" + c.MediaConf.Port,
|
"endpoint": c.MediaConf.Endpoint,
|
||||||
"provider": mediaProvider,
|
"provider": mediaProvider,
|
||||||
}).Debug("Media storage | Minio client created")
|
}).Debug("Media storage | Minio client created")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,9 @@ type GrpcConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MediaConfig struct {
|
type MediaConfig struct {
|
||||||
Host string
|
Endpoint string
|
||||||
Port string
|
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
Domain string
|
|
||||||
Secure string
|
Secure string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,11 +82,9 @@ func NewConfig() *Config {
|
||||||
},
|
},
|
||||||
|
|
||||||
MediaConf: MediaConfig{
|
MediaConf: MediaConfig{
|
||||||
Host: getEnv("MEDIA_STORAGE_HOST", ""),
|
Endpoint: getEnv("MEDIA_STORAGE_ENDPOINT", ""),
|
||||||
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", ""),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package mediaStorage
|
package mediaStorage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
@ -12,8 +11,7 @@ type Handler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
Host string
|
Endpoint string
|
||||||
Port string
|
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
Domain string
|
Domain string
|
||||||
|
|
@ -26,8 +24,7 @@ func NewHandler(deps Deps) *Handler {
|
||||||
secureMode = true
|
secureMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := fmt.Sprintf("%s:%s", deps.Host, deps.Port)
|
minioClient, err := minio.New(deps.Endpoint, &minio.Options{
|
||||||
minioClient, err := minio.New(endpoint, &minio.Options{
|
|
||||||
Creds: credentials.NewStaticV4(deps.User, deps.Password, ""),
|
Creds: credentials.NewStaticV4(deps.User, deps.Password, ""),
|
||||||
Secure: secureMode,
|
Secure: secureMode,
|
||||||
})
|
})
|
||||||
|
|
@ -36,11 +33,11 @@ func NewHandler(deps Deps) *Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"endpoint": endpoint,
|
"endpoint": deps.Endpoint,
|
||||||
"secure": secureMode,
|
"secure": secureMode,
|
||||||
}).Debug("Media storage | Created minio client")
|
}).Debug("Media storage | Created minio client")
|
||||||
|
|
||||||
return &Handler{
|
return &Handler{
|
||||||
newService(minioClient, deps.Domain, endpoint),
|
newService(minioClient),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ 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"
|
||||||
|
|
@ -16,10 +15,9 @@ type Service struct {
|
||||||
endpoint string
|
endpoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newService(client *minio.Client, domain, endpoint string) *Service {
|
func newService(client *minio.Client) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
client: client,
|
client: client,
|
||||||
domain: domain,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,21 +43,7 @@ func (s *Service) Get(ctx context.Context, bucket, object string, expires time.D
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.Parse(presigned.String())
|
return presigned.String(), nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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