feat: implement storage provider with local and S3 adapters
This commit is contained in:
28
src/lib/storage/storage.factory.ts
Normal file
28
src/lib/storage/storage.factory.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
LocalStorageAdapter,
|
||||
S3StorageAdapter,
|
||||
} from '@/lib/storage/storage.adapter';
|
||||
import { StorageProvider } from '@/lib/storage/storage.interface';
|
||||
|
||||
/**
|
||||
* Factory function to create the appropriate storage provider based on environment
|
||||
*/
|
||||
export function createStorageProvider(): StorageProvider {
|
||||
const storageType = process.env.STORAGE_TYPE || 'local';
|
||||
|
||||
if (storageType === 's3') {
|
||||
const bucketName = process.env.S3_BUCKET_NAME;
|
||||
const region = process.env.S3_REGION || 'us-east-1';
|
||||
|
||||
if (!bucketName) {
|
||||
throw new Error(
|
||||
'S3_BUCKET_NAME environment variable is required when STORAGE_TYPE=s3'
|
||||
);
|
||||
}
|
||||
|
||||
return new S3StorageAdapter(bucketName, region);
|
||||
}
|
||||
|
||||
// Default to local storage
|
||||
return new LocalStorageAdapter();
|
||||
}
|
||||
Reference in New Issue
Block a user