|
|
|
@ -410,33 +410,38 @@ var db = require('./database'),
|
|
|
|
|
|
|
|
|
|
Posts.uploadPostFile = function(file, callback) {
|
|
|
|
|
|
|
|
|
|
if(!meta.config.allowFileUploads) {
|
|
|
|
|
return callback(new Error('File uploads are not allowed'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!file || !file.data) {
|
|
|
|
|
return callback(new Error('invalid file'));
|
|
|
|
|
}
|
|
|
|
|
if(plugins.hasListeners('filter:post.uploadFile')) {
|
|
|
|
|
plugins.fireHook('filter:post.uploadFile', file, callback);
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
var buffer = new Buffer(file.data, 'base64');
|
|
|
|
|
if(!meta.config.allowFileUploads) {
|
|
|
|
|
return callback(new Error('File uploads are not allowed'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(buffer.length > parseInt(meta.config.maximumFileSize, 10) * 1024) {
|
|
|
|
|
return callback(new Error('File too big'));
|
|
|
|
|
}
|
|
|
|
|
if(!file || !file.data) {
|
|
|
|
|
return callback(new Error('invalid file'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filename = 'upload-' + utils.generateUUID() + path.extname(file.name);
|
|
|
|
|
var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename);
|
|
|
|
|
var buffer = new Buffer(file.data, 'base64');
|
|
|
|
|
|
|
|
|
|
fs.writeFile(uploadPath, buffer, function (err) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
if(buffer.length > parseInt(meta.config.maximumFileSize, 10) * 1024) {
|
|
|
|
|
return callback(new Error('File too big'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, {
|
|
|
|
|
url: nconf.get('upload_url') + filename,
|
|
|
|
|
name: file.name
|
|
|
|
|
var filename = 'upload-' + utils.generateUUID() + path.extname(file.name);
|
|
|
|
|
var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename);
|
|
|
|
|
|
|
|
|
|
fs.writeFile(uploadPath, buffer, function (err) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, {
|
|
|
|
|
url: nconf.get('upload_url') + filename,
|
|
|
|
|
name: file.name
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Posts.reIndexPids = function(pids, callback) {
|
|
|
|
|