switch from pre-signed to public images
All checks were successful
/ Make image (push) Successful in 1m31s

This commit is contained in:
nquidox 2025-10-19 19:43:33 +03:00
parent 947220b65c
commit 3298602a23
6 changed files with 71 additions and 20 deletions

View file

@ -14,7 +14,6 @@ type Deps struct {
Endpoint string
User string
Password string
Domain string
Secure string
}
@ -38,6 +37,6 @@ func NewHandler(deps Deps) *Handler {
}).Debug("Media storage | Created minio client")
return &Handler{
newService(minioClient),
newService(minioClient, deps.Endpoint, secureMode),
}
}

View file

@ -2,22 +2,26 @@ 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
client *minio.Client
endpoint string
secureMode bool
}
func newService(client *minio.Client) *Service {
func newService(client *minio.Client, endpoint string, secureMode bool) *Service {
return &Service{
client: client,
client: client,
endpoint: endpoint,
secureMode: secureMode,
}
}
@ -37,7 +41,30 @@ 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) (string, error) {
func (s *Service) GetPublicLink(ctx context.Context, bucket, object string) (string, string, error) {
stat, err := s.client.StatObject(ctx, bucket, object, minio.StatObjectOptions{})
if err != nil {
log.WithFields(log.Fields{
"error": err,
"key": bucket + "/" + object,
}).Error("Media storage | Failed to get public link")
return "", "", err
}
var scheme string
if s.secureMode {
scheme = "https"
} else {
scheme = "http"
}
link := fmt.Sprintf("%s://%s/%s/%s", scheme, strings.TrimRight(s.endpoint, "/"), bucket, object)
log.WithFields(log.Fields{"link": link}).Debug("Media storage | Get public link")
return link, stat.ETag, nil
}
func (s *Service) GetPresignedLink(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