NewLocalBackend creates a new local file storage backend
(config *StorageConfig)
| 34 | |
| 35 | // NewLocalBackend creates a new local file storage backend |
| 36 | func NewLocalBackend(config *StorageConfig) (StorageBackend, error) { |
| 37 | basePath := "./vsa-upload" // Default |
| 38 | |
| 39 | // Use base URL as path if provided |
| 40 | if config.BaseURL != "" { |
| 41 | basePath = config.BaseURL |
| 42 | } |
| 43 | |
| 44 | // Check parameters |
| 45 | for key, value := range config.Parameters { |
| 46 | switch key { |
| 47 | case "path", "dir", "directory": |
| 48 | basePath = value |
| 49 | default: |
| 50 | log.Warnf("[VSA] Local backend: ignoring unknown parameter '%s'", key) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // Ensure directory exists |
| 55 | if err := os.MkdirAll(basePath, 0o755); err != nil { |
| 56 | return nil, fmt.Errorf("failed to create storage directory %s: %w", basePath, err) |
| 57 | } |
| 58 | |
| 59 | return &LocalBackend{basePath: basePath}, nil |
| 60 | } |
| 61 | |
| 62 | // Name returns the backend name |
| 63 | func (l *LocalBackend) Name() string { |