feat: support S3 media processing pipeline

This commit is contained in:
2026-02-04 19:15:44 +08:00
parent 8f7000dc8d
commit 57b7269215
4 changed files with 366 additions and 17 deletions

View File

@@ -6,6 +6,7 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/url"
"os"
"path/filepath"
@@ -63,6 +64,44 @@ type Storage struct {
s3Client *minio.Client
}
func (s *Storage) Download(ctx context.Context, key, filePath string) error {
if s.storageType() == "local" {
localPath := s.Config.LocalPath
if localPath == "" {
localPath = "./storage"
}
srcPath := filepath.Join(localPath, key)
if err := os.MkdirAll(filepath.Dir(filePath), 0o755); err != nil {
return err
}
src, err := os.Open(srcPath)
if err != nil {
return err
}
defer src.Close()
dst, err := os.Create(filePath)
if err != nil {
return err
}
defer dst.Close()
if _, err := io.Copy(dst, src); err != nil {
return err
}
return nil
}
client, err := s.s3ClientForUse()
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(filePath), 0o755); err != nil {
return err
}
return client.FGetObject(ctx, s.Config.Bucket, key, filePath, minio.GetObjectOptions{})
}
func (s *Storage) Delete(key string) error {
if s.storageType() == "local" {
localPath := s.Config.LocalPath