From 209bcaba8caccd7a6ced3650610ac3cbb7c9b7a5 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 3 Mar 2014 12:49:47 -0500 Subject: [PATCH] middleware.updateLastOnlineTime; middleware.prepareAPI (reinstated) --- src/middleware/middleware.js | 16 ++++++++++++++++ src/routes/api.js | 11 +---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 1868c69e6f..1f10f192cb 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -13,6 +13,7 @@ var app, meta = require('./../meta'), translator = require('./../../public/src/translator'), user = require('./../user'), + db = require('./../database'), controllers = { api: require('./../controllers/api') @@ -30,6 +31,21 @@ middleware.authenticate = function(req, res, next) { } }; +middleware.updateLastOnlineTime = function(req, res, next) { + if(req.user) { + user.updateLastOnlineTime(req.user.uid); + } + + db.sortedSetAdd('ip:recent', Date.now(), req.ip || 'Unknown'); + + next(); +}; + +middleware.prepareAPI = function(req, res, next) { + res.locals.isAPI = true; + next(); +}; + middleware.checkGlobalPrivacySettings = function(req, res, next) { var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; diff --git a/src/routes/api.js b/src/routes/api.js index f44532e9d0..8f3cbc44d0 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -17,16 +17,7 @@ var path = require('path'), module.exports = function(app, middleware, controllers) { app.namespace('/api', function () { - app.all('*', function(req, res, next) { - if(req.user) { - user.updateLastOnlineTime(req.user.uid); - } - - db.sortedSetAdd('ip:recent', Date.now(), req.ip || 'Unknown'); - res.locals.isAPI = true; - - next(); - }); + app.all('*', middleware.updateLastOnlineTime, middleware.prepareAPI); app.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID);