refactor: update storage interface to use io.Reader for Save method and remove stream implementations

This commit is contained in:
krau
2025-03-21 23:05:09 +08:00
parent ed0837a89b
commit 2d2becccf6
9 changed files with 77 additions and 338 deletions
+4 -3
View File
@@ -3,6 +3,7 @@ package minio
import (
"context"
"fmt"
"io"
"path"
"github.com/krau/SaveAny-Bot/common"
@@ -59,10 +60,10 @@ func (m *Minio) JoinStoragePath(task types.Task) string {
return path.Join(m.config.BasePath, task.StoragePath)
}
func (m *Minio) Save(ctx context.Context, localFilePath, storagePath string) error {
common.Log.Infof("Saving file %s to %s", localFilePath, storagePath)
func (m *Minio) Save(ctx context.Context, r io.Reader, storagePath string) error {
common.Log.Infof("Saving file from reader to %s", storagePath)
_, err := m.client.FPutObject(ctx, m.config.BucketName, storagePath, localFilePath, minio.PutObjectOptions{})
_, err := m.client.PutObject(ctx, m.config.BucketName, storagePath, r, -1, minio.PutObjectOptions{})
if err != nil {
return fmt.Errorf("failed to upload file to minio: %w", err)
}