| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package minio
- import (
- "bytes"
- "context"
- "fmt"
- "io"
- "path"
- "strings"
- "time"
- minioUtil "fwh-toolbox-server/utils/minio"
- )
- const (
- renderPrefix = "DataDownloadRenderCache/"
- packagePrefix = "DataDownloadPackage/"
- binaryPrefix = "DataDownloadDocument/"
- )
- func PutRenderArtifact(ctx context.Context, documentID string, generation int64, format string, data []byte, contentType string) (string, error) {
- if strings.Contains(format, "/") || strings.Contains(format, "\\") {
- return "", fmt.Errorf("invalid format")
- }
- key := fmt.Sprintf("%s%s/%d/%d.%s", renderPrefix, documentID, generation, time.Now().UnixNano(), format)
- if err := minioUtil.UploadFromReader(bytes.NewReader(data), int64(len(data)), key, contentType); err != nil {
- return "", err
- }
- return key, nil
- }
- func PutPackage(ctx context.Context, name string, data []byte) (string, error) {
- key := fmt.Sprintf("%s%d-%s", packagePrefix, time.Now().UnixNano(), path.Base(name))
- if err := minioUtil.UploadFromReader(bytes.NewReader(data), int64(len(data)), key, "application/zip"); err != nil {
- return "", err
- }
- return key, nil
- }
- func PutBinaryDocument(ctx context.Context, documentID, filename string, reader io.Reader, size int64, contentType string) (string, error) {
- key := fmt.Sprintf("%s%s/%d-%s", binaryPrefix, documentID, time.Now().UnixNano(), path.Base(filename))
- if err := minioUtil.UploadFromReader(reader, size, key, contentType); err != nil {
- return "", err
- }
- return key, nil
- }
- func Open(ctx context.Context, objectKey string) (io.ReadCloser, error) {
- return minioUtil.GetObject(objectKey)
- }
- func Delete(ctx context.Context, objectKey string) error { return minioUtil.DeleteFile(objectKey) }
|