mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
removed global modules
This commit is contained in:
31
app.js
31
app.js
@@ -1,41 +1,34 @@
|
|||||||
var modules = {
|
var topics = require('./src/topics.js'),
|
||||||
user: require('./src/user.js'),
|
posts = require('./src/posts.js'),
|
||||||
topics: require('./src/topics.js'),
|
categories = require('./src/categories.js'),
|
||||||
posts: require('./src/posts.js'),
|
templates = require('./src/templates.js'),
|
||||||
categories: require('./src/categories.js'),
|
webserver = require('./src/webserver.js'),
|
||||||
templates: require('./src/templates.js'),
|
websockets = require('./src/websockets.js'),
|
||||||
webserver: require('./src/webserver.js'),
|
fs = require('fs');
|
||||||
websockets: require('./src/websockets.js'),
|
|
||||||
fs: require('fs')
|
|
||||||
}
|
|
||||||
|
|
||||||
DEVELOPMENT = true;
|
DEVELOPMENT = true;
|
||||||
|
|
||||||
|
|
||||||
global.configuration = {};
|
global.configuration = {};
|
||||||
global.modules = modules;
|
|
||||||
|
|
||||||
|
|
||||||
(function(config) {
|
(function(config) {
|
||||||
config['ROOT_DIRECTORY'] = __dirname;
|
config['ROOT_DIRECTORY'] = __dirname;
|
||||||
|
|
||||||
modules.templates.init();
|
templates.init();
|
||||||
modules.websockets.init();
|
websockets.init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//setup scripts to be moved outside of the app in future.
|
//setup scripts to be moved outside of the app in future.
|
||||||
function setup_categories() {
|
function setup_categories() {
|
||||||
console.log('Checking categories...');
|
console.log('Checking categories...');
|
||||||
modules.categories.get(function(data) {
|
categories.get(function(data) {
|
||||||
if (data.categories.length === 0) {
|
if (data.categories.length === 0) {
|
||||||
console.log('Setting up default categories...');
|
console.log('Setting up default categories...');
|
||||||
|
|
||||||
modules.fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, categories) {
|
fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, categories) {
|
||||||
categories = JSON.parse(categories);
|
categories = JSON.parse(categories);
|
||||||
|
|
||||||
for (var category in categories) {
|
for (var category in categories) {
|
||||||
modules.categories.create(categories[category]);
|
categories.create(categories[category]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
|
var user = require('./../user.js'),
|
||||||
|
topics = require('./../topics.js');
|
||||||
|
|
||||||
(function(Admin) {
|
(function(Admin) {
|
||||||
Admin.create_routes = function(app) {
|
Admin.create_routes = function(app) {
|
||||||
|
|
||||||
@@ -29,7 +32,7 @@
|
|||||||
if (req.params.tab == 'search') {
|
if (req.params.tab == 'search') {
|
||||||
res.send(JSON.stringify({search_display: 'block', users: []}))
|
res.send(JSON.stringify({search_display: 'block', users: []}))
|
||||||
} else {
|
} else {
|
||||||
global.modules.user.getUserList(function(data){
|
user.getUserList(function(data){
|
||||||
res.send(JSON.stringify({search_display: 'none', users:data}));
|
res.send(JSON.stringify({search_display: 'none', users:data}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -39,13 +42,13 @@
|
|||||||
if (req.params.tab == 'disabled') {
|
if (req.params.tab == 'disabled') {
|
||||||
res.send(JSON.stringify({categories: []}));
|
res.send(JSON.stringify({categories: []}));
|
||||||
} else {
|
} else {
|
||||||
global.modules.categories.get(function(data) {
|
categories.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'topics' :
|
case 'topics' :
|
||||||
global.modules.topics.get(function(data) {
|
topics.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
|
||||||
// to be deprecated in favour of client-side only templates.
|
// to be deprecated in favour of client-side only templates.
|
||||||
|
|
||||||
(function(Templates) {
|
(function(Templates) {
|
||||||
@@ -7,7 +10,7 @@
|
|||||||
function loadTemplates(templatesToLoad) {
|
function loadTemplates(templatesToLoad) {
|
||||||
for (var t in templatesToLoad) {
|
for (var t in templatesToLoad) {
|
||||||
(function(file) {
|
(function(file) {
|
||||||
modules.fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) {
|
fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) {
|
||||||
var template = function() {
|
var template = function() {
|
||||||
this.toString = function() {
|
this.toString = function() {
|
||||||
return this.html;
|
return this.html;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
var config = require('../config.js'),
|
var config = require('../config.js'),
|
||||||
utils = require('./utils.js'),
|
utils = require('./utils.js'),
|
||||||
RDB = require('./redis.js'),
|
RDB = require('./redis.js'),
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ var express = require('express'),
|
|||||||
redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options),
|
redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options),
|
||||||
|
|
||||||
user = require('./user.js'),
|
user = require('./user.js'),
|
||||||
|
categories = require('./categories.js'),
|
||||||
|
posts = require('./posts.js'),
|
||||||
|
topics = require('./topics.js'),
|
||||||
utils = require('./utils.js'),
|
utils = require('./utils.js'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
admin = require('./routes/admin.js'),
|
admin = require('./routes/admin.js'),
|
||||||
@@ -40,11 +43,11 @@ var express = require('express'),
|
|||||||
if (/^\/api\//.test(req.url)) return next();
|
if (/^\/api\//.test(req.url)) return next();
|
||||||
|
|
||||||
if (req.user && req.user.uid) {
|
if (req.user && req.user.uid) {
|
||||||
global.modules.user.session_ping(req.sessionID, req.user.uid);
|
user.session_ping(req.sessionID, req.user.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (Re-)register the session as active
|
// (Re-)register the session as active
|
||||||
global.modules.user.active.register(req.sessionID);
|
user.active.register(req.sessionID);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@@ -98,7 +101,7 @@ var express = require('express'),
|
|||||||
function api_method(req, res) {
|
function api_method(req, res) {
|
||||||
switch(req.params.method) {
|
switch(req.params.method) {
|
||||||
case 'home' :
|
case 'home' :
|
||||||
global.modules.categories.get(function(data) {
|
categories.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -147,27 +150,27 @@ var express = require('express'),
|
|||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
break;
|
break;
|
||||||
case 'topic' :
|
case 'topic' :
|
||||||
global.modules.posts.get(function(data) {
|
posts.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
}, req.params.id, (req.user) ? req.user.uid : 0);
|
}, req.params.id, (req.user) ? req.user.uid : 0);
|
||||||
break;
|
break;
|
||||||
case 'category' :
|
case 'category' :
|
||||||
global.modules.topics.get(function(data) {
|
topics.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
}, req.params.id, (req.user) ? req.user.uid : 0);
|
}, req.params.id, (req.user) ? req.user.uid : 0);
|
||||||
break;
|
break;
|
||||||
case 'latest' :
|
case 'latest' :
|
||||||
global.modules.topics.get(function(data) {
|
topics.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'popular' :
|
case 'popular' :
|
||||||
global.modules.topics.get(function(data) {
|
topics.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'active' :
|
case 'active' :
|
||||||
global.modules.topics.get(function(data) {
|
topics.get(function(data) {
|
||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -189,7 +192,7 @@ var express = require('express'),
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 'confirm':
|
case 'confirm':
|
||||||
global.modules.user.email.confirm(req.params.id, function(data) {
|
user.email.confirm(req.params.id, function(data) {
|
||||||
if (data.status === 'ok') {
|
if (data.status === 'ok') {
|
||||||
res.send(JSON.stringify({
|
res.send(JSON.stringify({
|
||||||
'alert-class': 'alert-success',
|
'alert-class': 'alert-success',
|
||||||
@@ -436,7 +439,7 @@ var express = require('express'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.get('/test', function(req, res) {
|
app.get('/test', function(req, res) {
|
||||||
global.modules.posts.getRawContent(11, function(post) {
|
posts.getRawContent(11, function(post) {
|
||||||
res.send(JSON.stringify(post));
|
res.send(JSON.stringify(post));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
||||||
cookie = require('cookie'),
|
cookie = require('cookie'),
|
||||||
connect = require('connect'),
|
connect = require('connect'),
|
||||||
config = require('../config.js');
|
config = require('../config.js'),
|
||||||
|
user = require('./user.js'),
|
||||||
|
posts = require('./posts.js'),
|
||||||
|
topics = require('./topics.js'),
|
||||||
|
categories = require('./categories.js'),
|
||||||
|
templates = require('./templates.js');
|
||||||
|
|
||||||
(function(io) {
|
(function(io) {
|
||||||
var modules = null,
|
var users = {},
|
||||||
users = {},
|
|
||||||
rooms = {}
|
rooms = {}
|
||||||
|
|
||||||
global.io = io;
|
global.io = io;
|
||||||
module.exports.init = function() {
|
module.exports.init = function() {
|
||||||
modules = global.modules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adapted from http://howtonode.org/socket-io-auth
|
// Adapted from http://howtonode.org/socket-io-auth
|
||||||
@@ -30,7 +34,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
// Otherwise, continue unimpeded.
|
// Otherwise, continue unimpeded.
|
||||||
var sessionID = handshakeData.sessionID;
|
var sessionID = handshakeData.sessionID;
|
||||||
|
|
||||||
global.modules.user.get_uid_by_session(sessionID, function(userId) {
|
user.get_uid_by_session(sessionID, function(userId) {
|
||||||
if (userId)
|
if (userId)
|
||||||
{
|
{
|
||||||
users[sessionID] = userId;
|
users[sessionID] = userId;
|
||||||
@@ -50,7 +54,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
|
|
||||||
if (DEVELOPMENT === true) {
|
if (DEVELOPMENT === true) {
|
||||||
// refreshing templates
|
// refreshing templates
|
||||||
modules.templates.init();
|
templates.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*process.on('uncaughtException', function(err) {
|
/*process.on('uncaughtException', function(err) {
|
||||||
@@ -93,7 +97,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
modules.user.get_usernames_by_uids(uids, function(usernames) {
|
user.get_usernames_by_uids(uids, function(usernames) {
|
||||||
io.sockets.in(data.enter).emit('api:get_users_in_room', {
|
io.sockets.in(data.enter).emit('api:get_users_in_room', {
|
||||||
usernames: usernames,
|
usernames: usernames,
|
||||||
uids: uids,
|
uids: uids,
|
||||||
@@ -111,7 +115,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
socket.on('api:updateHeader', function(data) {
|
socket.on('api:updateHeader', function(data) {
|
||||||
if(uid) {
|
if(uid) {
|
||||||
|
|
||||||
modules.user.getUserFields(uid, data.fields, function(fields) {
|
user.getUserFields(uid, data.fields, function(fields) {
|
||||||
fields.uid = uid;
|
fields.uid = uid;
|
||||||
socket.emit('api:updateHeader', fields);
|
socket.emit('api:updateHeader', fields);
|
||||||
});
|
});
|
||||||
@@ -128,107 +132,107 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.exists', function(data) {
|
socket.on('user.exists', function(data) {
|
||||||
modules.user.exists(data.username, function(exists){
|
user.exists(data.username, function(exists){
|
||||||
socket.emit('user.exists', {exists: exists});
|
socket.emit('user.exists', {exists: exists});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.count', function(data) {
|
socket.on('user.count', function(data) {
|
||||||
modules.user.count(socket, data);
|
user.count(socket, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.latest', function(data) {
|
socket.on('user.latest', function(data) {
|
||||||
modules.user.latest(socket, data);
|
user.latest(socket, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.email.exists', function(data) {
|
socket.on('user.email.exists', function(data) {
|
||||||
modules.user.email.exists(socket, data.email);
|
user.email.exists(socket, data.email);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user:reset.send', function(data) {
|
socket.on('user:reset.send', function(data) {
|
||||||
modules.user.reset.send(socket, data.email);
|
user.reset.send(socket, data.email);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user:reset.valid', function(data) {
|
socket.on('user:reset.valid', function(data) {
|
||||||
modules.user.reset.validate(socket, data.code);
|
user.reset.validate(socket, data.code);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user:reset.commit', function(data) {
|
socket.on('user:reset.commit', function(data) {
|
||||||
modules.user.reset.commit(socket, data.code, data.password);
|
user.reset.commit(socket, data.code, data.password);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topics.post', function(data) {
|
socket.on('api:topics.post', function(data) {
|
||||||
modules.topics.post(socket, uid, data.title, data.content, data.category_id);
|
topics.post(socket, uid, data.title, data.content, data.category_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.reply', function(data) {
|
socket.on('api:posts.reply', function(data) {
|
||||||
modules.posts.reply(socket, data.topic_id, uid, data.content);
|
posts.reply(socket, data.topic_id, uid, data.content);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.active.get', function() {
|
socket.on('api:user.active.get', function() {
|
||||||
modules.user.active.get();
|
user.active.get();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.favourite', function(data) {
|
socket.on('api:posts.favourite', function(data) {
|
||||||
modules.posts.favourite(io, data.pid, data.room_id, uid);
|
posts.favourite(io, data.pid, data.room_id, uid);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.unfavourite', function(data) {
|
socket.on('api:posts.unfavourite', function(data) {
|
||||||
modules.posts.unfavourite(io, data.pid, data.room_id, uid);
|
posts.unfavourite(io, data.pid, data.room_id, uid);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.active.get_record', function() {
|
socket.on('api:user.active.get_record', function() {
|
||||||
modules.user.active.get_record(socket);
|
user.active.get_record(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.delete', function(data) {
|
socket.on('api:topic.delete', function(data) {
|
||||||
modules.topics.delete(data.tid, uid, socket);
|
topics.delete(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.restore', function(data) {
|
socket.on('api:topic.restore', function(data) {
|
||||||
modules.topics.restore(data.tid, uid, socket);
|
topics.restore(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.lock', function(data) {
|
socket.on('api:topic.lock', function(data) {
|
||||||
modules.topics.lock(data.tid, uid, socket);
|
topics.lock(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.unlock', function(data) {
|
socket.on('api:topic.unlock', function(data) {
|
||||||
modules.topics.unlock(data.tid, uid, socket);
|
topics.unlock(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.pin', function(data) {
|
socket.on('api:topic.pin', function(data) {
|
||||||
modules.topics.pin(data.tid, uid, socket);
|
topics.pin(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.unpin', function(data) {
|
socket.on('api:topic.unpin', function(data) {
|
||||||
modules.topics.unpin(data.tid, uid, socket);
|
topics.unpin(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:categories.get', function() {
|
socket.on('api:categories.get', function() {
|
||||||
modules.categories.get(function(categories) {
|
categories.get(function(categories) {
|
||||||
socket.emit('api:categories.get', categories);
|
socket.emit('api:categories.get', categories);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.move', function(data) {
|
socket.on('api:topic.move', function(data) {
|
||||||
modules.topics.move(data.tid, data.cid, socket);
|
topics.move(data.tid, data.cid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.getRawPost', function(data) {
|
socket.on('api:posts.getRawPost', function(data) {
|
||||||
modules.posts.getRawContent(data.pid, socket);
|
posts.getRawContent(data.pid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.edit', function(data) {
|
socket.on('api:posts.edit', function(data) {
|
||||||
modules.posts.edit(uid, data.pid, data.content);
|
posts.edit(uid, data.pid, data.content);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.delete', function(data) {
|
socket.on('api:posts.delete', function(data) {
|
||||||
modules.posts.delete(uid, data.pid);
|
posts.delete(uid, data.pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.restore', function(data) {
|
socket.on('api:posts.restore', function(data) {
|
||||||
modules.posts.restore(uid, data.pid);
|
posts.restore(uid, data.pid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user