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
+4 -4
View File
@@ -28,17 +28,17 @@ func newWebDAVBackend(cfg WebDAVConfig) (*webDAVBackend, error) {
}, nil
}
func (b *webDAVBackend) Put(_ context.Context, key string, body io.Reader, size int64, _ string) (string, error) {
func (b *webDAVBackend) Put(_ context.Context, key string, body io.Reader, size int64, _ string) (PutResult, error) {
key = b.key(key)
if dir := path.Dir(key); dir != "." && dir != "/" {
if err := b.client.MkdirAll(dir, storageDirPerm); err != nil {
return "", fmt.Errorf("create WebDAV directory: %w", err)
return PutResult{}, fmt.Errorf("create WebDAV directory: %w", err)
}
}
if err := b.client.WriteStreamWithLength(key, body, size, storageFilePerm); err != nil {
return "", fmt.Errorf("put WebDAV object: %w", err)
return PutResult{}, fmt.Errorf("put WebDAV object: %w", err)
}
return key, nil
return PutResult{Key: key}, nil
}
func (b *webDAVBackend) Get(_ context.Context, key string) (*Object, error) {