v1.18.x
barisusakli 10 years ago
parent 08c1dad3ee
commit 456b844e61

@ -59,7 +59,8 @@
"cant-ban-other-admins": "You can't ban other admins!", "cant-ban-other-admins": "You can't ban other admins!",
"invalid-image-type": "Invalid image type", "invalid-image-type": "Invalid image type. Allowed types are: %1",
"invalid-image-extension": "Invalid image extension",
"group-name-too-short": "Group name too short", "group-name-too-short": "Group name too short",
"group-already-exists": "Group already exists", "group-already-exists": "Group already exists",
@ -88,5 +89,6 @@
"reload-failed": "NodeBB encountered a problem while reloading: \"%1\". NodeBB will continue to serve the existing client-side assets, although you should undo what you did just prior to reloading.", "reload-failed": "NodeBB encountered a problem while reloading: \"%1\". NodeBB will continue to serve the existing client-side assets, although you should undo what you did just prior to reloading.",
"registration-error": "Registration Error" "registration-error": "Registration Error",
"parse-error": "Something went wrong while parsing server response"
} }

@ -0,0 +1,5 @@
{
"uploading-file" : "Uploading the file...",
"select-file-to-upload": "Select a file to upload!",
"upload-success": "File uploaded successfully!"
}

@ -30,16 +30,16 @@ define('uploader', ['csrf'], function(csrf) {
function showAlert(type, message) { function showAlert(type, message) {
module.hideAlerts(); module.hideAlerts();
uploadModal.find('#alert-' + type).text(message).removeClass('hide'); uploadModal.find('#alert-' + type).translateText(message).removeClass('hide');
} }
showAlert('status', 'uploading the file ...'); showAlert('status', '[[uploads:uploading-file]]');
uploadModal.find('#upload-progress-bar').css('width', '0%'); uploadModal.find('#upload-progress-bar').css('width', '0%');
uploadModal.find('#upload-progress-box').show().removeClass('hide'); uploadModal.find('#upload-progress-box').show().removeClass('hide');
if (!$('#userPhotoInput').val()) { if (!$('#userPhotoInput').val()) {
showAlert('error', 'select an image to upload!'); showAlert('error', '[[uploads:select-file-to-upload]]');
return false; return false;
} }
@ -49,7 +49,7 @@ define('uploader', ['csrf'], function(csrf) {
}, },
error: function(xhr) { error: function(xhr) {
xhr = maybeParse(xhr); xhr = maybeParse(xhr);
showAlert('error', 'Error: ' + xhr.status); showAlert('error', xhr.responseJSON.error);
}, },
uploadProgress: function(event, position, total, percent) { uploadProgress: function(event, position, total, percent) {
@ -66,7 +66,7 @@ define('uploader', ['csrf'], function(csrf) {
callback(response[0].url); callback(response[0].url);
showAlert('success', 'File uploaded successfully!'); showAlert('success', '[[uploads:upload-success]]');
setTimeout(function() { setTimeout(function() {
module.hideAlerts(); module.hideAlerts();
uploadModal.modal('hide'); uploadModal.modal('hide');
@ -83,7 +83,7 @@ define('uploader', ['csrf'], function(csrf) {
try { try {
return $.parseJSON(response); return $.parseJSON(response);
} catch (e) { } catch (e) {
return {error: 'Something went wrong while parsing server response'}; return {error: '[[error:parse-error]]'};
} }
} }
return response; return response;

@ -395,25 +395,19 @@ accountsController.uploadPicture = function (req, res, next) {
if (userPhoto.size > uploadSize * 1024) { if (userPhoto.size > uploadSize * 1024) {
fs.unlink(userPhoto.path); fs.unlink(userPhoto.path);
return res.json({ return next(new Error('[[error:file-too-big, ' + uploadSize + ']]'));
error: 'Images must be smaller than ' + uploadSize + ' kb!'
});
} }
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif']; var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
if (allowedTypes.indexOf(userPhoto.type) === -1) { if (allowedTypes.indexOf(userPhoto.type) === -1) {
fs.unlink(userPhoto.path); fs.unlink(userPhoto.path);
return res.json({ return next(new Error('[[error:invalid-image-type, ' + allowedTypes.join(', ') + ']]'));
error: 'Allowed image types are png, jpg and gif!'
});
} }
var extension = path.extname(userPhoto.name); var extension = path.extname(userPhoto.name);
if (!extension) { if (!extension) {
fs.unlink(userPhoto.path); fs.unlink(userPhoto.path);
return res.json({ return next(new Error('[[error:invalid-image-extension]]'));
error: 'Error uploading file! Error : Invalid extension!'
});
} }
var updateUid = req.user ? req.user.uid : 0; var updateUid = req.user ? req.user.uid : 0;
@ -465,7 +459,7 @@ accountsController.uploadPicture = function (req, res, next) {
if (err) { if (err) {
fs.unlink(userPhoto.path); fs.unlink(userPhoto.path);
return res.json({error:err.message}); return next(err);
} }
if (plugins.hasListeners('filter:uploadImage')) { if (plugins.hasListeners('filter:uploadImage')) {
@ -476,6 +470,9 @@ accountsController.uploadPicture = function (req, res, next) {
var filename = updateUid + '-profileimg' + (convertToPNG ? '.png' : extension); var filename = updateUid + '-profileimg' + (convertToPNG ? '.png' : extension);
user.getUserField(updateUid, 'uploadedpicture', function (err, oldpicture) { user.getUserField(updateUid, 'uploadedpicture', function (err, oldpicture) {
if (err) {
return next(err);
}
if (!oldpicture) { if (!oldpicture) {
file.saveFileToLocal(filename, 'profile', userPhoto.path, done); file.saveFileToLocal(filename, 'profile', userPhoto.path, done);
return; return;

@ -16,16 +16,13 @@ uploadsController.uploadCategoryPicture = function(req, res, next) {
try { try {
params = JSON.parse(req.body.params); params = JSON.parse(req.body.params);
} catch (e) { } catch (e) {
var err = {
error: 'Error uploading file! Error :' + e.message
};
fs.unlink(uploadedFile.path); fs.unlink(uploadedFile.path);
return res.send(req.xhr ? err : JSON.stringify(err)); return next(e);
} }
if (validateUpload(req, res, uploadedFile, allowedTypes)) { if (validateUpload(req, res, next, uploadedFile, allowedTypes)) {
var filename = 'category-' + params.cid + path.extname(uploadedFile.name); var filename = 'category-' + params.cid + path.extname(uploadedFile.name);
uploadImage(filename, 'category', uploadedFile, req, res); uploadImage(filename, 'category', uploadedFile, req, res, next);
} }
}; };
@ -33,13 +30,14 @@ uploadsController.uploadFavicon = function(req, res, next) {
var uploadedFile = req.files.files[0]; var uploadedFile = req.files.files[0];
var allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon']; var allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'];
if (validateUpload(res, req, uploadedFile, allowedTypes)) { if (validateUpload(res, req, next, uploadedFile, allowedTypes)) {
file.saveFileToLocal('favicon.ico', 'files', uploadedFile.path, function(err, image) { file.saveFileToLocal('favicon.ico', 'files', uploadedFile.path, function(err, image) {
fs.unlink(uploadedFile.path); fs.unlink(uploadedFile.path);
if (err) {
return next(err);
}
var response = err ? {error: err.message} : [{name: uploadedFile.name, url: image.url}]; res.json([{name: uploadedFile.name, url: image.url}]);
res.send(req.xhr ? response : JSON.stringify(response));
}); });
} }
}; };
@ -55,33 +53,31 @@ uploadsController.uploadGravatarDefault = function(req, res, next) {
function upload(name, req, res, next) { function upload(name, req, res, next) {
var uploadedFile = req.files.files[0]; var uploadedFile = req.files.files[0];
var allowedTypes = ['image/png', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/gif']; var allowedTypes = ['image/png', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/gif'];
if (validateUpload(req, res, uploadedFile, allowedTypes)) { if (validateUpload(req, res, next, uploadedFile, allowedTypes)) {
var filename = name + path.extname(uploadedFile.name); var filename = name + path.extname(uploadedFile.name);
uploadImage(filename, 'files', uploadedFile, req, res); uploadImage(filename, 'files', uploadedFile, req, res, next);
} }
} }
function validateUpload(req, res, uploadedFile, allowedTypes) { function validateUpload(req, res, next, uploadedFile, allowedTypes) {
if (allowedTypes.indexOf(uploadedFile.type) === -1) { if (allowedTypes.indexOf(uploadedFile.type) === -1) {
var err = {
error: 'Invalid image type. Allowed types are: ' + allowedTypes.join(', ')
};
fs.unlink(uploadedFile.path); fs.unlink(uploadedFile.path);
res.send(req.xhr ? err : JSON.stringify(err));
next(new Error('[[error:invalid-image-type, ' + allowedTypes.join(', ') + ']]'));
return false; return false;
} }
return true; return true;
} }
function uploadImage(filename, folder, uploadedFile, req, res) { function uploadImage(filename, folder, uploadedFile, req, res, next) {
function done(err, image) { function done(err, image) {
fs.unlink(uploadedFile.path); fs.unlink(uploadedFile.path);
if (err) {
return next(err);
}
var response = err ? {error: err.message} : [{name: uploadedFile.name, url: image.url}]; res.json([{name: uploadedFile.name, url: image.url}]);
res.send(req.xhr ? response : JSON.stringify(response));
} }
if (plugins.hasListeners('filter:uploadImage')) { if (plugins.hasListeners('filter:uploadImage')) {

@ -166,7 +166,7 @@ SocketUser.changePicture = function(socket, data, callback) {
} else if (type === 'uploaded') { } else if (type === 'uploaded') {
type = 'uploadedpicture'; type = 'uploadedpicture';
} else { } else {
return callback(new Error('[[error:invalid-image-type]]')); return callback(new Error('[[error:invalid-image-type, ' + ['gravatar', 'uploadedpicture'].join(', ') + ']]'));
} }
if (socket.uid === parseInt(data.uid, 10)) { if (socket.uid === parseInt(data.uid, 10)) {

Loading…
Cancel
Save