Files
NodeBB/src/routes/plugins.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-11-21 12:28:10 -05:00
"use strict";
2013-11-03 17:15:18 -05:00
var nconf = require('nconf'),
path = require('path'),
fs = require('fs'),
2013-11-21 22:09:40 -05:00
validator = require('validator'),
2013-11-30 13:35:42 -05:00
plugins = require('../plugins'),
2013-11-03 17:15:18 -05:00
PluginRoutes = function(app) {
2013-11-21 12:28:10 -05:00
app.get('/plugins/fireHook', function(req, res) {
// GET = filter
Plugins.fireHook('filter:' + req.query.hook, req.query.args, function(err, returnData) {
if (typeof returnData === 'object') {
res.json(200, returnData);
} else {
2013-11-21 22:09:40 -05:00
res.send(200, validator.sanitize(returnData).escape());
2013-11-21 12:28:10 -05:00
}
});
});
app.put('/plugins/fireHook', function(req, res) {
// PUT = action
2013-11-30 13:35:42 -05:00
plugins.fireHook('action:' + req.body.hook, req.body.args);
2013-11-21 12:28:10 -05:00
res.send(200);
});
2013-11-03 17:15:18 -05:00
// Static Assets
app.get('/plugins/:id/*', function(req, res) {
var relPath = req.url.replace('/plugins/' + req.params.id, '');
if (Plugins.staticDirs[req.params.id]) {
var fullPath = path.join(Plugins.staticDirs[req.params.id], relPath);
fs.exists(fullPath, function(exists) {
if (exists) {
res.sendfile(fullPath, {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
2013-11-03 17:15:18 -05:00
} else {
res.redirect('/404');
}
2013-11-21 12:28:10 -05:00
});
2013-11-03 17:15:18 -05:00
} else {
res.redirect('/404');
}
});
};
module.exports = PluginRoutes;