@@ -15,7 +15,6 @@ export class StorageManager {
1515 this . isS3 = false
1616 this . storageData = { }
1717 this . storageLoaded = false
18-
1918 // Throttle saves to avoid too many writes
2019 this . saveStorageData = throttle ( ( ) => this . persistStorageData ( ) , 1000 , { leading : true , trailing : true } )
2120 }
@@ -24,7 +23,14 @@ export class StorageManager {
2423 * Initialize storage based on environment configuration
2524 */
2625 async initialize ( ) {
27- if ( process . env . S3_BUCKET_NAME ) {
26+ const storageType = process . env . STORAGE_TYPE || StorageManager . STORAGE_TYPE . LOCAL ;
27+
28+ if ( storageType === StorageManager . STORAGE_TYPE . S3 ) {
29+ // Validate required S3 configuration
30+ if ( ! process . env . S3_BUCKET_NAME ) {
31+ throw new Error ( 'S3_BUCKET_NAME is required when STORAGE_TYPE=s3' )
32+ }
33+
2834 // Initialize S3 storage
2935 this . isS3 = true
3036 const s3Config = {
@@ -35,7 +41,6 @@ export class StorageManager {
3541 storagePrefix : process . env . S3_STORAGE_PREFIX || 'storage/' ,
3642 cloudfrontUrl : process . env . CLOUDFRONT_URL ,
3743 }
38-
3944 if ( process . env . S3_ACCESS_KEY_ID && process . env . S3_SECRET_ACCESS_KEY ) {
4045 s3Config . credentials = {
4146 accessKeyId : process . env . S3_ACCESS_KEY_ID ,
@@ -57,6 +62,8 @@ export class StorageManager {
5762
5863 console . log ( 'Initializing local file storage...' )
5964 await this . storage . initialize ( )
65+ } else {
66+ throw new Error ( `Unsupported storage type: ${ storageType } . Supported types: 'local', 's3'` )
6067 }
6168
6269 // Initialize storage data
@@ -101,7 +108,6 @@ export class StorageManager {
101108 console . warn ( 'Storage not yet loaded, cannot set value' )
102109 return
103110 }
104-
105111 try {
106112 // Ensure value is serializable
107113 value = JSON . parse ( JSON . stringify ( value ) )
@@ -120,7 +126,6 @@ export class StorageManager {
120126 console . warn ( 'Storage not yet loaded, cannot persist' )
121127 return
122128 }
123-
124129 try {
125130 await this . storage . saveStorageData ( this . storageData )
126131 // console.log('Storage data persisted successfully')
0 commit comments