import type { StorageProviderKind, StorageInput, StorageResult, } from '../types'; import {uploadLocal, getLocal, deleteLocal, pingLocal} from './local'; import {deleteS3, getS3, pingS3, uploadS3} from "@/features/storages/providers/s3"; type ProviderHandler = { upload: (config: any, input: StorageInput & { action: 'upload' }) => Promise; get: (config: any, input: StorageInput & { action: 'get' }) => Promise; delete: (config: any, input: StorageInput & { action: 'delete' }) => Promise; ping: (config: any, input: { action: 'ping' }) => Promise; }; const handlers: Record = { local: { upload: uploadLocal, get: getLocal, delete: deleteLocal, ping: pingLocal, }, s3: { upload: uploadS3, get: getS3, delete: deleteS3, ping: pingS3, }, // gcs: null as any, // azure: null as any, }; export async function dispatchViaProvider( kind: StorageProviderKind, config: any, input: StorageInput ): Promise { const provider = handlers[kind]; if (!provider) { return { success: false, provider: kind, error: `Unsupported storage provider: ${kind}`, }; } try { return await provider[input.action](config, input as any); } catch (err: any) { return { success: false, provider: kind, error: err.message || 'Storage provider error', }; } }