mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	closes #4392
This commit is contained in:
		| @@ -45,11 +45,26 @@ uploadsController.upload = function(req, res, filesIterator, next) { | |||||||
|  |  | ||||||
| uploadsController.uploadPost = function(req, res, next) { | uploadsController.uploadPost = function(req, res, next) { | ||||||
| 	uploadsController.upload(req, res, function(uploadedFile, next) { | 	uploadsController.upload(req, res, function(uploadedFile, next) { | ||||||
| 		if (uploadedFile.type.match(/image./)) { | 		var isImage = uploadedFile.type.match(/image./); | ||||||
| 			uploadImage(req.uid, uploadedFile, next); | 		if (isImage && plugins.hasListeners('filter:uploadImage')) { | ||||||
|  | 			return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: req.uid}, next); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		async.waterfall([ | ||||||
|  | 			function(next) { | ||||||
|  | 				if (isImage) { | ||||||
|  | 					file.isFileTypeAllowed(uploadedFile.path, next); | ||||||
| 				} else { | 				} else { | ||||||
|  | 					next(); | ||||||
|  | 				} | ||||||
|  | 			}, | ||||||
|  | 			function (next) { | ||||||
|  | 				if (parseInt(meta.config.allowFileUploads, 10) !== 1) { | ||||||
|  | 					return next(new Error('[[error:uploads-are-disabled]]')); | ||||||
|  | 				} | ||||||
| 				uploadFile(req.uid, uploadedFile, next); | 				uploadFile(req.uid, uploadedFile, next); | ||||||
| 			} | 			} | ||||||
|  | 		], next); | ||||||
| 	}, next); | 	}, next); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -65,7 +80,10 @@ uploadsController.uploadThumb = function(req, res, next) { | |||||||
| 				return next(err); | 				return next(err); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if (uploadedFile.type.match(/image./)) { | 			if (!uploadedFile.type.match(/image./)) { | ||||||
|  | 				return next(new Error('[[error:invalid-file]]')); | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 			var size = parseInt(meta.config.topicThumbSize, 10) || 120; | 			var size = parseInt(meta.config.topicThumbSize, 10) || 120; | ||||||
| 			image.resizeImage({ | 			image.resizeImage({ | ||||||
| 				path: uploadedFile.path, | 				path: uploadedFile.path, | ||||||
| @@ -76,11 +94,13 @@ uploadsController.uploadThumb = function(req, res, next) { | |||||||
| 				if (err) { | 				if (err) { | ||||||
| 					return next(err); | 					return next(err); | ||||||
| 				} | 				} | ||||||
| 					uploadImage(req.uid, uploadedFile, next); |  | ||||||
| 				}); | 				if (plugins.hasListeners('filter:uploadImage')) { | ||||||
| 			} else { | 					return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: req.uid}, next); | ||||||
| 				next(new Error('[[error:invalid-file]]')); |  | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|  | 				uploadFile(req.uid, uploadedFile, next); | ||||||
|  | 			}); | ||||||
| 		}); | 		}); | ||||||
| 	}, next); | 	}, next); | ||||||
| }; | }; | ||||||
| @@ -102,32 +122,11 @@ uploadsController.uploadGroupCover = function(uid, uploadedFile, callback) { | |||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| function uploadImage(uid, image, callback) { |  | ||||||
| 	if (plugins.hasListeners('filter:uploadImage')) { |  | ||||||
| 		return plugins.fireHook('filter:uploadImage', {image: image, uid: uid}, callback); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	file.isFileTypeAllowed(image.path, function(err) { |  | ||||||
| 		if (err) { |  | ||||||
| 			return callback(err); |  | ||||||
| 		} |  | ||||||
| 		if (parseInt(meta.config.allowFileUploads, 10)) { |  | ||||||
| 			uploadFile(uid, image, callback); |  | ||||||
| 		} else { |  | ||||||
| 			callback(new Error('[[error:uploads-are-disabled]]')); |  | ||||||
| 		} |  | ||||||
| 	}); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function uploadFile(uid, uploadedFile, callback) { | function uploadFile(uid, uploadedFile, callback) { | ||||||
| 	if (plugins.hasListeners('filter:uploadFile')) { | 	if (plugins.hasListeners('filter:uploadFile')) { | ||||||
| 		return plugins.fireHook('filter:uploadFile', {file: uploadedFile, uid: uid}, callback); | 		return plugins.fireHook('filter:uploadFile', {file: uploadedFile, uid: uid}, callback); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (parseInt(meta.config.allowFileUploads, 10) !== 1) { |  | ||||||
| 		return callback(new Error('[[error:uploads-are-disabled]]')); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (!uploadedFile) { | 	if (!uploadedFile) { | ||||||
| 		return callback(new Error('[[error:invalid-file]]')); | 		return callback(new Error('[[error:invalid-file]]')); | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user