File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
import uuid from 'node-uuid' ;
2
2
import S3Policy from 's3-policy-v4' ;
3
3
import s3 from '@auth0/s3' ;
4
+ import mongoose from 'mongoose' ;
4
5
import { getProjectsForUserId } from './project.controller' ;
5
6
import { findUserByUsername } from './user.controller' ;
6
7
8
+ const { ObjectId } = mongoose . Types ;
9
+
7
10
const client = s3 . createClient ( {
8
11
maxAsyncS3 : 20 ,
9
12
s3RetryCount : 3 ,
@@ -27,15 +30,12 @@ function getExtension(filename) {
27
30
}
28
31
29
32
export function getObjectKey ( url ) {
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 ] ;
33
+ const urlArray = url . split ( '/' ) ;
34
+ const objectKey = urlArray . pop ( ) ;
35
+ const userId = urlArray . pop ( ) ;
36
+ if ( ObjectId . isValid ( userId ) && userId === new ObjectId ( userId ) . toString ( ) ) {
37
+ return `${ userId } /${ objectKey } ` ;
37
38
}
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