meta config changes, refactors

v1.18.x
Baris Usakli 12 years ago
parent caa057ff4d
commit c647793512

@ -19,7 +19,8 @@
var fs = require('fs'),
winston = require('winston'),
pkg = require('./package.json'),
url = require('url');
url = require('url'),
meta = require('./src/meta.js');
nconf = require('nconf');
// Runtime environment
@ -49,25 +50,20 @@ winston.info('This program comes with ABSOLUTELY NO WARRANTY.');
winston.info('This is free software, and you are welcome to redistribute it under certain conditions.');
winston.info('===');
if(nconf.get('upgrade')) {
require('./src/upgrade').upgrade();
meta.configs.init(function() {
require('./src/upgrade').upgrade();
});
} else if (!nconf.get('setup') && nconf.get('base_url')) {
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/');
nconf.set('upload_url', nconf.get('url') + 'uploads/');
winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using Redis store at ' + nconf.get('redis:host') + ':' + nconf.get('redis:port') + '.');
winston.info('Base Configuration OK.');
// TODO: Replace this with nconf-redis
var meta = require('./src/meta.js');
global.config = {};
meta.config.get(function(config) {
for(c in config) {
if (config.hasOwnProperty(c)) {
global.config[c] = config[c];
}
}
meta.configs.init(function() {
var categories = require('./src/categories.js'),
templates = require('./public/src/templates.js'),
@ -127,6 +123,7 @@ if(nconf.get('upgrade')) {
setup_categories();
}(global.configuration));
});
} else {
// New install, ask setup questions
if (nconf.get('setup')) winston.info('NodeBB Setup Triggered via Command Line');

@ -85,10 +85,10 @@ var async = require('async'),
server_conf.base_url = protocol + '//' + host;
server_conf.relative_path = relative_path;
meta.config.set('postDelay', 10000);
meta.config.set('minimumPostLength', 8);
meta.config.set('minimumTitleLength', 3);
meta.config.set('imgurClientID', '');
meta.configs.set('postDelay', 10000);
meta.configs.set('minimumPostLength', 8);
meta.configs.set('minimumTitleLength', 3);
meta.configs.set('imgurClientID', '');
install.save(server_conf, client_conf, callback);
});

