Skip to content

Node.js based forum software built for the modern web

totally derped commit

Julian Lam164977972e5a
diff --git a/src/feed.js b/src/feed.js
index ee95309d71..8799db8b85 100644
--- a/src/feed.js
+++ b/src/feed.js
@@ -24,7 +24,7 @@
});
}
- Feed.updateTopic = function(tid, cid) {
+ Feed.updateTopic = function(tid, callback) {
if (process.env.NODE_ENV === 'development') winston.info('[rss] Updating RSS feeds for topic ' + tid);
topics.getTopicWithPosts(tid, 0, 0, -1, function(err, topicData) {
@@ -57,11 +57,12 @@
}
Feed.saveFeed('feeds/topics/' + tid + '.rss', feed);
+ if (callback) callback();
});
};
- Feed.updateCategory = function(cid) {
+ Feed.updateCategory = function(cid, callback) {
if (process.env.NODE_ENV === 'development') winston.info('[rss] Updating RSS feeds for category ' + cid);
categories.getCategoryById(cid, 0, function(err, categoryData) {
if (err) return winston.error('Could not update RSS feed for category ' + cid, err.stack);
@@ -90,6 +91,7 @@
}
Feed.saveFeed('feeds/categories/' + cid + '.rss', feed);
+ if (callback) callback();
});
};
diff --git a/src/posts.js b/src/posts.js
index 037e356df0..97f8d55bdf 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -314,7 +314,7 @@ var RDB = require('./redis.js'),
topics.getTopicField(tid, 'cid', function(err, cid) {
RDB.handle(err);
- feed.updateTopic(tid, cid);
+ feed.updateTopic(tid);
RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid);
RDB.zadd('categories:' + cid + ':tid', timestamp, tid);
diff --git a/src/webserver.js b/src/webserver.js
index 0abdcb36a3..6c7b9193e9 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -21,7 +21,8 @@ var express = require('express'),
installRoute = require('./routes/install.js'),
testBed = require('./routes/testbed.js'),
auth = require('./routes/authentication.js'),
- meta = require('./meta.js');
+ meta = require('./meta.js'),
+ feed = require('./feed');
(function(app) {
var templates = null;
@@ -212,15 +213,25 @@ var express = require('express'),
var tid = req.params.topic_id;
if (tid.match(/^\d+\.rss$/)) {
- fs.readFile(path.join(__dirname, '../', 'feeds/topics', tid), function (err, data) {
- if (err) {
- res.type('text').send(404, "Unable to locate an rss feed at this location.");
+ tid = tid.slice(0, -4);
+ var rssPath = path.join(__dirname, '../', 'feeds/topics', tid + '.rss'),
+ loadFeed = function() {
+ fs.readFile(rssPath, function (err, data) {
+ if (err) {
+ res.type('text').send(404, "Unable to locate an rss feed at this location.");
+ return;
+ }
+
+ res.type('xml').set('Content-Length', data.length).send(data);
+ });
return;
- }
+ };
- res.type('xml').set('Content-Length', data.length).send(data);
- });
- return;
+ if (!fs.existsSync(rssPath)) {
+ feed.updateTopic(tid, function() {
+ loadFeed();
+ });
+ } else loadFeed();
}
async.waterfall([