mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user