diff --git a/src/posts.js b/src/posts.js index f732116334..8b295144b0 100644 --- a/src/posts.js +++ b/src/posts.js @@ -421,52 +421,6 @@ var db = require('./database'), }); }; - Posts.uploadPostImage = function(image, callback) { - - if(plugins.hasListeners('filter:uploadImage')) { - plugins.fireHook('filter:uploadImage', image, callback); - } else { - - if (meta.config.allowFileUploads) { - Posts.uploadPostFile(image, callback); - } else { - callback(new Error('Uploads are disabled!')); - } - } - }; - - Posts.uploadPostFile = function(file, callback) { - - if(plugins.hasListeners('filter:uploadFile')) { - plugins.fireHook('filter:uploadFile', file, callback); - } else { - - if(!meta.config.allowFileUploads) { - return callback(new Error('File uploads are not allowed')); - } - - if(!file) { - return callback(new Error('invalid file')); - } - - if(file.size > parseInt(meta.config.maximumFileSize, 10) * 1024) { - return callback(new Error('File too big')); - } - - var filename = 'upload-' + utils.generateUUID() + path.extname(file.name); - require('./file').saveFileToLocal(filename, file.path, function(err, upload) { - if(err) { - return callback(err); - } - - callback(null, { - url: upload.url, - name: file.name - }); - }); - } - }; - Posts.getFavourites = function(uid, start, end, callback) { db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) { if (err) { diff --git a/src/routes/api.js b/src/routes/api.js index 8e35612179..43194ce8cb 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -15,12 +15,19 @@ var path = require('path'), pkg = require('./../../package.json'); +function deleteTempFiles(files) { + for(var i=0; i parseInt(meta.config.maximumFileSize, 10) * 1024) { + return callback(new Error('File too big')); + } + + var filename = 'upload-' + utils.generateUUID() + path.extname(file.name); + require('./file').saveFileToLocal(filename, file.path, function(err, upload) { + if(err) { + return callback(err); + } + + callback(null, { + url: upload.url, + name: file.name + }); + }); + } +} + + function getModerators(req, res, next) { categories.getModerators(req.params.cid, function(err, moderators) { res.json({moderators: moderators}); diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 384689d0ad..3f6b9320d0 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -104,18 +104,6 @@ function favouriteCommand(command, socket, data) { } } -SocketPosts.uploadImage = function(socket, data, callback) { - if(data) { - posts.uploadPostImage(data, callback); - } -}; - -SocketPosts.uploadFile = function(socket, data, callback) { - if(data) { - posts.uploadPostFile(data, callback); - } -}; - SocketPosts.getRawPost = function(socket, pid, callback) { posts.getPostFields(pid, ['content', 'deleted'], function(err, data) { if(err) { diff --git a/src/topics.js b/src/topics.js index bedd5305a8..680d0d2bac 100644 --- a/src/topics.js +++ b/src/topics.js @@ -371,9 +371,9 @@ var async = require('async'), } topic.user = { - username: userData.username || 'Anonymous', - userslug: userData.userslug || '', - picture: userData.picture || gravatar.url('', {}, true) + username: userData.username || 'Anonymous', + userslug: userData.userslug || '', + picture: userData.picture || gravatar.url('', {}, true) }; callback(null, topic); @@ -846,28 +846,6 @@ var async = require('async'), }); }; - Topics.uploadTopicThumb = function(image, callback) { - - if(plugins.hasListeners('filter:uploadImage')) { - plugins.fireHook('filter:uploadImage', image, callback); - } else { - if (meta.config.allowTopicsThumbnail) { - var filename = 'upload-' + utils.generateUUID() + path.extname(image.name); - require('./file').saveFileToLocal(filename, image.path, function(err, upload) { - if(err) { - return callback(err); - } - callback(null, { - url: upload.url, - name: image.name - }); - }); - } else { - callback(new Error('Topic Thumbnails are disabled!')); - } - } - }; - Topics.markAsUnreadForAll = function(tid, callback) { db.delete('tid:' + tid + ':read_by_uid', function(err) { if(err) { @@ -996,31 +974,25 @@ var async = require('async'), }; Topics.increasePostCount = function(tid, callback) { - db.incrObjectField('topic:' + tid, 'postcount', function(err, value) { - if(err) { - return callback(err); - } - db.sortedSetAdd('topics:posts', value, tid, callback); - }); + incrementFieldAndUpdateSortedSet(tid, 'postcount', 1, 'topics:posts', callback); }; Topics.decreasePostCount = function(tid, callback) { - db.decrObjectField('topic:' + tid, 'postcount', function(err, value) { - if(err) { - return callback(err); - } - db.sortedSetAdd('topics:posts', value, tid, callback); - }); + incrementFieldAndUpdateSortedSet(tid, 'postcount', -1, 'topics:posts', callback); }; Topics.increaseViewCount = function(tid, callback) { - db.incrObjectField('topic:' + tid, 'viewcount', function(err, value) { + incrementFieldAndUpdateSortedSet(tid, 'viewcount', 1, 'topics:views', callback); + }; + + function incrementFieldAndUpdateSortedSet(tid, field, by, set, callback) { + db.incrObjectFieldBy('topic:' + tid, field, by, function(err, value) { if(err) { return callback(err); } - db.sortedSetAdd('topics:views', value, tid, callback); + db.sortedSetAdd(set, value, tid, callback); }); - }; + } Topics.isLocked = function(tid, callback) { Topics.getTopicField(tid, 'locked', function(err, locked) {