feat: integrate S3 storage adapter and update file upload functionality
This commit is contained in:
@@ -1,28 +1,13 @@
|
||||
import {
|
||||
LocalStorageAdapter,
|
||||
S3StorageAdapter,
|
||||
} from '@/lib/storage/storage.adapter';
|
||||
import { new_s3_storage_adapter } 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);
|
||||
const storage_provider = new_s3_storage_adapter();
|
||||
if (!storage_provider) {
|
||||
throw new Error('Failed to create storage provider');
|
||||
}
|
||||
|
||||
// Default to local storage
|
||||
return new LocalStorageAdapter();
|
||||
return storage_provider;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user