@@ -17,24 +17,36 @@ import { streamToBuffer } from '~/lib/utils'
1717export const s3Driver = defineStorageDriver ( {
1818 envSchema : z . object ( {
1919 STORAGE_S3_BUCKET : z . string ( ) . min ( 1 ) ,
20- STORAGE_S3_ENDPOINT : z . string ( ) . min ( 1 ) ,
21- STORAGE_S3_REGION : z . string ( ) . min ( 1 ) . default ( 'us-east-1' ) ,
22- STORAGE_S3_PORT : z . coerce . number ( ) . positive ( ) ,
23- STORAGE_S3_USE_SSL : z . string ( ) . transform ( ( v ) => v === 'true' ) ,
24- STORAGE_S3_ACCESS_KEY : z . string ( ) . min ( 1 ) ,
25- STORAGE_S3_SECRET_KEY : z . string ( ) . min ( 1 ) ,
20+ STORAGE_S3_ENDPOINT : z . string ( ) . optional ( ) ,
21+ STORAGE_S3_REGION : z . string ( ) . min ( 1 ) . default ( 'us-east-1' ) . optional ( ) ,
22+ STORAGE_S3_PORT : z . coerce . number ( ) . positive ( ) . optional ( ) ,
23+ STORAGE_S3_USE_SSL : z
24+ . string ( )
25+ . transform ( ( v ) => v === 'true' )
26+ . optional ( ) ,
27+ STORAGE_S3_ACCESS_KEY : z . string ( ) . optional ( ) ,
28+ STORAGE_S3_SECRET_KEY : z . string ( ) . optional ( ) ,
29+ AWS_REGION : z . string ( ) . optional ( ) ,
30+ AWS_DEFAULT_REGION : z . string ( ) . optional ( ) ,
2631 } ) ,
2732 async setup ( options ) {
2833 const protocol = options . STORAGE_S3_USE_SSL ? 'https' : 'http'
2934 const port = options . STORAGE_S3_PORT ? `:${ options . STORAGE_S3_PORT } ` : ''
35+ let credentials
3036
31- const s3 = new S3Client ( {
32- credentials : {
37+ if ( options . STORAGE_S3_ACCESS_KEY && options . STORAGE_S3_SECRET_KEY ) {
38+ credentials = {
3339 secretAccessKey : options . STORAGE_S3_SECRET_KEY ,
3440 accessKeyId : options . STORAGE_S3_ACCESS_KEY ,
35- } ,
36- endpoint : `${ protocol } ://${ options . STORAGE_S3_ENDPOINT } ${ port } ` ,
37- region : options . STORAGE_S3_REGION ,
41+ }
42+ }
43+
44+ const s3 = new S3Client ( {
45+ credentials,
46+ endpoint : options . STORAGE_S3_ENDPOINT
47+ ? `${ protocol } ://${ options . STORAGE_S3_ENDPOINT } ${ port } `
48+ : undefined ,
49+ region : options . AWS_REGION ?? options . AWS_DEFAULT_REGION ?? options . STORAGE_S3_REGION ,
3850 forcePathStyle : true ,
3951 } )
4052
0 commit comments