38 lines
864 B
Go
38 lines
864 B
Go
package answer
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/minio/minio-go/v7"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
bucket = "3c580be9-cf31f296-d055-49cf-b39e-30c7959dc17b"
|
|
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")
|
|
url, err := s.client.PresignedGetObject(ctx, bucket, bucketAnswers + "/" + objectName, time.Hour*1, reqParams)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return url.String(), nil
|
|
}
|