From 02a02fa64c5f48e966b8197b77b6a0bf68d17ce2 Mon Sep 17 00:00:00 2001 From: Julian Lam <julian@designcreateplay.com> Date: Tue, 3 Sep 2013 13:11:21 -0400 Subject: [PATCH] updated getTopicWithPosts to use a start and end option, and fixed issue with RSS feed saving (issue #256) --- src/feed.js | 18 +++++++++++------- src/routes/api.js | 2 +- src/topics.js | 4 ++-- src/webserver.js | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/feed.js b/src/feed.js index bdbab1d1e7..7127e30256 100644 --- a/src/feed.js +++ b/src/feed.js @@ -5,10 +5,13 @@ topics = require('./topics.js'), fs = require('fs'), rss = require('node-rss'), - winston = require('winston'); + winston = require('winston'), + path = require('path'); function saveFeed(location, feed) { - fs.writeFile(location, rss.getFeedXML(feed), function (err) { + var savePath = path.join(__dirname, '../', location); + + fs.writeFile(savePath, rss.getFeedXML(feed), function (err) { if(err) { winston.err(err); } @@ -21,18 +24,19 @@ feed_url, description, author, - xml_url, + xml_url, { 'urn' : urn } - ); + ); } Feed.updateTopic = function(tid, cid) { + winston.info('[RSS] Updating RSS feeds for topic ' + tid); var cache_time_in_seconds = 60; - topics.getTopicWithPosts(tid, 0, function(err, topicData) { + topics.getTopicWithPosts(tid, 0, 0, -1, function(err, topicData) { if (err) winston.error('Problem saving topic RSS feed', err.stack); var location = '/topic/' + topicData.slug, @@ -79,14 +83,14 @@ var urn = 'urn:' + cid; var feed = createFeed(categoryData.category_name, '', location, xml_url, 'NodeBB', urn); // not exactly sure if author for a category should be site_title? - + var title; var topics = categoryData.topics; for (var i = 0, ii = topics.length; i < ii; i++) { urn = 'urn:' + cid + ':' + topics[i].tid; title = topics[i].title + '. Posted on ' + (new Date(parseInt(topics[i].timestamp, 10)).toUTCString()); - + feed.addNewItem( title, location, diff --git a/src/routes/api.js b/src/routes/api.js index fbaa4bd341..234ed7aa22 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -110,7 +110,7 @@ var user = require('./../user.js'), app.get('/api/topic/:id/:slug?', function(req, res, next) { var uid = (req.user) ? req.user.uid : 0; - topics.getTopicWithPosts(req.params.id, uid, function(err, data) { + topics.getTopicWithPosts(req.params.id, uid, 0, 10, function(err, data) { if(data.deleted === '1' && data.expose_tools === 0) { return res.json(404, {}); } diff --git a/src/topics.js b/src/topics.js index aa227c3be8..c504c67a30 100644 --- a/src/topics.js +++ b/src/topics.js @@ -324,7 +324,7 @@ var RDB = require('./redis.js') } - Topics.getTopicWithPosts = function(tid, current_user, callback) { + Topics.getTopicWithPosts = function(tid, current_user, start, end, callback) { threadTools.exists(tid, function(exists) { if (!exists) return callback(new Error('Topic tid \'' + tid + '\' not found')); @@ -338,7 +338,7 @@ var RDB = require('./redis.js') } function getTopicPosts(next) { - Topics.getTopicPosts(tid, 0, 10, current_user, function(topicPosts, privileges) { + Topics.getTopicPosts(tid, start, end, current_user, function(topicPosts, privileges) { next(null, topicPosts); }); } diff --git a/src/webserver.js b/src/webserver.js index 0ea5f47dfe..0c5f9b5b54 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -225,7 +225,7 @@ var express = require('express'), async.waterfall([ function(next) { - topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topicData) { + topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), 0, -1, function(err, topicData) { if(topicData) { if(topicData.deleted === '1' && topicData.expose_tools === 0) return next(new Error('Topic deleted'), null);