fixed broken mget implementation if no topics are present

v1.18.x
Julian Lam 12 years ago
parent a16f72e11c
commit 9e5a7b96b3

@ -5,8 +5,8 @@
redis = require('redis'), redis = require('redis'),
db = redis.createClient(); db = redis.createClient();
// todo (holy cow): append,auth,bgrewriteaof,bgsave,bitcount,bitop,blpop,brpop,brpoplpush,client kill,client list,client getname,client setname,config get,config set,config resetstat,dbsize,debug object,debug segfault,decrby,del,discard,dump,echo,eval,evalsha,exec,exists,expire,expireat,flushall,flushdb,getbit,getrange,getset,hdel,hexists,hget,hgetall,hincrby,hincrbyfloat,hkeys,hlen,hmget,hmset,hset,hsetnx,hvals,incrby,incrbyfloat,info,keys,lastsave,lindex,linsert,llen,lpop,lpush,lpushx,lrange,lrem,lset,ltrim,mget,migrate,monitor,move,mset,msetnx,multi,object,persist,pexpire,pexpireat,ping,psetex,psubscribe,pttl,publish,punsubscribe,quit,randomkey,rename,renamenx,restore,rpop,rpoplpush,rpush,rpushx,sadd,save,scard,script exists,script flush,script kill,script load,sdiff,sdiffstore,select,setbit,setex,setnx,setrange,shutdown,sinter,sinterstore,sismember,slaveof,slowlog,smembers,smove,sort,spop,srandmember,srem,strlen,subscribe,sunion,sunionstore,sync,time,ttl,type,unsubscribe,unwatch,watch,zadd,zcard,zcount,zincrby,zinterstore,zrange,zrangebyscore,zrank,zrem,zremrangebyrank,zremrangebyscore,zrevrange,zrevrangebyscore,zrevrank,zscore,zunionstore // todo (holy cow): append,auth,bgrewriteaof,bgsave,bitcount,bitop,blpop,brpop,brpoplpush,client kill,client list,client getname,client setname,config get,config set,config resetstat,dbsize,debug object,debug segfault,decrby,discard,dump,echo,eval,evalsha,exec,exists,expireat,flushall,flushdb,getbit,getrange,getset,hdel,hexists,hget,hgetall,hincrby,hincrbyfloat,hkeys,hlen,hmget,hmset,hset,hsetnx,hvals,incrby,incrbyfloat,info,keys,lastsave,lindex,linsert,llen,lpop,lpushx,lrem,lset,ltrim,migrate,monitor,move,mset,msetnx,object,persist,pexpire,pexpireat,ping,psetex,psubscribe,pttl,publish,punsubscribe,quit,randomkey,rename,renamenx,restore,rpop,rpoplpush,rpush,rpushx,sadd,save,scard,script exists,script flush,script kill,script load,sdiff,sdiffstore,select,setbit,setex,setnx,setrange,shutdown,sinter,sinterstore,sismember,slaveof,slowlog,smembers,smove,sort,spop,srandmember,srem,strlen,subscribe,sunion,sunionstore,sync,time,ttl,type,unsubscribe,unwatch,watch,zadd,zcard,zcount,zincrby,zinterstore,zrange,zrangebyscore,zrank,zrem,zremrangebyrank,zremrangebyscore,zrevrange,zrevrangebyscore,zrevrank,zscore,zunionstore
// done :^) get, set, incr, decr // done: get, set, incr, decr, del, mget, multi, expire, lpush, lrange
function return_handler(error, data, callback, error_handler) { function return_handler(error, data, callback, error_handler) {
if (error !== null) { if (error !== null) {

@ -53,33 +53,34 @@ var RDB = require('./redis.js'),
callback(topic_data); callback(topic_data);
});*/ });*/
RDB.multi() if (tids.length > 0) {
.mget(title) RDB.multi()
.mget(uid) .mget(title)
.mget(timestamp) .mget(uid)
.mget(posts) .mget(timestamp)
.exec(function(err, replies) { .mget(posts)
title = replies[0]; .exec(function(err, replies) {
uid = replies[1]; title = replies[0];
timestamp = replies[2]; uid = replies[1];
posts = replies[3]; timestamp = replies[2];
posts = replies[3];
var topics = [];
for (var i=0, ii=title.length; i<ii; i++) { var topics = [];
topics.push({ for (var i=0, ii=title.length; i<ii; i++) {
'title' : title[i], topics.push({
'uid' : uid[i], 'title' : title[i],
'timestamp' : timestamp[i], 'uid' : uid[i],
'posts' : posts[i], 'timestamp' : timestamp[i],
'post_count' : 0 'posts' : posts[i],
}); 'post_count' : 0
});
}
callback(topics);
} }
);
callback(topics); } else callback([]);
});
}); });
} }

@ -15,9 +15,16 @@ var express = require('express'),
} }
} }
function checkAuth(req, res, next) { function hasAuth(req, res, next) {
// Include this middleware if the endpoint is publically accessible, but has elements that logged in users can see
}
function requireAuth(req, res, next) {
// Include this middleware if the endpoint requires a logged in user to view
console.log('REQUIRE: ', global.uid, req.sessionID);
if (!global.uid) { if (!global.uid) {
res.send(403, 'You are not authorized to view this page'); req.redirect('/403');
} else { } else {
next(); next();
} }
@ -63,11 +70,15 @@ var express = require('express'),
res.send(templates['header'] + templates['register'] + templates['footer']); res.send(templates['header'] + templates['register'] + templates['footer']);
}); });
app.get('/account', checkAuth, function(req, res) { app.get('/account', requireAuth, function(req, res) {
refreshTemplates(); refreshTemplates();
res.send(templates['header'] + templates['account_settings'] + templates['footer']); res.send(templates['header'] + templates['account_settings'] + templates['footer']);
}); });
app.get('/403', function(req, res) {
res.send(403, 'You are not authorized to view this page');
});
module.exports.init = function() { module.exports.init = function() {
// todo move some of this stuff into config.json // todo move some of this stuff into config.json
app.configure(function() { app.configure(function() {

Loading…
Cancel
Save