2021-11-19 18:14:43 +00:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"os"
|
2024-01-03 20:25:15 +00:00
|
|
|
"resource-manager/domain/cache"
|
2021-11-19 18:14:43 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UploadRequest struct {
|
|
|
|
Buffer *bytes.Buffer
|
|
|
|
Path string
|
|
|
|
MimeType string
|
|
|
|
Overwrite bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewManager(cacheManager cache.Manager, expiration time.Duration) Manager {
|
|
|
|
if strings.Contains(os.Getenv("PROFILE"), "s3") {
|
|
|
|
log.Println("Manager | using S3 for data storage")
|
|
|
|
return newS3Bucket(cacheManager, expiration)
|
|
|
|
} else {
|
2024-01-06 13:10:24 +00:00
|
|
|
log.Println("Manager | using local file for data storage")
|
2021-11-19 18:14:43 +00:00
|
|
|
return newLocalFolder(cacheManager, expiration)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Manager interface {
|
|
|
|
Upload(request UploadRequest)
|
|
|
|
Download(ctx context.Context, path string) (file []byte, err error)
|
|
|
|
Presign(ctx context.Context, path string) (string, error)
|
|
|
|
Copy(from string, to string, overwrite bool) error
|
|
|
|
Delete(path string) error
|
|
|
|
}
|