refactor(storage): update Backend.Put to return PutResult and encapsulate bucket mapping

- Update Backend.Put method signature in storage.go to return (PutResult, error).
- Adjust all backend implementations (local, oss, s3, webdav) to return a PutResult enclosing Key and Bucket.
- Refactor storeUploadFile in upload routers.go to extract key/bucket from PutResult, eliminating manual config bucket lookups.
- Remove the unused cfgBucket helper from storage_ops.go.
- Adjust storage_migration_task.go and tests to accommodate the updated method signature.
This commit is contained in:
ryan
2026-06-13 15:48:41 +08:00
parent ce9423f877
commit 1d37242a8b
9 changed files with 37 additions and 57 deletions
+3 -3
View File
@@ -35,7 +35,7 @@ func newOSSBackend(cfg ObjectConfig) (*ossBackend, error) {
}, nil
}
func (b *ossBackend) Put(ctx context.Context, key string, body io.Reader, _ int64, _ string) (string, error) {
func (b *ossBackend) Put(ctx context.Context, key string, body io.Reader, _ int64, _ string) (PutResult, error) {
key = b.key(key)
_, err := b.client.PutObject(ctx, &oss.PutObjectRequest{
Bucket: oss.Ptr(b.bucket),
@@ -43,9 +43,9 @@ func (b *ossBackend) Put(ctx context.Context, key string, body io.Reader, _ int6
Body: body,
})
if err != nil {
return "", fmt.Errorf("put OSS object: %w", err)
return PutResult{}, fmt.Errorf("put OSS object: %w", err)
}
return key, nil
return PutResult{Key: key, Bucket: b.bucket}, nil
}
func (b *ossBackend) Get(ctx context.Context, key string) (*Object, error) {