mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +01:00
wrap lwip.open in try catch, it throws on unknow types, closes #3632
This commit is contained in:
12
src/image.js
12
src/image.js
@@ -17,7 +17,7 @@ image.resizeImage = function(path, extension, width, height, callback) {
|
||||
callback(err);
|
||||
});
|
||||
} else {
|
||||
lwip.open(path, function(err, image) {
|
||||
tryOpen(path, function(err, image) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ image.normalise = function(path, extension, callback) {
|
||||
callback(err);
|
||||
});
|
||||
} else {
|
||||
lwip.open(path, function(err, image) {
|
||||
tryOpen(path, function(err, image) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -50,6 +50,14 @@ image.normalise = function(path, extension, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
function tryOpen(path, callback) {
|
||||
try {
|
||||
lwip.open(path, callback);
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
|
||||
image.convertImageToBase64 = function(path, callback) {
|
||||
fs.readFile(path, function(err, data) {
|
||||
callback(err, data ? data.toString('base64') : null);
|
||||
|
||||
Reference in New Issue
Block a user