Baris Soner Usakli 11 years ago
commit f96a711298

@ -187,7 +187,15 @@ define(['taskbar'], function(taskbar) {
switch(action) { switch(action) {
case 'post': composer.post(uuid); break; case 'post': composer.post(uuid); break;
case 'minimize': composer.minimize(uuid); break; case 'minimize': composer.minimize(uuid); break;
case 'discard': composer.discard(uuid); break; case 'discard':
if (postContentEl.value.length > 0) {
bootbox.confirm('Are you sure you wish to discard this post?', function(discard) {
if (discard) composer.discard(uuid);
});
} else {
composer.discard(uuid);
}
break;
} }
}); });

@ -26,7 +26,6 @@ var fs = require('fs'),
function(plugins, next) { function(plugins, next) {
if (plugins && Array.isArray(plugins) && plugins.length > 0) { if (plugins && Array.isArray(plugins) && plugins.length > 0) {
async.each(plugins, function(plugin, next) { async.each(plugins, function(plugin, next) {
// TODO: Update this check to also check node_modules
var pluginPath = path.join(__dirname, '../plugins/', plugin), var pluginPath = path.join(__dirname, '../plugins/', plugin),
modulePath = path.join(__dirname, '../node_modules/', plugin); modulePath = path.join(__dirname, '../node_modules/', plugin);
if (fs.existsSync(pluginPath)) _self.loadPlugin(pluginPath, next); if (fs.existsSync(pluginPath)) _self.loadPlugin(pluginPath, next);
@ -57,11 +56,13 @@ var fs = require('fs'),
if (global.env === 'development') winston.info('[plugins] Plugins OK'); if (global.env === 'development') winston.info('[plugins] Plugins OK');
_self.initialized = true;
_self.readyEvent.emit('ready'); _self.readyEvent.emit('ready');
}); });
}, },
ready: function(callback) { ready: function(callback) {
this.readyEvent.once('ready', callback); if (!this.initialized) this.readyEvent.once('ready', callback);
else callback();
}, },
initialized: false, initialized: false,
loadPlugin: function(pluginPath, callback) { loadPlugin: function(pluginPath, callback) {
@ -161,7 +162,7 @@ var fs = require('fs'),
} }
} }
callback(returnVal); callback(err, returnVal);
}); });
break; break;
case 'action': case 'action':
@ -184,7 +185,7 @@ var fs = require('fs'),
} else { } else {
// Otherwise, this hook contains no methods // Otherwise, this hook contains no methods
var returnVal = (Array.isArray(args) ? args[0] : args); var returnVal = (Array.isArray(args) ? args[0] : args);
if (callback) callback(returnVal); if (callback) callback(err, returnVal);
} }
}, },
isActive: function(id, callback) { isActive: function(id, callback) {

@ -102,8 +102,8 @@ var RDB = require('./redis.js'),
PostTools.privileges(pid, uid, function(privileges) { PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) { if (privileges.editable) {
plugins.fireHook('filter:post.save', content, function(parsedContent) { plugins.fireHook('filter:post.save', content, function(err, parsedContent) {
content = parsedContent; if (!err) content = parsedContent;
success(); success();
}); });
} }
@ -193,8 +193,8 @@ var RDB = require('./redis.js'),
PostTools.parse = function(raw, callback) { PostTools.parse = function(raw, callback) {
raw = raw || ''; raw = raw || '';
plugins.fireHook('filter:post.parse', raw, function(parsed) { plugins.fireHook('filter:post.parse', raw, function(err, parsed) {
callback(null, parsed); callback(null, !err ? parsed : raw);
}); });
} }

@ -122,8 +122,9 @@ var RDB = require('./redis.js'),
Posts.getPostData = function(pid, callback) { Posts.getPostData = function(pid, callback) {
RDB.hgetall('post:' + pid, function(err, data) { RDB.hgetall('post:' + pid, function(err, data) {
if (err === null) { if (err === null) {
plugins.fireHook('filter:post.get', data, function(data) { plugins.fireHook('filter:post.get', data, function(err, newData) {
callback(data); if (!err) callback(newData);
else callback(data);
}); });
} else } else
console.log(err); console.log(err);
@ -287,7 +288,9 @@ var RDB = require('./redis.js'),
RDB.incr('global:next_post_id', function(err, pid) { RDB.incr('global:next_post_id', function(err, pid) {
RDB.handle(err); RDB.handle(err);
plugins.fireHook('filter:post.save', content, function(content) { plugins.fireHook('filter:post.save', content, function(err, newContent) {
if (!err) content = newContent;
var timestamp = Date.now(), var timestamp = Date.now(),
postData = { postData = {
'pid': pid, 'pid': pid,
@ -337,7 +340,9 @@ var RDB = require('./redis.js'),
async.parallel({ async.parallel({
content: function(next) { content: function(next) {
plugins.fireHook('filter:post.get', postData, function(postData) { plugins.fireHook('filter:post.get', postData, function(err, newPostData) {
if (!err) postData = newPostData;
postTools.parse(postData.content, function(err, content) { postTools.parse(postData.content, function(err, content) {
next(null, content); next(null, content);
}); });

@ -22,7 +22,8 @@ var express = require('express'),
meta = require('./meta.js'), meta = require('./meta.js'),
feed = require('./feed'), feed = require('./feed'),
plugins = require('./plugins'), plugins = require('./plugins'),
nconf = require('nconf'); nconf = require('nconf'),
winston = require('winston');
(function (app) { (function (app) {
var templates = null, var templates = null,
@ -72,54 +73,104 @@ var express = require('express'),
}; };
// Middlewares // Middlewares
app.use(express.compress()); app.configure(function() {
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico'))); async.series([
app.use(require('less-middleware')({ function(next) {
src: path.join(__dirname, '../', 'public'), // Pre-router middlewares
prefix: nconf.get('relative_path'), app.use(express.compress());
yuicompress: true app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
})); app.use(require('less-middleware')({
app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public'))); src: path.join(__dirname, '../', 'public'),
app.use(express.bodyParser()); // Puts POST vars in request.body prefix: nconf.get('relative_path'),
yuicompress: true
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies) }));
app.use(express.session({ app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public')));
store: new RedisStore({ app.use(express.bodyParser()); // Puts POST vars in request.body
client: RDB, app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
ttl: 60 * 60 * 24 * 30 app.use(express.session({
}), store: new RedisStore({
secret: nconf.get('secret'), client: RDB,
key: 'express.sid', ttl: 60 * 60 * 24 * 30
cookie: { }),
maxAge: 60 * 60 * 24 * 30 * 1000 // 30 days secret: nconf.get('secret'),
} key: 'express.sid',
})); cookie: {
app.use(express.csrf()); maxAge: 60 * 60 * 24 * 30 * 1000 // 30 days
app.use(function (req, res, next) { }
res.locals.csrf_token = req.session._csrf; }));
next(); app.use(express.csrf());
});
// Local vars, other assorted setup
app.use(function (req, res, next) {
nconf.set('https', req.secure);
res.locals.csrf_token = req.session._csrf;
next();
});
// Static Directories for NodeBB Plugins // Authentication Routes
app.configure(function () { auth.initialize(app);
var tailMiddlewares = [];
next();
plugins.ready(function () { },
// Remove some middlewares until the router is gone function(next) {
// This is not recommended behaviour: http://stackoverflow.com/a/13691542/122353 // Static Directories for NodeBB Plugins
// Also: https://www.exratione.com/2013/03/nodejs-abusing-express-3-to-enable-late-addition-of-middleware/ plugins.ready(function () {
tailMiddlewares.push(app.stack.pop()); for (d in plugins.staticDirs) {
tailMiddlewares.push(app.stack.pop()); app.use(nconf.get('relative_path') + '/plugins/' + d, express.static(plugins.staticDirs[d]));
tailMiddlewares.push(app.stack.pop()); winston.info('Static directory routed for plugin: ' + d);
for (d in plugins.staticDirs) { }
app.use(nconf.get('relative_path') + '/plugins/' + d, express.static(plugins.staticDirs[d]));
} next();
});
},
function(next) {
// Router & post-router middlewares
app.use(app.router);
// 404 catch-all
app.use(function (req, res, next) {
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.redirect(nconf.get('relative_path') + '/404');
return;
}
// respond with json
if (req.accepts('json')) {
res.send({
error: 'Not found'
});
return;
}
// Push the removed middlewares back onto the application stack // default to plain-text. send()
tailMiddlewares.reverse(); res.type('txt').send('Not found');
app.stack.push(tailMiddlewares.shift()); });
app.stack.push(tailMiddlewares.shift());
app.stack.push(tailMiddlewares.shift()); app.use(function (err, req, res, next) {
// we may use properties of the error object
// here and next(err) appropriately, or if
// we possibly recovered from the error, simply next().
console.error(err.stack);
res.status(err.status || 500);
res.json('500', {
error: err.message
});
});
next();
}
], function(err) {
if (err) {
winston.error('Errors were encountered while attempting to initialise NodeBB.');
} else {
winston.info('Middlewares loaded.');
}
}); });
}); });
@ -137,59 +188,10 @@ var express = require('express'),
server.listen(nconf.get('PORT') || nconf.get('port')); server.listen(nconf.get('PORT') || nconf.get('port'));
} }
auth.initialize(app);
app.use(function (req, res, next) {
nconf.set('https', req.secure);
next();
});
app.use(app.router);
app.use(function (req, res, next) {
res.status(404);
// respond with html page
if (req.accepts('html')) {
//res.json('404', { url: req.url });
res.redirect(nconf.get('relative_path') + '/404');
return;
}
// respond with json
if (req.accepts('json')) {
res.send({
error: 'Not found'
});
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
app.use(function (err, req, res, next) {
// we may use properties of the error object
// here and next(err) appropriately, or if
// we possibly recovered from the error, simply next().
console.error(err.stack);
res.status(err.status || 500);
res.json('500', {
error: err.message
});
});
app.create_route = function (url, tpl) { // to remove app.create_route = function (url, tpl) { // to remove
return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>'; return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';
}; };
app.namespace(nconf.get('relative_path'), function () { app.namespace(nconf.get('relative_path'), function () {
auth.create_routes(app); auth.create_routes(app);

Loading…
Cancel
Save