Merge branch 'master' of github.com:designcreateplay/NodeBB

This commit is contained in:
Julian Lam
2014-02-27 14:05:55 -05:00
35 changed files with 781 additions and 829 deletions

View File

@@ -239,6 +239,7 @@ var fs = require('fs'),
'src/templates.js',
'src/ajaxify.js',
'src/translator.js',
'src/overrides.js',
'src/utils.js'
],
minFile: nconf.get('relative_path') + 'nodebb.min.js',

View File

@@ -109,20 +109,22 @@ var nconf = require('nconf'),
return res.redirect('/403');
}
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
var params = null;
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'],
params = null, er;
try {
params = JSON.parse(req.body.params);
} catch (e) {
return res.send({
er = {
error: 'Error uploading file! Error :' + e.message
});
};
return res.send(req.xhr ? er : JSON.stringify(er));
}
if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
res.send({
er = {
error: 'Allowed image types are png, jpg and gif!'
});
};
res.send(req.xhr ? er : JSON.stringify(er));
return;
}
@@ -136,12 +138,12 @@ var nconf = require('nconf'),
return res.redirect('/403');
}
var allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'];
var allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'],
er;
if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
res.send({
error: 'You can only upload icon file type!'
});
er = {error: 'You can only upload icon file type!'};
res.send(req.xhr ? er : JSON.stringify(er));
return;
}
@@ -149,14 +151,12 @@ var nconf = require('nconf'),
fs.unlink(req.files.userPhoto.path);
if(err) {
return res.send({
error: err.message
});
er = {error: err.message};
return res.send(req.xhr ? er : JSON.stringify(er));
}
res.json({
path: image.url
});
var rs = {path: image.url};
res.send(req.xhr ? rs : JSON.stringify(rs));
});
});
@@ -166,12 +166,12 @@ var nconf = require('nconf'),
return res.redirect('/403');
}
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
var allowedTypes = ['image/png', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/gif'],
er;
if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
res.send({
error: 'Allowed image types are png, jpg and gif!'
});
er = {error: 'Allowed image types are png, jpg and gif!'};
res.send(req.xhr ? er : JSON.stringify(er));
return;
}
@@ -191,17 +191,16 @@ var nconf = require('nconf'),
function uploadImage(filename, req, res) {
function done(err, image) {
var er, rs;
fs.unlink(req.files.userPhoto.path);
if(err) {
return res.send({
error: err.message
});
er = {error: err.message};
return res.send(req.xhr ? er : JSON.stringify(er));
}
res.json({
path: image.url
});
rs = {path: image.url};
res.send(req.xhr ? rs : JSON.stringify(rs));
}
if(plugins.hasListeners('filter:uploadImage')) {

View File

@@ -469,16 +469,25 @@ var path = require('path'),
async.map(files, filesIterator, function(err, images) {
deleteTempFiles();
if(err) {
return res.json(500, err.message);
return res.send(500, err.message);
}
res.json(200, images);
// if this was not a XMLHttpRequest (hence the req.xhr check http://expressjs.com/api.html#req.xhr)
// then most likely it's submit via the iFrame workaround, via the jquery.form plugin's ajaxSubmit()
// we need to send it as text/html so IE8 won't trigger a file download for the json response
// malsup.com/jquery/form/#file-upload
// Also, req.send is safe for both types, if the response was an object, res.send will automatically submit as application/json
// expressjs.com/api.html#res.send
res.send(200, req.xhr ? images : JSON.stringify(images));
});
}
app.post('/post/upload', function(req, res, next) {
upload(req, res, function(file, next) {
if(file.type.match('image.*')) {
if(file.type.match(/image./)) {
posts.uploadPostImage(file, next);
} else {
posts.uploadPostFile(file, next);
@@ -488,7 +497,7 @@ var path = require('path'),
app.post('/topic/thumb/upload', function(req, res, next) {
upload(req, res, function(file, next) {
if(file.type.match('image.*')) {
if(file.type.match(/image./)) {
topics.uploadTopicThumb(file, next);
} else {
res.json(500, {message: 'Invalid File'});