mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 15:06:37 +08:00
refactor(storage): drop per-upload storage_driver, use storage_config as single source
Remove w_uploads.storage_driver and route all read/write/delete paths through storage.Active() backed by storage_config.driver. Block direct driver switches when uploads exist; require migration task instead. Simplify migration to cursor-based file_path iteration without per-row driver updates.
This commit is contained in:
@@ -5,7 +5,6 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Rain-kl/Wavelet/internal/model"
|
||||
"github.com/Rain-kl/Wavelet/internal/storage"
|
||||
@@ -22,46 +21,11 @@ func ReadOnly(ctx context.Context) bool {
|
||||
return state.ReadOnly
|
||||
}
|
||||
|
||||
// OpenStoredObject opens a stored upload object from its configured backend.
|
||||
// OpenStoredObject opens a stored upload object from the active storage backend.
|
||||
func OpenStoredObject(ctx context.Context, upload *model.Upload) (*storage.Object, error) {
|
||||
driver := storage.Driver(upload.StorageDriver)
|
||||
if driver == "" {
|
||||
driver = storage.DriverLocal
|
||||
}
|
||||
backend, err := backendForStoredDriver(ctx, driver)
|
||||
_, backend, err := storage.Active(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return backend.Get(ctx, upload.FilePath)
|
||||
}
|
||||
|
||||
func backendForStoredDriver(ctx context.Context, driver storage.Driver) (storage.Backend, error) {
|
||||
backend, err := storage.ForDriver(ctx, driver)
|
||||
if err == nil {
|
||||
return backend, nil
|
||||
}
|
||||
|
||||
target, ok, targetErr := CurrentMigrationTargetConfig(ctx)
|
||||
if targetErr != nil {
|
||||
return nil, targetErr
|
||||
}
|
||||
if ok && target.Driver == driver {
|
||||
return storage.NewBackend(ctx, target, driver)
|
||||
}
|
||||
return nil, fmt.Errorf("storage configuration for driver %q is unavailable", driver)
|
||||
}
|
||||
|
||||
// CurrentMigrationTargetConfig returns the pending migration target config when available.
|
||||
func CurrentMigrationTargetConfig(ctx context.Context) (storage.Config, bool, error) {
|
||||
state := LoadMigrationAccessState(ctx)
|
||||
if state.LoadErr != nil {
|
||||
return storage.Config{}, false, state.LoadErr
|
||||
}
|
||||
if state.TargetErr != nil {
|
||||
return storage.Config{}, false, state.TargetErr
|
||||
}
|
||||
if !state.HasTarget {
|
||||
return storage.Config{}, false, nil
|
||||
}
|
||||
return state.Target, true, nil
|
||||
}
|
||||
Reference in New Issue
Block a user