22//
33// Stores Parse files in AWS S3.
44
5- const { S3Client, CreateBucketCommand, PutObjectCommand, DeleteObjectCommand, GetObjectCommand } = require ( '@aws-sdk/client-s3' ) ;
5+ const {
6+ S3Client,
7+ CreateBucketCommand,
8+ PutObjectCommand,
9+ DeleteObjectCommand,
10+ GetObjectCommand,
11+ } = require ( '@aws-sdk/client-s3' ) ;
612const { getSignedUrl } = require ( '@aws-sdk/s3-request-presigner' ) ;
713const optionsFromArguments = require ( './lib/optionsFromArguments' ) ;
814
915const awsCredentialsDeprecationNotice = function awsCredentialsDeprecationNotice ( ) {
1016 // eslint-disable-next-line no-console
11- console . warn ( 'Passing AWS credentials to this adapter is now DEPRECATED and will be removed in a future version' ,
12- 'See: https://github.com/parse-server-modules/parse-server-s3-adapter#aws-credentials for details' ) ;
17+ console . warn (
18+ 'Passing AWS credentials to this adapter is now DEPRECATED and will be removed in a future version' ,
19+ 'See: https://github.com/parse-server-modules/parse-server-s3-adapter#aws-credentials for details'
20+ ) ;
1321} ;
1422
15- const serialize = ( obj ) => {
23+ const serialize = obj => {
1624 const str = [ ] ;
17- Object . keys ( obj ) . forEach ( ( key ) => {
25+ Object . keys ( obj ) . forEach ( key => {
1826 if ( obj [ key ] ) {
1927 str . push ( `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( obj [ key ] ) } ` ) ;
2028 }
@@ -40,7 +48,7 @@ function buildDirectAccessUrl(baseUrl, baseUrlFileKey, presignedUrl, config, fil
4048function responseToBuffer ( response ) {
4149 return new Promise ( ( resolve , reject ) => {
4250 const chunks = [ ] ;
43- response . Body . on ( 'data' , ( chunk ) => chunks . push ( chunk ) ) ;
51+ response . Body . on ( 'data' , chunk => chunks . push ( chunk ) ) ;
4452 response . Body . on ( 'end' , ( ) => resolve ( Buffer . concat ( chunks ) ) ) ;
4553 response . Body . on ( 'error' , reject ) ;
4654 } ) ;
@@ -81,9 +89,7 @@ class S3Adapter {
8189 accessKeyId : options . accessKey ,
8290 secretAccessKey : options . secretKey ,
8391 } ;
84- } else if ( options . credentials )
85- s3Options . credentials = options . credentials ;
86-
92+ } else if ( options . credentials ) s3Options . credentials = options . credentials ;
8793
8894 if ( options . accessKey && options . secretKey ) {
8995 awsCredentialsDeprecationNotice ( ) ;
@@ -104,8 +110,7 @@ class S3Adapter {
104110 await this . _s3Client . send ( new CreateBucketCommand ( { Bucket : this . _bucket } ) ) ;
105111 this . _hasBucket = true ;
106112 } catch ( error ) {
107- if ( error . name === 'BucketAlreadyOwnedByYou' )
108- this . _hasBucket = true ;
113+ if ( error . name === 'BucketAlreadyOwnedByYou' ) this . _hasBucket = true ;
109114 else throw error ;
110115 }
111116 }
@@ -160,9 +165,9 @@ class S3Adapter {
160165 Bucket : this . _bucket ,
161166 Key : this . _bucketPrefix + filename ,
162167 } ;
163- await this . createBucket ( )
168+ await this . createBucket ( ) ;
164169 const command = new DeleteObjectCommand ( params ) ;
165- const response = await this . _s3Client . send ( command )
170+ const response = await this . _s3Client . send ( command ) ;
166171 return response ;
167172 }
168173
@@ -173,7 +178,7 @@ class S3Adapter {
173178 Bucket : this . _bucket ,
174179 Key : this . _bucketPrefix + filename ,
175180 } ;
176- await this . createBucket ( )
181+ await this . createBucket ( ) ;
177182 const command = new GetObjectCommand ( params ) ;
178183 const response = await this . _s3Client . send ( command ) ;
179184 if ( response && ! response . Body ) throw new Error ( response ) ;
@@ -229,17 +234,17 @@ class S3Adapter {
229234 await this . createBucket ( ) ;
230235 const command = new GetObjectCommand ( params ) ;
231236 const data = await this . _s3Client . send ( command ) ;
232- if ( data && ! data . Body ) throw new Error ( " S3 object body is missing." ) ;
237+ if ( data && ! data . Body ) throw new Error ( ' S3 object body is missing.' ) ;
233238
234239 res . writeHead ( 206 , {
235240 'Accept-Ranges' : data . AcceptRanges ,
236241 'Content-Length' : data . ContentLength ,
237242 'Content-Range' : data . ContentRange ,
238243 'Content-Type' : data . ContentType ,
239244 } ) ;
240- data . Body . on ( 'data' , ( chunk ) => res . write ( chunk ) ) ;
245+ data . Body . on ( 'data' , chunk => res . write ( chunk ) ) ;
241246 data . Body . on ( 'end' , ( ) => res . end ( ) ) ;
242- data . Body . on ( 'error' , ( e ) => {
247+ data . Body . on ( 'error' , e => {
243248 res . status ( 404 ) ;
244249 res . send ( e . message ) ;
245250 } ) ;
0 commit comments