File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -280,7 +280,6 @@ var S3Adapter = require("@parse/s3-files-adapter");
280
280
var AWS = require (" aws-sdk" );
281
281
282
282
// Configure Digital Ocean Spaces EndPoint
283
- const spacesEndpoint = new AWS.Endpoint (process .env .SPACES_ENDPOINT );
284
283
var s3Options = {
285
284
bucket: process .env .SPACES_BUCKET_NAME ,
286
285
baseUrl: process .env .SPACES_BASE_URL ,
@@ -293,7 +292,7 @@ var s3Options = {
293
292
s3overrides: {
294
293
accessKeyId: process .env .SPACES_ACCESS_KEY ,
295
294
secretAccessKey: process .env .SPACES_SECRET_KEY ,
296
- endpoint: spacesEndpoint
295
+ endpoint: process . env . SPACES_ENDPOINT
297
296
}
298
297
};
299
298
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ class S3Adapter {
73
73
this . _presignedUrlExpires = parseInt ( options . presignedUrlExpires , 10 ) ;
74
74
this . _encryption = options . ServerSideEncryption ;
75
75
this . _generateKey = options . generateKey ;
76
+ this . _endpoint = options . s3overrides ?. endpoint ;
76
77
// Optional FilesAdaptor method
77
78
this . validateFilename = options . validateFilename ;
78
79
@@ -157,7 +158,8 @@ class S3Adapter {
157
158
await this . createBucket ( ) ;
158
159
const command = new PutObjectCommand ( params ) ;
159
160
const response = await this . _s3Client . send ( command ) ;
160
- const location = `https://${ this . _bucket } .s3.${ this . _region } .amazonaws.com/${ params . Key } ` ;
161
+ const endpoint = this . _endpoint || `https://${ this . _bucket } .s3.${ this . _region } .amazonaws.com` ;
162
+ const location = `${ endpoint } /${ params . Key } ` ;
161
163
162
164
return Object . assign ( response || { } , { Location : location } ) ;
163
165
}
Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ describe('S3Adapter tests', () => {
153
153
s3overrides : { endpoint : otherEndpoint } ,
154
154
} ;
155
155
const s3 = new S3Adapter ( confObj ) ;
156
+ expect ( s3 . _endpoint ) . toEqual ( otherEndpoint ) ;
156
157
const endpointFromConfig = await s3 . _s3Client . config . endpoint ( ) ;
157
158
expect ( endpointFromConfig . protocol ) . toEqual ( 'https:' ) ;
158
159
expect ( endpointFromConfig . path ) . toEqual ( '/path' ) ;
@@ -161,6 +162,18 @@ describe('S3Adapter tests', () => {
161
162
expect ( endpointFromConfig . query . foo ) . toEqual ( 'bar' ) ;
162
163
} ) ;
163
164
165
+ it ( "should have undefined endpoint if no custom endpoint is provided" , async ( ) => {
166
+ const confObj = {
167
+ bucketPrefix : 'test/' ,
168
+ bucket : 'bucket-1' ,
169
+ secretKey : 'secret-1' ,
170
+ accessKey : 'key-1' ,
171
+ } ;
172
+ const s3 = new S3Adapter ( confObj ) ;
173
+ const endpoint = await s3 . _s3Client . config . endpoint ?. ( ) ;
174
+ expect ( endpoint ) . toBeUndefined ( ) ;
175
+ } ) ;
176
+
164
177
it ( 'should accept options and overrides as args' , ( ) => {
165
178
const confObj = {
166
179
bucketPrefix : 'test/' ,
You can’t perform that action at this time.
0 commit comments