@@ -9,32 +9,32 @@ const fs = require('fs')
9
9
10
10
function uploader ( options ) {
11
11
const uploadPath = options . path
12
- const fileName = options . name
13
12
const log = options . log
14
13
15
14
return upload
16
15
17
- function upload ( data , cb ) {
16
+ function upload ( data , options , cb ) {
18
17
const files = [ ]
18
+ const fileNames = options . fileNames || { }
19
19
Async . each ( Object . keys ( data ) , ( prop , cbAsync ) => {
20
20
if ( data . hasOwnProperty ( prop ) ) files . push ( prop )
21
21
cbAsync ( )
22
22
} ,
23
23
( err ) => {
24
24
if ( err ) return cb ( Boom . internal ( ) )
25
- saveFiles ( files , data , cb )
25
+ saveFiles ( files , fileNames , data , cb )
26
26
} )
27
27
}
28
28
29
- function saveFiles ( files , data , cb ) {
29
+ function saveFiles ( files , fileNames , data , cb ) {
30
30
if ( ! files ) return cb ( Boom . badData ( ) )
31
- if ( files . length === 1 ) return saveFile ( data [ files [ 0 ] ] , cb )
31
+ if ( files . length === 1 ) return saveFile ( data [ files [ 0 ] ] , fileNames [ files [ 0 ] ] , cb )
32
32
Async . map ( files , ( file , cbAsync ) => {
33
- saveFile ( data [ file ] , cbAsync )
33
+ saveFile ( data [ file ] , fileNames [ file ] , cbAsync )
34
34
} , cb )
35
35
}
36
36
37
- function saveFile ( data , cb ) {
37
+ function saveFile ( data , fileName , cb ) {
38
38
const mimeType = data . hapi . headers [ 'content-type' ]
39
39
const name = fileName || urlencode . decode ( data . hapi . filename , 'utf8' )
40
40
const file = data
@@ -54,9 +54,10 @@ function uploader (options) {
54
54
'Error while saving file, possible issue with path - ' +
55
55
err
56
56
) )
57
+ } else {
58
+ // Still not sure if throw is the best to go here
59
+ log ( [ 'error' ] , new Error ( 'Error while saving file - ' + err ) )
57
60
}
58
- // Still not sure if throw is the best to go here
59
- log ( [ 'error' ] , new Error ( 'Error while saving file - ' + err ) )
60
61
return cb ( Boom . internal ( ) )
61
62
} )
62
63
0 commit comments