mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
fix crash when you go to /topics/nonexistant
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -75,6 +76,11 @@ marked.setOptions({
|
||||
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 = [];
|
||||
|
||||
for (var i=0, ii=pids.length; i<ii; i++) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user