mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +01:00
25
src/image.js
25
src/image.js
@@ -139,3 +139,28 @@ image.writeImageDataToTempFile = function (imageData, callback) {
|
||||
image.sizeFromBase64 = function (imageData) {
|
||||
return Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64').length;
|
||||
};
|
||||
|
||||
image.uploadImage = function (filename, folder, image, callback) {
|
||||
if (plugins.hasListeners('filter:uploadImage')) {
|
||||
return plugins.fireHook('filter:uploadImage', {
|
||||
image: image,
|
||||
uid: image.uid,
|
||||
}, callback);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
file.isFileTypeAllowed(image.path, next);
|
||||
},
|
||||
function (next) {
|
||||
file.saveFileToLocal(filename, folder, image.path, next);
|
||||
},
|
||||
function (upload, next) {
|
||||
next(null, {
|
||||
url: upload.url,
|
||||
path: upload.path,
|
||||
name: image.name,
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user