@@ -16,7 +16,7 @@ module.exports = function (options) {
16
16
} ;
17
17
18
18
options = _ . extend ( {
19
- tmpDir : '/tmp' ,
19
+ tmpDir : __dirname + '/tmp' ,
20
20
uploadDir : __dirname + '/public/files' ,
21
21
uploadUrl : '/files/' ,
22
22
maxPostSize : 11000000000 , // 11 GB
@@ -92,11 +92,9 @@ module.exports = function (options) {
92
92
} ;
93
93
94
94
UploadHandler . prototype . noCache = function ( ) {
95
- this . res . set ( {
96
- 'Pragma' : 'no-cache' ,
97
- 'Cache-Control' : 'no-store, no-cache, must-revalidate' ,
98
- 'Content-Disposition' : 'inline; filename="files.json"'
99
- } ) ;
95
+ this . res . header ( 'Pragma' , 'no-cache' ) ;
96
+ this . res . header ( 'Cache-Control' , 'no-store, no-cache, must-revalidate' ) ;
97
+ this . res . header ( 'Content-Disposition' , 'inline; filename="files.json"' ) ;
100
98
} ;
101
99
102
100
UploadHandler . prototype . get = function ( ) {
@@ -162,6 +160,8 @@ module.exports = function (options) {
162
160
fs . unlink ( file . path ) ;
163
161
return ;
164
162
}
163
+ var _filename = handler . req . query . imgName ;
164
+ fileInfo . name = _filename ? _filename + path . extname ( fileInfo . name ) : fileInfo . name ;
165
165
fs . renameSync ( file . path , options . uploadDir + '/' + fileInfo . name ) ;
166
166
if ( options . imageTypes . test ( fileInfo . name ) && _ . keys ( options . imageVersions ) . length ) {
167
167
Object . keys ( options . imageVersions ) . forEach ( function ( version ) {
@@ -208,19 +208,15 @@ module.exports = function (options) {
208
208
} ;
209
209
210
210
return function ( req , res , next ) {
211
- res . set ( {
212
- 'Access-Control-Allow-Origin' : options . accessControl . allowOrigin ,
213
- 'Access-Control-Allow-Methods' : options . accessControl . allowMethods
214
- } ) ;
211
+ res . header ( 'Access-Control-Allow-Origin' , options . accessControl . allowOrigin ) ;
212
+ res . header ( 'Access-Control-Allow-Methods' , options . accessControl . allowMethods ) ;
213
+
215
214
var handler = new UploadHandler ( req , res , function ( result , redirect ) {
216
215
if ( redirect ) {
217
216
res . redirect ( redirect . replace ( / % s / , encodeURIComponent ( JSON . stringify ( result ) ) ) ) ;
218
217
} else {
219
- res . set ( {
220
- 'Content-Type' : req . headers . accept . indexOf ( 'application/json' ) !== - 1
221
- ? 'application/json'
222
- : 'text/plain'
223
- } ) ;
218
+ var _tmp = req . headers . accept . indexOf ( 'application/json' ) !== - 1 ? 'application/json' : 'text/plain' ;
219
+ res . header ( 'Content-Type' , _tmp ) ;
224
220
res . json ( 200 , result ) ;
225
221
}
226
222
} ) ;
0 commit comments