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 11import uuid from 'node-uuid' ;
22import S3Policy from 's3-policy-v4' ;
33import s3 from '@auth0/s3' ;
4+ import mongoose from 'mongoose' ;
45import { getProjectsForUserId } from './project.controller' ;
56import { findUserByUsername } from './user.controller' ;
67
8+ const { ObjectId } = mongoose . Types ;
9+
710const client = s3 . createClient ( {
811 maxAsyncS3 : 20 ,
912 s3RetryCount : 3 ,
@@ -27,15 +30,12 @@ function getExtension(filename) {
2730}
2831
2932export 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 } ` ;
3738 }
38- const objectKey = matchResults [ 1 ] ;
3939 return objectKey ;
4040}
4141
You can’t perform that action at this time.
0 commit comments