common/repository/answer/dal_minio.go

38 lines
864 B
Go
Raw Normal View History

2024-03-28 12:22:54 +00:00
package answer
2024-03-28 11:53:12 +00:00
import (
"context"
"fmt"
"github.com/minio/minio-go/v7"
"net/url"
"time"
)
const (
2024-05-30 13:39:53 +00:00
bucket = "3c580be9-cf31f296-d055-49cf-b39e-30c7959dc17b"
2024-03-28 11:53:12 +00:00
bucketAnswers = "squizanswer"
)
type StorerAnswer struct {
client *minio.Client
}
func NewAnswerMinio(ctx context.Context, minioClient *minio.Client) (*StorerAnswer, error) {
return &StorerAnswer{
client: minioClient,
}, nil
}
func (s *StorerAnswer) GetAnswerURL(ctx context.Context, quizID string, questionID int64, filename string) (string, error) {
objectName := fmt.Sprintf("%s/%d/%s", quizID, questionID, filename)
reqParams := make(url.Values)
reqParams.Set("response-content-disposition", "attachment")
2024-05-30 13:39:53 +00:00
url, err := s.client.PresignedGetObject(ctx, bucket, bucketAnswers + "/" + objectName, time.Hour*1, reqParams)
2024-03-28 11:53:12 +00:00
if err != nil {
return "", err
}
return url.String(), nil
}