mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
hinting
This commit is contained in:
18
src/feed.js
18
src/feed.js
@@ -1,4 +1,4 @@
|
|||||||
(function(Feed) {
|
(function (Feed) {
|
||||||
var RDB = require('./redis.js'),
|
var RDB = require('./redis.js'),
|
||||||
schema = require('./schema.js'),
|
schema = require('./schema.js'),
|
||||||
posts = require('./posts.js'),
|
posts = require('./posts.js'),
|
||||||
@@ -15,20 +15,20 @@
|
|||||||
baseUrl: nconf.get('url') + 'feeds'
|
baseUrl: nconf.get('url') + 'feeds'
|
||||||
};
|
};
|
||||||
|
|
||||||
Feed.saveFeed = function(location, feed, callback) {
|
Feed.saveFeed = function (location, feed, callback) {
|
||||||
var savePath = path.join(__dirname, '../', location);
|
var savePath = path.join(__dirname, '../', location);
|
||||||
|
|
||||||
fs.writeFile(savePath, feed.xml(), function(err) {
|
fs.writeFile(savePath, feed.xml(), function (err) {
|
||||||
if (err) return winston.err(err);
|
if (err) return winston.err(err);
|
||||||
|
|
||||||
if (callback) callback(err);
|
if (callback) callback(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed.updateTopic = function(tid, callback) {
|
Feed.updateTopic = function (tid, callback) {
|
||||||
if (process.env.NODE_ENV === 'development') winston.info('[rss] Updating RSS feeds for topic ' + tid);
|
if (process.env.NODE_ENV === 'development') winston.info('[rss] Updating RSS feeds for topic ' + tid);
|
||||||
|
|
||||||
topics.getTopicWithPosts(tid, 0, 0, -1, function(err, topicData) {
|
topics.getTopicWithPosts(tid, 0, 0, -1, function (err, topicData) {
|
||||||
if (err) return callback(new Error('topic-invalid'));
|
if (err) return callback(new Error('topic-invalid'));
|
||||||
|
|
||||||
var feed = new rss({
|
var feed = new rss({
|
||||||
@@ -62,16 +62,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed.saveFeed('feeds/topics/' + tid + '.rss', feed, function(err) {
|
Feed.saveFeed('feeds/topics/' + tid + '.rss', feed, function (err) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Feed.updateCategory = function(cid, callback) {
|
Feed.updateCategory = function (cid, callback) {
|
||||||
if (process.env.NODE_ENV === 'development') winston.info('[rss] Updating RSS feeds for category ' + cid);
|
if (process.env.NODE_ENV === 'development') winston.info('[rss] Updating RSS feeds for category ' + cid);
|
||||||
categories.getCategoryById(cid, 0, function(err, categoryData) {
|
categories.getCategoryById(cid, 0, function (err, categoryData) {
|
||||||
if (err) return callback(new Error('category-invalid'));
|
if (err) return callback(new Error('category-invalid'));
|
||||||
|
|
||||||
var feed = new rss({
|
var feed = new rss({
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed.saveFeed('feeds/categories/' + cid + '.rss', feed, function(err) {
|
Feed.saveFeed('feeds/categories/' + cid + '.rss', feed, function (err) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
204
src/groups.js
204
src/groups.js
@@ -1,95 +1,117 @@
|
|||||||
var async = require('async'),
|
(function () {
|
||||||
User = require('./user'),
|
"use strict";
|
||||||
RDB = RDB || require('./redis'),
|
|
||||||
Groups = {
|
|
||||||
list: function(options, callback) {
|
|
||||||
RDB.hvals('group:gid', function(err, gids) {
|
|
||||||
if (gids.length > 0) {
|
|
||||||
async.map(gids, function(gid, next) {
|
|
||||||
Groups.get(gid, {
|
|
||||||
expand: options.expand
|
|
||||||
}, next);
|
|
||||||
}, function(err, groups) {
|
|
||||||
callback(err, groups.filter(function(group) {
|
|
||||||
if (group.deleted === '1') return false;
|
|
||||||
else return true;
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
} else callback(null, []);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
get: function(gid, options, callback) {
|
|
||||||
async.parallel({
|
|
||||||
base: function(next) {
|
|
||||||
RDB.hgetall('gid:' + gid, next);
|
|
||||||
},
|
|
||||||
users: function(next) {
|
|
||||||
RDB.smembers('gid:' + gid + ':members', function(err, uids) {
|
|
||||||
if (options.expand) {
|
|
||||||
if (err) return next(err);
|
|
||||||
|
|
||||||
async.map(uids, function(uid, next) {
|
var async = require('async'),
|
||||||
User.getUserData(uid, next);
|
User = require('./user'),
|
||||||
}, function(err, users) {
|
RDB = RDB || require('./redis'),
|
||||||
next(err, users);
|
Groups = {
|
||||||
});
|
list: function (options, callback) {
|
||||||
} else next(err, uids);
|
RDB.hvals('group:gid', function (err, gids) {
|
||||||
});
|
if (gids.length > 0) {
|
||||||
|
async.map(gids, function (gid, next) {
|
||||||
|
Groups.get(gid, {
|
||||||
|
expand: options.expand
|
||||||
|
}, next);
|
||||||
|
}, function (err, groups) {
|
||||||
|
callback(err, groups.filter(function (group) {
|
||||||
|
if (group.deleted === '1') {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(null, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
get: function (gid, options, callback) {
|
||||||
|
async.parallel({
|
||||||
|
base: function (next) {
|
||||||
|
RDB.hgetall('gid:' + gid, next);
|
||||||
|
},
|
||||||
|
users: function (next) {
|
||||||
|
RDB.smembers('gid:' + gid + ':members', function (err, uids) {
|
||||||
|
if (options.expand) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.map(uids, function (uid, next) {
|
||||||
|
User.getUserData(uid, next);
|
||||||
|
}, function (err, users) {
|
||||||
|
next(err, users);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
next(err, uids);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, function (err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
results.base.count = results.users.length;
|
||||||
|
results.base.members = results.users;
|
||||||
|
|
||||||
|
callback(err, results.base);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getGidFromName: function (name, callback) {
|
||||||
|
RDB.hget('group:gid', name, callback);
|
||||||
|
},
|
||||||
|
isMember: function (uid, gid, callback) {
|
||||||
|
RDB.sismember('gid:' + gid + ':members', uid, callback);
|
||||||
|
},
|
||||||
|
exists: function (name, callback) {
|
||||||
|
RDB.hexists('group:gid', name, callback);
|
||||||
|
},
|
||||||
|
create: function (name, description, callback) {
|
||||||
|
if (name.length === 0) {
|
||||||
|
return callback(new Error('name-too-short'));
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
|
||||||
if (err) return callback(err);
|
|
||||||
|
|
||||||
results.base.count = results.users.length;
|
Groups.exists(name, function (err, exists) {
|
||||||
results.base.members = results.users;
|
if (!exists) {
|
||||||
|
RDB.incr('next_gid', function (err, gid) {
|
||||||
|
RDB.multi()
|
||||||
|
.hset('group:gid', name, gid)
|
||||||
|
.hmset('gid:' + gid, {
|
||||||
|
gid: gid,
|
||||||
|
name: name,
|
||||||
|
description: description,
|
||||||
|
deleted: '0'
|
||||||
|
})
|
||||||
|
.exec(function (err) {
|
||||||
|
Groups.get(gid, {}, callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(new Error('group-exists'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
update: function (gid, values, callback) {
|
||||||
|
RDB.exists('gid:' + gid, function (err, exists) {
|
||||||
|
if (!err && exists) {
|
||||||
|
RDB.hmset('gid:' + gid, values, callback);
|
||||||
|
} else {
|
||||||
|
callback(new Error('gid-not-found'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
destroy: function (gid, callback) {
|
||||||
|
RDB.hset('gid:' + gid, 'deleted', '1', callback);
|
||||||
|
},
|
||||||
|
join: function (gid, uid, callback) {
|
||||||
|
RDB.sadd('gid:' + gid + ':members', uid, callback);
|
||||||
|
},
|
||||||
|
leave: function (gid, uid, callback) {
|
||||||
|
RDB.srem('gid:' + gid + ':members', uid, callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
callback(err, results.base);
|
module.exports = Groups;
|
||||||
});
|
}());
|
||||||
},
|
|
||||||
getGidFromName: function(name, callback) {
|
|
||||||
RDB.hget('group:gid', name, callback);
|
|
||||||
},
|
|
||||||
isMember: function(uid, gid, callback) {
|
|
||||||
RDB.sismember('gid:' + gid + ':members', uid, callback);
|
|
||||||
},
|
|
||||||
exists: function(name, callback) {
|
|
||||||
RDB.hexists('group:gid', name, callback);
|
|
||||||
},
|
|
||||||
create: function(name, description, callback) {
|
|
||||||
if (name.length === 0) return callback(new Error('name-too-short'));
|
|
||||||
|
|
||||||
Groups.exists(name, function(err, exists) {
|
|
||||||
if (!exists) {
|
|
||||||
RDB.incr('next_gid', function(err, gid) {
|
|
||||||
RDB.multi()
|
|
||||||
.hset('group:gid', name, gid)
|
|
||||||
.hmset('gid:' + gid, {
|
|
||||||
gid: gid,
|
|
||||||
name: name,
|
|
||||||
description: description,
|
|
||||||
deleted: '0'
|
|
||||||
})
|
|
||||||
.exec(function(err) {
|
|
||||||
Groups.get(gid, {}, callback);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else callback(new Error('group-exists'))
|
|
||||||
});
|
|
||||||
},
|
|
||||||
update: function(gid, values, callback) {
|
|
||||||
RDB.exists('gid:' + gid, function(err, exists) {
|
|
||||||
if (!err && exists) RDB.hmset('gid:' + gid, values, callback);
|
|
||||||
else calback(new Error('gid-not-found'));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
destroy: function(gid, callback) {
|
|
||||||
RDB.hset('gid:' + gid, 'deleted', '1', callback);
|
|
||||||
},
|
|
||||||
join: function(gid, uid, callback) {
|
|
||||||
RDB.sadd('gid:' + gid + ':members', uid, callback);
|
|
||||||
},
|
|
||||||
leave: function(gid, uid, callback) {
|
|
||||||
RDB.srem('gid:' + gid + ':members', uid, callback);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Groups;
|
|
||||||
14
src/imgur.js
14
src/imgur.js
@@ -1,10 +1,12 @@
|
|||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
|
||||||
|
|
||||||
(function(imgur) {
|
(function (imgur) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var clientID = '';
|
var clientID = '';
|
||||||
|
|
||||||
imgur.upload = function(image, type, callback) {
|
imgur.upload = function (image, type, callback) {
|
||||||
var options = {
|
var options = {
|
||||||
url: 'https://api.imgur.com/3/upload.json',
|
url: 'https://api.imgur.com/3/upload.json',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -12,7 +14,7 @@ var request = require('request');
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var post = request.post(options, function(err, req, body) {
|
var post = request.post(options, function (err, req, body) {
|
||||||
try {
|
try {
|
||||||
callback(err, JSON.parse(body));
|
callback(err, JSON.parse(body));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -24,10 +26,10 @@ var request = require('request');
|
|||||||
type: type,
|
type: type,
|
||||||
image: image
|
image: image
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
imgur.setClientID = function(id) {
|
imgur.setClientID = function (id) {
|
||||||
clientID = id;
|
clientID = id;
|
||||||
}
|
};
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
Reference in New Issue
Block a user