|
|
@ -6,74 +6,16 @@ var winston = require('winston');
|
|
|
|
|
|
|
|
|
|
|
|
var db = require('../database');
|
|
|
|
var db = require('../database');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function (Categories) {
|
|
|
|
const intFields = ['cid', 'parentCid', 'disabled', 'isSection', 'order', 'topic_count', 'post_count'];
|
|
|
|
Categories.getCategoryData = function (cid, callback) {
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
db.getObject('category:' + cid, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (category, next) {
|
|
|
|
|
|
|
|
modifyCategory(category);
|
|
|
|
|
|
|
|
next(null, category);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoriesData = function (cids, callback) {
|
|
|
|
|
|
|
|
Categories.getCategoriesFields(cids, [], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function modifyCategory(category) {
|
|
|
|
|
|
|
|
if (!category) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('name')) {
|
|
|
|
|
|
|
|
category.name = validator.escape(String(category.name || ''));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('disabled')) {
|
|
|
|
|
|
|
|
category.disabled = parseInt(category.disabled, 10) === 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('isSection')) {
|
|
|
|
|
|
|
|
category.isSection = parseInt(category.isSection, 10) === 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('icon')) {
|
|
|
|
|
|
|
|
category.icon = category.icon || 'hidden';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('post_count')) {
|
|
|
|
|
|
|
|
category.post_count = category.post_count || 0;
|
|
|
|
|
|
|
|
category.totalPostCount = category.post_count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('topic_count')) {
|
|
|
|
|
|
|
|
category.topic_count = category.topic_count || 0;
|
|
|
|
|
|
|
|
category.totalTopicCount = category.topic_count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.image) {
|
|
|
|
|
|
|
|
category.backgroundImage = category.image;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.description) {
|
|
|
|
|
|
|
|
category.description = validator.escape(String(category.description));
|
|
|
|
|
|
|
|
category.descriptionParsed = category.descriptionParsed || category.description;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoryField = function (cid, field, callback) {
|
|
|
|
|
|
|
|
db.getObjectField('category:' + cid, field, callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function (Categories) {
|
|
|
|
Categories.getCategoriesFields = function (cids, fields, callback) {
|
|
|
|
Categories.getCategoriesFields = function (cids, fields, callback) {
|
|
|
|
if (!Array.isArray(cids) || !cids.length) {
|
|
|
|
if (!Array.isArray(cids) || !cids.length) {
|
|
|
|
return callback(null, []);
|
|
|
|
return callback(null, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var keys = cids.map(function (cid) {
|
|
|
|
var keys = cids.map(cid => 'category:' + cid);
|
|
|
|
return 'category:' + cid;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
if (fields.length) {
|
|
|
|
if (fields.length) {
|
|
|
@ -89,6 +31,28 @@ module.exports = function (Categories) {
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoryData = function (cid, callback) {
|
|
|
|
|
|
|
|
Categories.getCategoriesFields([cid], [], function (err, categories) {
|
|
|
|
|
|
|
|
callback(err, categories && categories.length ? categories[0] : null);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoriesData = function (cids, callback) {
|
|
|
|
|
|
|
|
Categories.getCategoriesFields(cids, [], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoryField = function (cid, field, callback) {
|
|
|
|
|
|
|
|
Categories.getCategoryFields(cid, [field], function (err, category) {
|
|
|
|
|
|
|
|
callback(err, category ? category[field] : null);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoryFields = function (cid, fields, callback) {
|
|
|
|
|
|
|
|
Categories.getCategoriesFields([cid], fields, function (err, categories) {
|
|
|
|
|
|
|
|
callback(err, categories ? categories[0] : null);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getMultipleCategoryFields = function (cids, fields, callback) {
|
|
|
|
Categories.getMultipleCategoryFields = function (cids, fields, callback) {
|
|
|
|
winston.warn('[deprecated] Categories.getMultipleCategoryFields is deprecated please use Categories.getCategoriesFields');
|
|
|
|
winston.warn('[deprecated] Categories.getMultipleCategoryFields is deprecated please use Categories.getCategoriesFields');
|
|
|
|
Categories.getCategoriesFields(cids, fields, callback);
|
|
|
|
Categories.getCategoriesFields(cids, fields, callback);
|
|
|
@ -103,10 +67,6 @@ module.exports = function (Categories) {
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoryFields = function (cid, fields, callback) {
|
|
|
|
|
|
|
|
db.getObjectFields('category:' + cid, fields, callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.setCategoryField = function (cid, field, value, callback) {
|
|
|
|
Categories.setCategoryField = function (cid, field, value, callback) {
|
|
|
|
db.setObjectField('category:' + cid, field, value, callback);
|
|
|
|
db.setObjectField('category:' + cid, field, value, callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -115,3 +75,38 @@ module.exports = function (Categories) {
|
|
|
|
db.incrObjectFieldBy('category:' + cid, field, value, callback);
|
|
|
|
db.incrObjectFieldBy('category:' + cid, field, value, callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function modifyCategory(category) {
|
|
|
|
|
|
|
|
if (!category) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
intFields.forEach(field => db.parseIntField(category, field));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('name')) {
|
|
|
|
|
|
|
|
category.name = validator.escape(String(category.name || ''));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('icon')) {
|
|
|
|
|
|
|
|
category.icon = category.icon || 'hidden';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('post_count')) {
|
|
|
|
|
|
|
|
category.post_count = category.post_count || 0;
|
|
|
|
|
|
|
|
category.totalPostCount = category.post_count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.hasOwnProperty('topic_count')) {
|
|
|
|
|
|
|
|
category.topic_count = category.topic_count || 0;
|
|
|
|
|
|
|
|
category.totalTopicCount = category.topic_count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.image) {
|
|
|
|
|
|
|
|
category.backgroundImage = category.image;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (category.description) {
|
|
|
|
|
|
|
|
category.description = validator.escape(String(category.description));
|
|
|
|
|
|
|
|
category.descriptionParsed = category.descriptionParsed || category.description;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|