Skip to content

Commit bf894bf

Browse files
author
Sebastian.Just
committed
Merge remote-tracking branch 'upstream/master'
Conflicts: lib/uploadhandler.js
2 parents 56c640a + efe6040 commit bf894bf

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

History.md

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
0.1.7 / 2014-10-09
2+
==================
3+
4+
* #58 improved support for IE9
5+
6+
0.1.6 / 2014-10-04
7+
==================
8+
9+
* #56 avoid path traversal in DELETE requests
10+
11+
0.1.5 / 2014-08-02
12+
==================
13+
14+
* #31 request and response objects passed to event handlers
15+
16+
0.1.4 / 2014-07-06
17+
==================
18+
19+
* #53 documentation update
20+
121
0.1.3 / 2014-07-05
222
==================
323

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ More sophisticated example - Events
100100
app.use('/upload', upload.fileHandler());
101101

102102
// events
103-
upload.on('begin', function (fileInfo) {
103+
upload.on('begin', function (fileInfo, req, res) {
104104
// fileInfo structure is the same as returned to browser
105105
// {
106106
// name: '3 (3).jpg',
@@ -113,10 +113,10 @@ More sophisticated example - Events
113113
// thumbnail_url: 'http://youhost/uploads/thumbnail/3%20(3).jpg'
114114
// }
115115
});
116-
upload.on('abort', function (fileInfo) { ... });
117-
upload.on('end', function (fileInfo) { ... });
118-
upload.on('delete', function (fileInfo) { ... });
119-
upload.on('error', function (e) {
116+
upload.on('abort', function (fileInfo, req, res) { ... });
117+
upload.on('end', function (fileInfo, req, res) { ... });
118+
upload.on('delete', function (fileInfo, req, res) { ... });
119+
upload.on('error', function (e, req, res) {
120120
console.log(e.message);
121121
});
122122
```
@@ -278,6 +278,9 @@ Other options and their default values:
278278

279279
* [@soomtong](http://github.com/soomtong)
280280
* [@gsarwohadi](https://github.com/gsarwohadi)
281+
* [@peecky](https://github.com/peecky)
282+
* [@tonyspiro](https://github.com/tonyspiro)
283+
* [@derjust](https://github.com/derjust)
281284

282285
## License
283286
Copyright (c) 2012 [Aleksandr Guidrevitch](http://aguidrevitch.blogspot.com/)

lib/filehandler.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ module.exports = function (middleware, options) {
2121
});
2222

2323
handler.on('begin', function (fileInfo) {
24-
middleware.emit('begin', fileInfo);
24+
middleware.emit('begin', fileInfo, req, res);
2525
});
2626
handler.on('end', function (fileInfo) {
27-
middleware.emit('end', fileInfo);
27+
middleware.emit('end', fileInfo, req, res);
2828
});
2929
handler.on('abort', function (fileInfo) {
30-
middleware.emit('abort', fileInfo);
30+
middleware.emit('abort', fileInfo, req, res);
3131
});
3232
handler.on('error', function (e) {
33-
middleware.emit('abort', e);
33+
middleware.emit('abort', e, req, res);
3434
});
3535
handler.on('delete', function (fileName) {
36-
middleware.emit('delete', fileName);
36+
middleware.emit('delete', fileName, req, res);
3737
});
3838

3939
switch (req.method) {

lib/uploadhandler.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ module.exports = function (options) {
2626
UploadHandler.prototype.noCache = function () {
2727
this.res.set({
2828
'Pragma': 'no-cache',
29-
'Cache-Control': 'no-store, no-cache, must-revalidate',
30-
// 'Content-Disposition': 'inline; filename="files.json"'
29+
'Cache-Control': 'no-store, no-cache, must-revalidate'
3130
});
31+
if ((this.req.get("Accept") || "").indexOf("application/json") != -1) {
32+
this.res.set({
33+
'Content-Type': 'application/json',
34+
'Content-Disposition': 'inline; filename="files.json"'
35+
});
36+
} else {
37+
this.res.set({ 'Content-Type': 'text/plain' });
38+
}
3239
};
3340

3441
UploadHandler.prototype.get = function () {
@@ -177,18 +184,12 @@ module.exports = function (options) {
177184
var filepath = path.join(options.uploadDir(), fileName);
178185
if (filepath.indexOf(options.uploadDir()) !== 0) {
179186
self.emit('delete', fileName);
180-
self.callback({success: false});
187+
self.callback({success: false});
181188
return;
182189
}
183190
fs.unlink(filepath, function (ex) {
184191
_.each(options.imageVersions, function (value, version) {
185-
var versionfilepath = path.join(options.uploadDir(), version, fileName);
186-
if (versionfilepath.indexOf(options.uploadDir()) !== 0) {
187-
self.emit('delete', fileName);
188-
self.callback({success: false});
189-
return;
190-
}
191-
fs.unlink(versionfilepath);
192+
fs.unlink(path.join(options.uploadDir(), version, fileName));
192193
});
193194
self.emit('delete', fileName);
194195
self.callback({success: !ex});

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"express",
99
"middleware"
1010
],
11-
"version": "0.1.3",
11+
"version": "0.1.7",
1212
"dependencies": {
1313
"formidable": ">=1.0.11",
1414
"imagemagick": ">=0.1.2",
@@ -29,6 +29,6 @@
2929
"scripts": {
3030
"test": "echo \"Error: no test specified\" && exit 1"
3131
},
32-
"_id": "jquery-file-upload-middleware@0.1.3",
32+
"_id": "jquery-file-upload-middleware@0.1.7",
3333
"license": "MIT"
3434
}

0 commit comments

Comments
 (0)