mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Merge pull request #2306 from mscdex/update-busboy
This commit is contained in:
commit
17589a1afe
2 changed files with 13 additions and 19 deletions
|
@ -2,19 +2,17 @@ var BusBoy = require('busboy'),
|
|||
fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
os = require('os'),
|
||||
crypto = require('crypto'),
|
||||
errors = require('../errors');
|
||||
crypto = require('crypto');
|
||||
|
||||
// ### ghostBusboy
|
||||
// Process multipart file streams
|
||||
function ghostBusBoy(req, res, next) {
|
||||
var busboy,
|
||||
stream,
|
||||
tmpDir,
|
||||
hasError = false;
|
||||
tmpDir;
|
||||
|
||||
// busboy is only used for POST requests
|
||||
if (req.method && !req.method.match(/post/i)) {
|
||||
if (req.method && !/post/i.test(req.method)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
|
@ -29,13 +27,9 @@ function ghostBusBoy(req, res, next) {
|
|||
tmpFileName,
|
||||
md5 = crypto.createHash('md5');
|
||||
|
||||
// If the filename is invalid, mark an error
|
||||
// If the filename is invalid, skip the stream
|
||||
if (!filename) {
|
||||
hasError = true;
|
||||
}
|
||||
// If we've flagged any errors, do not process any streams
|
||||
if (hasError) {
|
||||
return file.emit('end');
|
||||
return file.resume();
|
||||
}
|
||||
|
||||
// Create an MD5 hash of original filename
|
||||
|
@ -54,12 +48,7 @@ function ghostBusBoy(req, res, next) {
|
|||
};
|
||||
});
|
||||
|
||||
busboy.on('limit', function () {
|
||||
hasError = true;
|
||||
res.send(413, new errors.RequestEntityTooLargeError('File size limit breached.'));
|
||||
});
|
||||
|
||||
busboy.on('error', function (error) {
|
||||
file.on('error', function (error) {
|
||||
console.log('Error', 'Something went wrong uploading the file', error);
|
||||
});
|
||||
|
||||
|
@ -73,11 +62,16 @@ function ghostBusBoy(req, res, next) {
|
|||
|
||||
});
|
||||
|
||||
busboy.on('error', function (error) {
|
||||
console.log('Error', 'Something went wrong parsing the form', error);
|
||||
res.send(500, {code: 500, message: 'Could not parse upload completely.'});
|
||||
});
|
||||
|
||||
busboy.on('field', function (fieldname, val) {
|
||||
req.body[fieldname] = val;
|
||||
});
|
||||
|
||||
busboy.on('end', function () {
|
||||
busboy.on('finish', function () {
|
||||
next();
|
||||
});
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
"bcryptjs": "0.7.10",
|
||||
"body-parser": "1.0.2",
|
||||
"bookshelf": "0.7.6",
|
||||
"busboy": "0.0.12",
|
||||
"busboy": "0.2.3",
|
||||
"colors": "0.6.2",
|
||||
"compression": "^1.0.2",
|
||||
"cookie-parser": "1.0.1",
|
||||
|
|
Loading…
Add table
Reference in a new issue