File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -17,25 +17,25 @@ const client = s3.createClient({
17
17
} ,
18
18
} ) ;
19
19
20
- const s3Bucket = process . env . S3_BUCKET_URL_BASE ||
21
- `https://s3-${ process . env . AWS_REGION } .amazonaws.com/${ process . env . S3_BUCKET } /` ;
20
+ const bucketBase = process . env . S3_BUCKET_URL_BASE ;
21
+ const s3Url = `https://s3-${ process . env . AWS_REGION } .amazonaws.com/${ process . env . S3_BUCKET } /` ;
22
+ const s3Bucket = bucketBase || s3Url ;
22
23
23
24
function getExtension ( filename ) {
24
25
const i = filename . lastIndexOf ( '.' ) ;
25
26
return ( i < 0 ) ? '' : filename . substr ( i ) ;
26
27
}
27
28
28
29
export function getObjectKey ( url ) {
29
- const urlArray = url . split ( '/' ) ;
30
- let objectKey ;
31
- if ( urlArray . length === 5 ) {
32
- const key = urlArray . pop ( ) ;
33
- const userId = urlArray . pop ( ) ;
34
- objectKey = `${ userId } /${ key } ` ;
35
- } else {
36
- const key = urlArray . pop ( ) ;
37
- objectKey = key ;
30
+ const matchResults = url . split ( s3Bucket ) ;
31
+ // if, for some reason, the object is not using the default bucket url
32
+ if ( matchResults . length === 1 ) {
33
+ if ( bucketBase ) {
34
+ return url . split ( s3Url ) [ 1 ] ;
35
+ }
36
+ return url . split ( bucketBase ) [ 1 ] ;
38
37
}
38
+ const objectKey = matchResults [ 1 ] ;
39
39
return objectKey ;
40
40
}
41
41
You can’t perform that action at this time.
0 commit comments