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({
1717 } ,
1818} ) ;
1919
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 ;
2223
2324function getExtension ( filename ) {
2425 const i = filename . lastIndexOf ( '.' ) ;
2526 return ( i < 0 ) ? '' : filename . substr ( i ) ;
2627}
2728
2829export 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 ] ;
3837 }
38+ const objectKey = matchResults [ 1 ] ;
3939 return objectKey ;
4040}
4141
You can’t perform that action at this time.
0 commit comments