replace domain for links
All checks were successful
/ Make image (push) Successful in 1m21s

This commit is contained in:
nquidox 2025-10-18 15:30:59 +03:00
parent 0348dda5cd
commit bb305eab9e
7 changed files with 29 additions and 8 deletions

View file

@ -16,6 +16,7 @@ type Deps struct {
Port string
User string
Password string
Domain string
Secure string
}
@ -40,6 +41,6 @@ func NewHandler(deps Deps) *Handler {
}).Debug("Media storage | Created minio client")
return &Handler{
newService(minioClient),
newService(minioClient, deps.Domain, endpoint),
}
}

View file

@ -2,20 +2,25 @@ 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
client *minio.Client
domain string
endpoint string
}
func newService(client *minio.Client) *Service {
func newService(client *minio.Client, domain, endpoint string) *Service {
return &Service{
client: client,
domain: domain,
}
}
@ -35,8 +40,18 @@ 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) (*url.URL, error) {
return s.client.PresignedGetObject(ctx, bucket, object, expires, params)
func (s *Service) Get(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
}
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 {