fix crash when you go to /topics/nonexistant

v1.18.x
Baris Usakli 12 years ago
parent 9d5f6364ad
commit 34432773d6

@ -40,6 +40,7 @@ var templates = {};
for (var t in templatesToLoad) {
(function(file) {
$.get('/templates/' + file + '.tpl?v=' + timestamp, function(html) {
var template = function() {
this.toString = function() {
return this.html;
@ -168,6 +169,12 @@ function load_template(callback, url, template) {
jQuery.get(API_URL + url, function(data) {
console.log(data);
if(!data) {
window.location.href = '/403';
return;
}
var tpl = templates.get_custom_map(url);
if (tpl == false && !templates[url]) {

@ -12,6 +12,7 @@ marked.setOptions({
(function(Posts) {
Posts.get = function(callback, tid, current_user, start, end) {
if (start == null) start = 0;
if (end == null) end = start + 10;
@ -74,6 +75,11 @@ marked.setOptions({
// get all data for thread in asynchronous fashion
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
RDB.handle(err);
if(pids.length === 0){
callback(false);
return;
}
var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];

@ -20,6 +20,12 @@ var RDB = require('./redis.js'),
var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid';
RDB.smembers(range_var, function(err, tids) {
if(tids.length === 0) {
callback(false);
return;
}
var title = [],
uid = [],
timestamp = [],

@ -154,26 +154,46 @@ var express = require('express'),
break;
case 'topic' :
posts.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0);
break;
case 'category' :
topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0);
break;
case 'latest' :
topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data));
});
break;
case 'popular' :
topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data));
});
break;
case 'active' :
topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data));
});
break;

Loading…
Cancel
Save