add media service
This commit is contained in:
32
internal/application/usecases/presign.go
Normal file
32
internal/application/usecases/presign.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package usecases
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"lendry-erp/media/internal/application/dto"
|
||||
"lendry-erp/media/internal/infrastructure/storage"
|
||||
)
|
||||
|
||||
type PresignUseCase struct {
|
||||
storage storage.Storage
|
||||
}
|
||||
|
||||
func NewPresignUseCase(s storage.Storage) *PresignUseCase {
|
||||
return &PresignUseCase{storage: s}
|
||||
}
|
||||
|
||||
func (u *PresignUseCase) Execute(ctx context.Context, input dto.GetUrlRequest) (*dto.GetUrlResponse, error) {
|
||||
// Приватные файлы (из чатов) сгорают быстро, публичные (аватарки) живут 24 часа
|
||||
expiry := time.Minute * 2
|
||||
if input.IsPublic {
|
||||
expiry = time.Hour * 24
|
||||
}
|
||||
|
||||
url, err := u.storage.GetPresignedURL(ctx, input.FileName, expiry, "GET")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.GetUrlResponse{URL: url}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user