@@ -115,7 +115,7 @@ const createIndex = async (collection, keys, opts) => {
115115 * @param config._preCollectionName {String} - [Server] preCollection name
116116 * @summary Create new instance of FilesCollection
117117 */
118- export class FilesCollection extends FilesCollectionCore {
118+ class FilesCollection extends FilesCollectionCore {
119119 constructor ( config ) {
120120 super ( ) ;
121121 let storagePath ;
@@ -844,10 +844,6 @@ export class FilesCollection extends FilesCollectionCore {
844844
845845 opts . fileId = helpers . sanitize ( opts . fileId , 20 , 'a' ) ;
846846
847- if ( opts . FSName ) {
848- opts . FSName = helpers . sanitize ( opts . FSName ) ;
849- }
850-
851847 self . _debug ( `[FilesCollection] [File Start Method] ${ opts . file . name } - ${ opts . fileId } ` ) ;
852848 opts . ___s = true ;
853849 const { result } = self . _prepareUpload ( helpers . clone ( opts ) , this . userId , 'DDP Start Method' ) ;
@@ -968,10 +964,6 @@ export class FilesCollection extends FilesCollectionCore {
968964 opts . chunkId = - 1 ;
969965 }
970966
971- if ( opts . fileId ) {
972- opts . fileId = helpers . sanitize ( opts . fileId , 20 , 'a' ) ;
973- }
974-
975967 if ( ! helpers . isString ( opts . FSName ) ) {
976968 opts . FSName = opts . fileId ;
977969 }
@@ -993,6 +985,11 @@ export class FilesCollection extends FilesCollectionCore {
993985 result . _id = opts . fileId ;
994986 result . userId = userId || null ;
995987 opts . FSName = helpers . sanitize ( opts . FSName ) ;
988+
989+ if ( this . namingFunction ) {
990+ opts . FSName = this . namingFunction ( opts ) ;
991+ }
992+
996993 result . path = `${ this . storagePath ( result ) } ${ nodePath . sep } ${ opts . FSName } ${ extensionWithDot } ` ;
997994 result = Object . assign ( result , this . _dataToSchema ( result ) ) ;
998995
@@ -1230,12 +1227,12 @@ export class FilesCollection extends FilesCollectionCore {
12301227
12311228 opts . fileId = opts . fileId && helpers . sanitize ( opts . fileId , 20 , 'a' ) ;
12321229 const fileId = opts . fileId || Random . id ( ) ;
1233- const FSName = this . namingFunction ? this . namingFunction ( opts ) : fileId ;
1234- const fileName = ( opts . name || opts . fileName ) ? ( opts . name || opts . fileName ) : FSName ;
1230+ const fsName = this . namingFunction ? this . namingFunction ( opts ) : fileId ;
1231+ const fileName = ( opts . name || opts . fileName ) ? ( opts . name || opts . fileName ) : fsName ;
12351232
12361233 const { extension, extensionWithDot} = this . _getExt ( fileName ) ;
12371234
1238- opts . path = `${ this . storagePath ( opts ) } ${ nodePath . sep } ${ FSName } ${ extensionWithDot } ` ;
1235+ opts . path = `${ this . storagePath ( opts ) } ${ nodePath . sep } ${ fsName } ${ extensionWithDot } ` ;
12391236 opts . type = this . _getMimeType ( opts ) ;
12401237 if ( ! helpers . isObject ( opts . meta ) ) {
12411238 opts . meta = { } ;
@@ -1341,12 +1338,12 @@ export class FilesCollection extends FilesCollectionCore {
13411338 }
13421339
13431340 const fileId = ( opts . fileId && helpers . sanitize ( opts . fileId , 20 , 'a' ) ) || Random . id ( ) ;
1344- const FSName = this . namingFunction ? this . namingFunction ( opts ) : fileId ;
1341+ const fsName = this . namingFunction ? this . namingFunction ( opts ) : fileId ;
13451342 const pathParts = url . split ( '/' ) ;
1346- const fileName = ( opts . name || opts . fileName ) ? ( opts . name || opts . fileName ) : pathParts [ pathParts . length - 1 ] . split ( '?' ) [ 0 ] || FSName ;
1343+ const fileName = ( opts . name || opts . fileName ) ? ( opts . name || opts . fileName ) : pathParts [ pathParts . length - 1 ] . split ( '?' ) [ 0 ] || fsName ;
13471344
13481345 const { extension, extensionWithDot} = this . _getExt ( fileName ) ;
1349- opts . path = `${ this . storagePath ( opts ) } ${ nodePath . sep } ${ FSName } ${ extensionWithDot } ` ;
1346+ opts . path = `${ this . storagePath ( opts ) } ${ nodePath . sep } ${ fsName } ${ extensionWithDot } ` ;
13501347
13511348 const storeResult = ( result , cb ) => {
13521349 result . _id = fileId ;
@@ -1988,3 +1985,5 @@ export class FilesCollection extends FilesCollectionCore {
19881985 }
19891986 }
19901987}
1988+
1989+ export { FilesCollection , helpers } ;
0 commit comments