@ -25,13 +25,17 @@ var user = require('./user.js'),
});
}
user.getUserFields(uid, ['password', 'banned'], function(userData) {
user.getUserFields(uid, ['password', 'banned'], function(err, userData) {
if(err)
return next(err);
if(userData.banned && userData.banned === '1') {
return next({
status: "error",
message: "user-banned"
});
}
bcrypt.compare(password, userData.password, function(err, res) {
if(err) {
winston.err(err);

@ -5,7 +5,14 @@ var utils = require('./../public/src/utils.js'),
fs = require('fs');
(function(Meta) {
Meta.config = {
Meta.configs = {
init: function(callback) {
Meta.configs.get(function(config) {
Meta.config = config;
callback();
});
},
get: function(callback) {
RDB.hgetall('config', function(err, config) {
if (!err) {
@ -80,8 +87,8 @@ var utils = require('./../public/src/utils.js'),
}, function(err, values) {
var title;
if (err) title = global.config.title || 'NodeBB';
else title = (values.title ? values.title + ' | ' : '') + (global.config.title || 'NodeBB');
if (err) title = Meta.config.title || 'NodeBB';
else title = (values.title ? values.title + ' | ' : '') + (Meta.config.title || 'NodeBB');
callback(null, title, values.notifCount);
});
@ -110,4 +117,6 @@ var utils = require('./../public/src/utils.js'),
} else callback(null);
}
}
}(exports));

@ -10,7 +10,8 @@ var RDB = require('./redis.js'),
reds = require('reds'),
postSearch = reds.createSearch('nodebbpostsearch'),
topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston');
winston = require('winston'),
meta = require('./meta.js');
(function(PostTools) {
PostTools.isMain = function(pid, tid, callback) {
@ -41,7 +42,7 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) {
user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= global.config['privileges:manage_content']);
next(null, reputation >= meta.config['privileges:manage_content']);
});
}

@ -11,6 +11,7 @@ var RDB = require('./redis.js'),
plugins = require('./plugins'),
reds = require('reds'),
nconf = require('nconf'),
meta = require('./meta.js'),
postSearch = reds.createSearch('nodebbpostsearch'),
winston = require('winston');
@ -32,7 +33,9 @@ var RDB = require('./redis.js'),
}
Posts.addUserInfoToPost = function(post, callback) {
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(userData) {
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(err, userData) {
if(err)
return callback();
post.username = userData.username || 'anonymous';
post.userslug = userData.userslug || '';
@ -43,7 +46,9 @@ var RDB = require('./redis.js'),
post.signature = postTools.markdownToHTML(userData.signature, true);
if(post.editor !== '') {
user.getUserFields(post.editor, ['username', 'userslug'], function(editorData) {
user.getUserFields(post.editor, ['username', 'userslug'], function(err, editorData) {
if(err)
return callback();
post.editorname = editorData.username;
post.editorslug = editorData.userslug;
callback();
@ -146,7 +151,12 @@ var RDB = require('./redis.js'),
postData.content = postTools.markdownToHTML(postData.content);
if(postData.uploadedImages) {
postData.uploadedImages = JSON.parse(postData.uploadedImages);
try {
postData.uploadedImages = JSON.parse(postData.uploadedImages);
} catch(err) {
postData.uploadedImages = [];
winston.err(err);
}
} else {
postData.uploadedImages = [];
}
@ -184,7 +194,7 @@ var RDB = require('./redis.js'),
type: 'error',
timeout: 2000,
title: 'Content too short',
message: "Please enter a longer post. At least " + config.minimumPostLength + " characters.",
message: "Please enter a longer post. At least " + meta.config.minimumPostLength + " characters.",
alert_id: 'post_error'
});
}
@ -192,7 +202,7 @@ var RDB = require('./redis.js'),
Posts.emitTooManyPostsAlert = function(socket) {
socket.emit('event:alert', {
title: 'Too many posts!',
message: 'You can only post every '+ config.postDelay/1000 + ' seconds.',
message: 'You can only post every '+ meta.config.postDelay/1000 + ' seconds.',
type: 'error',
timeout: 2000
});
@ -203,13 +213,13 @@ var RDB = require('./redis.js'),
content = content.trim();
}
if (!content || content.length < config.minimumPostLength) {
if (!content || content.length < meta.config.minimumPostLength) {
callback(new Error('content-too-short'), null);
return;
}
user.getUserField(uid, 'lastposttime', function(lastposttime) {
if(Date.now() - lastposttime < config.postDelay) {
if(Date.now() - lastposttime < meta.config.postDelay) {
callback(new Error('too-many-posts'), null);
return;
}
@ -264,7 +274,7 @@ var RDB = require('./redis.js'),
'editor': '',
'edited': 0,
'deleted': 0,
'uploadedImages': [],
'uploadedImages': '[]',
'fav_button_class': '',
'fav_star_class': 'icon-star-empty',
'show_banned': 'hide',
@ -310,7 +320,6 @@ var RDB = require('./redis.js'),
next(null, []);
} else {
next(null, uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
}
});
},
@ -321,6 +330,7 @@ var RDB = require('./redis.js'),
}
}, function(err, results) {
postData.uploadedImages = results.uploadedImages;
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(postData.uploadedImages));
postData.content = results.content;
callback(postData);
});
@ -338,7 +348,7 @@ var RDB = require('./redis.js'),
function uploadPostImages(postData, images, callback) {
var imgur = require('./imgur');
imgur.setClientID(config.imgurClientID);
imgur.setClientID(meta.config.imgurClientID);
var uploadedImages = [];

@ -16,19 +16,14 @@ var user = require('./../user.js'),
});
app.get('/api/config', function(req, res, next) {
meta.config.getFields(['postDelay', 'minimumTitleLength', 'minimumPostLength', 'imgurClientID'], function(err, metaConfig) {
if(err) return next();
var clientConfig = require('../../public/config.json');
var config = require('../../public/config.json');
for (var attrname in metaConfig) {
clientConfig[attrname] = metaConfig[attrname];
}
clientConfig['imgurClientIDSet'] = !!clientConfig['imgurClientID'];
delete clientConfig['imgurClientID'];
config['postDelay'] = meta.config['postDelay'];
config['minimumTitleLength'] = meta.config['minimumTitleLength'];
config['minimumPostLength'] = meta.config['minimumPostLength'];
config['imgurClientIDSet'] = !!meta.config['imgurClientID'];
res.json(200, clientConfig);
})
res.json(200, config);
});
app.get('/api/home', function(req, res) {
@ -48,8 +43,8 @@ var user = require('./../user.js'),
}
require('async').each(data.categories, iterator, function(err) {
data.motd_class = (config.show_motd === '1' || config.show_motd === undefined) ? '' : 'none';
data.motd = marked(config.motd || "# NodeBB <span class='hidden-phone'>v " + pkg.version + "</span>\nWelcome to NodeBB, the discussion platform of the future.\n\n<a target=\"_blank\" href=\"http://www.nodebb.org\" class=\"btn btn-large\"><i class=\"icon-comment\"></i><span class='hidden-phone'>&nbsp;Get NodeBB</span></a> <a target=\"_blank\" href=\"https://github.com/designcreateplay/NodeBB\" class=\"btn btn-large\"><i class=\"icon-github-alt\"></i><span class='hidden-phone'>&nbsp;Fork us on Github</span></a> <a target=\"_blank\" href=\"https://twitter.com/dcplabs\" class=\"btn btn-large\"><i class=\"icon-twitter\"></i><span class='hidden-phone'>&nbsp;@dcplabs</span></a>");
data.motd_class = (meta.config.show_motd === '1' || meta.config.show_motd === undefined) ? '' : 'none';
data.motd = marked(meta.config.motd || "# NodeBB <span class='hidden-phone'>v " + pkg.version + "</span>\nWelcome to NodeBB, the discussion platform of the future.\n\n<a target=\"_blank\" href=\"http://www.nodebb.org\" class=\"btn btn-large\"><i class=\"icon-comment\"></i><span class='hidden-phone'>&nbsp;Get NodeBB</span></a> <a target=\"_blank\" href=\"https://github.com/designcreateplay/NodeBB\" class=\"btn btn-large\"><i class=\"icon-github-alt\"></i><span class='hidden-phone'>&nbsp;Fork us on Github</span></a> <a target=\"_blank\" href=\"https://twitter.com/dcplabs\" class=\"btn btn-large\"><i class=\"icon-twitter\"></i><span class='hidden-phone'>&nbsp;@dcplabs</span></a>");
res.json(data);
});

@ -6,6 +6,7 @@
passportFacebook = require('passport-facebook').Strategy,
login_strategies = [],
nconf = require('nconf'),
meta = require('../meta'),
user = require('../user'),
winston = require('winston'),
login_module = require('./../login.js');
@ -17,10 +18,10 @@
});
}));
if (global.config['social:twitter:key'] && global.config['social:twitter:secret']) {
if (meta.config['social:twitter:key'] && meta.config['social:twitter:secret']) {
passport.use(new passportTwitter({
consumerKey: global.config['social:twitter:key'],
consumerSecret: global.config['social:twitter:secret'],
consumerKey: meta.config['social:twitter:key'],
consumerSecret: meta.config['social:twitter:secret'],
callbackURL: nconf.get('url') + 'auth/twitter/callback'
}, function(token, tokenSecret, profile, done) {
login_module.loginViaTwitter(profile.id, profile.username, profile.photos, function(err, user) {
@ -32,10 +33,10 @@
login_strategies.push('twitter');
}
if (global.config['social:google:id'] && global.config['social:google:secret']) {
if (meta.config['social:google:id'] && meta.config['social:google:secret']) {
passport.use(new passportGoogle({
clientID: global.config['social:google:id'],
clientSecret: global.config['social:google:secret'],
clientID: meta.config['social:google:id'],
clientSecret: meta.config['social:google:secret'],
callbackURL: nconf.get('url') + 'auth/google/callback'
}, function(accessToken, refreshToken, profile, done) {
login_module.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
@ -47,10 +48,10 @@
login_strategies.push('google');
}
if (global.config['social:facebook:app_id'] && global.config['social:facebook:secret']) {
if (meta.config['social:facebook:app_id'] && meta.config['social:facebook:secret']) {
passport.use(new passportFacebook({
clientID: global.config['social:facebook:app_id'],
clientSecret: global.config['social:facebook:secret'],
clientID: meta.config['social:facebook:app_id'],
clientSecret: meta.config['social:facebook:secret'],
callbackURL: nconf.get('url') + 'auth/facebook/callback'
}, function(accessToken, refreshToken, profile, done) {
login_module.loginViaFacebook(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {

@ -281,7 +281,7 @@ var user = require('./../user.js'),
});
});
app.get('/api/users/:userslug/settings', function(req, res) {
app.get('/api/users/:userslug/settings', function(req, res, next) {
var callerUID = req.user ? req.user.uid : 0;
user.get_uid_by_userslug(req.params.userslug, function(uid) {
@ -294,7 +294,10 @@ var user = require('./../user.js'),
res.json(403, { error: 'Not allowed!' });
return;
}
user.getUserFields(uid, ['username','userslug','showemail'], function(userData) {
user.getUserFields(uid, ['username','userslug','showemail'], function(err, userData) {
if(err)
return next(err);
if(userData) {
if(userData.showemail && userData.showemail === "1")
userData.showemail = "checked";
@ -322,7 +325,10 @@ var user = require('./../user.js'),
return;
}
user.getUserFields(uid, ['username','userslug'], function(userData) {
user.getUserFields(uid, ['username','userslug'], function(err, userData) {
if(err)
return next(err);
if(userData) {
posts.getFavourites(uid, function(err, posts) {
if(err)

@ -7,7 +7,8 @@ var RDB = require('./redis.js'),
posts = require('./posts'),
reds = require('reds'),
topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston');
winston = require('winston'),
meta = require('./meta');
(function(ThreadTools) {
@ -31,7 +32,7 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) {
user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= global.config['privileges:manage_topic']);
next(null, reputation >= meta.config['privileges:manage_topic']);
});
}
@ -110,12 +111,12 @@ var RDB = require('./redis.js'),
topics.setTopicField(tid, 'deleted', 0);
ThreadTools.unlock(tid, uid);
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
tid: tid,
status: 'ok'
});
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
tid: tid,
status: 'ok'
});
if (socket) {
socket.emit('api:topic.restore', {
status: 'ok',
tid: tid
@ -187,7 +188,7 @@ var RDB = require('./redis.js'),
multi.exec(function(err, result) {
if (!err && result === 1) {
if (!err && result[0] === 1 && result[1] === 1) {
topics.setTopicField(tid, 'cid', cid);

@ -211,9 +211,7 @@ marked.setOptions({
function getTopicInfo(topicData, callback) {
function getUserInfo(next) {
user.getUserFields(topicData.uid, ['username'], function(userData) {
next(null, userData);
});
user.getUserFields(topicData.uid, ['username'], next);
}
function hasReadTopic(next) {
@ -520,7 +518,10 @@ marked.setOptions({
if (!err) {
posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(postData) {
user.getUserFields(postData.uid, ['username', 'picture'], function(userData) {
user.getUserFields(postData.uid, ['username', 'picture'], function(err, userData) {
if(err)
return callback(err, null);
var stripped = postData.content,
timestamp = postData.timestamp;
@ -546,7 +547,7 @@ marked.setOptions({
type: 'error',
timeout: 2000,
title: 'Title too short',
message: "Please enter a longer title. At least " + config.minimumTitleLength + " characters.",
message: "Please enter a longer title. At least " + meta.config.minimumTitleLength + " characters.",
alert_id: 'post_error'
});
}
@ -563,17 +564,17 @@ marked.setOptions({
if (uid === 0) {
callback(new Error('not-logged-in'), null);
return;
} else if(!title || title.length < config.minimumTitleLength) {
} else if(!title || title.length < meta.config.minimumTitleLength) {
callback(new Error('title-too-short'), null);
return;
} else if (!content || content.length < config.miminumPostLength) {
} else if (!content || content.length < meta.config.miminumPostLength) {
callback(new Error('content-too-short'), null);
return;
}
user.getUserField(uid, 'lastposttime', function(lastposttime) {
if(Date.now() - lastposttime < config.postDelay) {
if(Date.now() - lastposttime < meta.config.postDelay) {
callback(new Error('too-many-posts'), null);
return;
}

@ -1,6 +1,7 @@
var RDB = require('./redis.js'),
async = require('async'),
winston = require('winston');
winston = require('winston'),
user = require('./user');
function upgradeCategory(cid, callback) {
@ -36,7 +37,7 @@ function upgradeCategory(cid, callback) {
}
function upgradeUser(uid, callback) {
RDB.hmgetObject('user:' + uid, ['joindate', 'postcount', 'reputation'], function(err, userData) {
user.getUserFields(uid, ['joindate', 'postcount', 'reputation'], function(err, userData) {
if(err)
return callback(err);
@ -46,7 +47,6 @@ function upgradeUser(uid, callback) {
callback(null);
});
}
exports.upgrade = function() {

@ -2,7 +2,8 @@ var utils = require('./../public/src/utils.js'),
RDB = require('./redis.js'),
crypto = require('crypto'),
emailjs = require('emailjs'),
emailjsServer = emailjs.server.connect(config.mailer),
meta = require('./meta.js'),
emailjsServer = emailjs.server.connect(meta.config.mailer),
bcrypt = require('bcrypt'),
marked = require('marked'),
notifications = require('./notifications.js'),
@ -148,13 +149,7 @@ var utils = require('./../public/src/utils.js'),
}
User.getUserFields = function(uid, fields, callback) {
RDB.hmgetObject('user:' + uid, fields, function(err, data) {
if(err === null) {
callback(data);
} else {
console.log(err);
}
});
RDB.hmgetObject('user:' + uid, fields, callback);
}
User.getMultipleUserFields = function(uids, fields, callback) {
@ -170,7 +165,9 @@ var utils = require('./../public/src/utils.js'),
});
function iterator(uid, callback) {
User.getUserFields(uid, fields, function(userData) {
User.getUserFields(uid, fields, function(err, userData) {
if(err)
return callback(err);
returnData.push(userData);
callback(null);
});
@ -261,7 +258,10 @@ var utils = require('./../public/src/utils.js'),
if(field === 'email') {
var gravatarpicture = User.createGravatarURLFromEmail(data[field]);
User.setUserField(uid, 'gravatarpicture', gravatarpicture);
User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(userData) {
User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(err, userData) {
if(err)
return callback(err);
RDB.del('email:' + userData['email'] + ':uid');
RDB.set('email:' + data['email'] + ':uid', uid);
User.setUserField(uid, field, data[field]);
@ -385,7 +385,7 @@ var utils = require('./../public/src/utils.js'),
return;
}
bcrypt.genSalt(config.bcrypt_rounds, function(err, salt) {
bcrypt.genSalt(nconf.get('bcrypt_rounds'), function(err, salt) {
bcrypt.hash(password, salt, function(err, hash) {
callback(hash);
});
@ -450,9 +450,9 @@ var utils = require('./../public/src/utils.js'),
}
User.sendConfirmationEmail = function (email) {
if (global.config['email:host'] && global.config['email:port'] && global.config['email:from']) {
if (meta.config['email:host'] && meta.config['email:port'] && meta.config['email:from']) {
var confirm_code = utils.generateUUID(),
confirm_link = config.url + 'confirm/' + confirm_code,
confirm_link = nconf.get('url') + 'confirm/' + confirm_code,
confirm_email = global.templates['emails/header'] + global.templates['emails/email_confirm'].parse({'CONFIRM_LINK': confirm_link}) + global.templates['emails/footer'],
confirm_email_plaintext = global.templates['emails/email_confirm_plaintext'].parse({ 'CONFIRM_LINK': confirm_link });
@ -466,10 +466,10 @@ var utils = require('./../public/src/utils.js'),
RDB.set(confirm_key, email);
RDB.expire(confirm_key, expiry_time);
// Send intro email w/ confirm code
// Send intro email w/ confirm code
var message = emailjs.message.create({
text: confirm_email_plaintext,
from: config.mailer.from,
from: meta.config.mailer.from,
to: email,
subject: '[NodeBB] Registration Email Verification',
attachment: [
@ -625,8 +625,9 @@ var utils = require('./../public/src/utils.js'),
RDB.zrevrange('users:joindate', 0, 0, function(err, uid) {
RDB.handle(err);
User.getUserFields(uid, ['username', 'userslug'], function(userData) {
socket.emit('user.latest', {userslug: userData.userslug, username: userData.username});
User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
if(!err && userData)
socket.emit('user.latest', {userslug: userData.userslug, username: userData.username});
});
});
}
@ -848,7 +849,7 @@ var utils = require('./../public/src/utils.js'),
var message = emailjs.message.create({
text: reset_email_plaintext,
from: config.mailer?config.mailer.from:'localhost@example.org',
from: meta.config.mailer?meta.config.mailer.from:'localhost@example.org',
to: email,
subject: 'Password Reset Requested',
attachment: [

@ -36,13 +36,13 @@ var express = require('express'),
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' },
{ name: 'content-type', content: 'text/html; charset=UTF-8' },
{ name: 'apple-mobile-web-app-capable', content: 'yes' },
{ property: 'og:site_name', content: global.config.title || 'NodeBB' },
{ property: 'og:site_name', content: meta.config.title || 'NodeBB' },
],
metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
templateValues = {
cssSrc: global.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
title: global.config['title'] || 'NodeBB',
browserTitle: global.config['title'] || 'NodeBB',
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
title: meta.config['title'] || 'NodeBB',
browserTitle: meta.config['title'] || 'NodeBB',
csrf: options.res.locals.csrf_token,
relative_path: nconf.get('relative_path'),
meta_tags: metaString
@ -183,9 +183,9 @@ var express = require('express'),
req: req,
res: res,
metaTags: [
{ name: "title", content: global.config.title || 'NodeBB' },
{ name: "description", content: global.config.description || '' },
{ property: 'og:title', content: 'Index | ' + (global.config.title || 'NodeBB') },
{ name: "title", content: meta.config.title || 'NodeBB' },
{ name: "description", content: meta.config.description || '' },
{ property: 'og:title', content: 'Index | ' + (meta.config.title || 'NodeBB') },
{ property: "og:type", content: 'website' }
]
}, next);
@ -241,7 +241,7 @@ var express = require('express'),
res: res,
metaTags: [
{ name: "title", content: topicData.topic_name },
{ property: 'og:title', content: topicData.topic_name + ' | ' + (global.config.title || 'NodeBB') },
{ property: 'og:title', content: topicData.topic_name + ' | ' + (meta.config.title || 'NodeBB') },
{ property: "og:type", content: 'article' },
{ property: "og:url", content: nconf.get('url') + 'topic/' + topicData.slug },
{ property: 'og:image', content: topicData.main_posts[0].picture },

@ -177,9 +177,11 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
socket.on('api:updateHeader', function(data) {
if(uid) {
user.getUserFields(uid, data.fields, function(fields) {
fields.uid = uid;
socket.emit('api:updateHeader', fields);
user.getUserFields(uid, data.fields, function(err, fields) {
if(!err && fields) {
fields.uid = uid;
socket.emit('api:updateHeader', fields);
}
});
}
else {
@ -261,10 +263,14 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
var type = data.type;
function updateHeader() {
user.getUserFields(uid, ['picture'], function(fields) {
fields.uid = uid;
socket.emit('api:updateHeader', fields);
callback(true);
user.getUserFields(uid, ['picture'], function(err, fields) {
if(!err && fields) {
fields.uid = uid;
socket.emit('api:updateHeader', fields);
callback(true);
} else {
callback(false);
}
});
}
@ -525,19 +531,19 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:config.get', function(data) {
meta.config.get(function(config) {
meta.configs.get(function(config) {
socket.emit('api:config.get', config);
});
});
socket.on('api:config.set', function(data) {
meta.config.set(data.key, data.value, function(err) {
meta.configs.set(data.key, data.value, function(err) {
if (!err) socket.emit('api:config.set', { status: 'ok' });
});
});
socket.on('api:config.remove', function(key) {
meta.config.remove(key);
meta.configs.remove(key);
});
socket.on('api:composer.push', function(data) {
@ -555,14 +561,16 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
});
} else if (parseInt(data.cid) > 0) {
user.getUserFields(uid, ['username', 'picture'], function(userData) {
socket.emit('api:composer.push', {
tid: 0,
cid: data.cid,
username: userData.username,
picture: userData.picture,
title: undefined
});
user.getUserFields(uid, ['username', 'picture'], function(err, userData) {
if(!err && userData) {
socket.emit('api:composer.push', {
tid: 0,
cid: data.cid,
username: userData.username,
picture: userData.picture,
title: undefined
});
}
});
} else if (parseInt(data.pid) > 0) {
async.parallel([

Loading…
Cancel
Save