From 2f8cd3b7adf0dfc364839806bb9a4a00a64a021a Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 27 Mar 2013 17:39:01 +0000 Subject: [PATCH] working caching hopefully --- README.md | 4 +-- client.js | 4 +-- ep.json | 1 - index.js | 70 ++++++++++++++++++++++++--------------- static/img/rss.gif | Bin 0 -> 918 bytes templates/embedFrame.ejs | 8 +++++ update.js | 61 ---------------------------------- 7 files changed, 55 insertions(+), 93 deletions(-) create mode 100644 static/img/rss.gif create mode 100644 templates/embedFrame.ejs delete mode 100644 update.js diff --git a/README.md b/README.md index 214153f..8fb362e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Creates an RSS feed and prefixes it to the end of a pad IE as atom.xml IE http://bacon.com/p/yummi/atom.xml # Installation -Just install then click the Embed button to get the link +Just install then click the Share and Embed button to get the RSS feed URL # TODO -Everything +Smarter creation of new items upon modification diff --git a/client.js b/client.js index fc9c43f..1d0ee23 100644 --- a/client.js +++ b/client.js @@ -1,7 +1,7 @@ var eejs = require("ep_etherpad-lite/node/eejs"); exports.eejsBlock_embedPopup = function (hook_name, args, cb) { - var rssFeed = { padId:"test" }; - args.content = args.content + eejs.require("ep_rss/templates/embedFrame.html", rssFeed, module); + var feedURL = args.renderContext.req.url + "/feed"; + args.content = args.content + eejs.require("ep_rss/templates/embedFrame.ejs", {feed: feedURL}); return cb(); }; diff --git a/ep.json b/ep.json index 3644909..6e3b797 100644 --- a/ep.json +++ b/ep.json @@ -3,7 +3,6 @@ { "name": "ep_rss", "hooks": { - "padUpdate": "ep_rss/update", "eejsBlock_htmlHead": "ep_rss/index", "expressCreateServer" : "ep_rss/index:registerRoute", "eejsBlock_embedPopup": "ep_rss/client:eejsBlock_embedPopup" diff --git a/index.js b/index.js index 1dca3ae..e2d7ac2 100644 --- a/index.js +++ b/index.js @@ -43,20 +43,33 @@ exports.registerRoute = function (hook_name, args, cb) { var padId=path[2]; var padURL = req.protocol + "://" + req.get('host') + "/p/" +padId; var dateString = new Date(); - var isPublished = false; + var isPublished = false; // is this item already published? /* When was this pad last edited and should we publish an RSS update? */ async.series([ function(cb){ API.getLastEdited(padId, function(callback, message){ var currTS = new Date().getTime(); - if(currTS - message.lastEdited < staleTime){ + if(!feeds[padId]){ + feeds[padId] = {}; + } + + if(currTS - message.lastEdited < staleTime){ // was the pad edited within the last 5 minutes? isPublished = isAlreadyPublished(padId, message.lastEdited); - if(!isPublished){ - feeds[padId] = message.lastEdited; // Add it to the timer object + + if(!isPublished){ // If it's not already published and it's gone stale + feeds[padId].lastEdited = message.lastEdited; // Add it to the timer object } cb(); + }else{ + if(!feeds[padId].feed){ // If it's not already stored in memory + console.debug("Feed not already in memory so writing memory", feeds); + isPublished = false; + feeds[padId].lastEdited = message.lastEdited; // Add it to the timer object + }else{ + isPublished = true; + } cb(); } }); @@ -65,7 +78,6 @@ exports.registerRoute = function (hook_name, args, cb) { /* Get the pad text */ function(cb){ if(!isPublished){ - console.warn("here"); var padText = padManager.getPad(padId, function(err, _pad){ pad = _pad; text = safe_tags(pad.text()).replace(/\n/g,"
"); @@ -80,34 +92,38 @@ exports.registerRoute = function (hook_name, args, cb) { /* Create a new RSS item */ function(cb){ if(isPublished){ + console.debug("Sending RSS from memory for "+padId); + res.contentType("rss"); res.send(feeds[padId].feed); cb(); } + else{ + console.debug("Building RSS for "+padId); /* Why don't we use EEJS require here? Well EEJS require isn't ASYNC so on first load it would bring in the .ejs content only and then on second load pad contents would be included.. Sorry this is ugly but that's how the plugin FW was designed by @redhog -- bug him for a fix! */ - - res.contentType("rss"); - args.content = '\n'; - args.content += '\n'; - args.content += ''+padId+'\n'; - args.content += '\n'; - args.content += 'en-us\n'; - args.content += ''+dateString+'\n'; - args.content += ''+dateString+'\n'; - args.content += '\n'; - args.content += '\n'; - args.content += padId + ' has been changed\n'; - args.content += '\n'; - args.content += '\n'; - args.content += '\n'; - args.content += ''+padURL+'\n'; - args.content += '\n'; - args.content += '\n'; - args.content += ''; - feeds[padId].feed = args.content; - res.send(args.content); // Send it to the requester - cb(); // Am I even called? + res.contentType("rss"); + args.content = '\n'; + args.content += '\n'; + args.content += ''+padId+'\n'; + args.content += '\n'; + args.content += 'en-us\n'; + args.content += ''+dateString+'\n'; + args.content += ''+dateString+'\n'; + args.content += '\n'; + args.content += '\n'; + args.content += padId + ' has been changed\n'; + args.content += '\n'; + args.content += '\n'; + args.content += '\n'; + args.content += ''+padURL+'\n'; + args.content += '\n'; + args.content += '\n'; + args.content += ''; + feeds[padId].feed = args.content; + res.send(args.content); // Send it to the requester + cb(); // Am I even called? + } },function(){ /* Todo - Some error handling */ diff --git a/static/img/rss.gif b/static/img/rss.gif new file mode 100644 index 0000000000000000000000000000000000000000..19e37b5dd52116d2830cbd2dafda7fa743045266 GIT binary patch literal 918 zcmV;H18Mw6Nk%w1VJH9&0OkMy|NsBYT@~t;W&M*R>3cEbrG434DEYX0;cYDaW(fTC@%525^|gfUj7a*OI{x_c z-D4{GnK{@<1@pI)@uF(^!jtZI7wM^g`lCnUdrj+qEBwTV`n7K4btcFzkUc&0QAllUm$*GyCb?=cP1-)JlAg*NAUG4{{2?0Y8hkwWf;Gv|FT z;e23^p8U#|+-5e-UKaGIYVn6J^o=n8{{8=p6!(}o-h@Ht zdnNdwM(B4e-+?&ky_nr+BK3SCov^QEIC}O)} z2N+s6N-i`y6-$qgA$m3%9b91+I0g*s03%8ncK`{GB<5_`(2oKO1OdpLVKQaHj7JFu z*toDI1wDHJ7*OdWln8zvsgc4*4S*02#;mw_kHP`~MjH6o@My!83tH9*5x~KK zQ$9ZPQ1k;Jh07xXE4Jd`AOHY`V@+_0x$+Re1Sc6j{I$?Fz!4ijddN5dpi2b^06qj! zK@Uk^5MQh0+VurmKRlrX3p}`hfD2K$0e~7r(16K~n9xvw8i4=+JN;m&tpET3 literal 0 HcmV?d00001 diff --git a/templates/embedFrame.ejs b/templates/embedFrame.ejs new file mode 100644 index 0000000..9e63558 --- /dev/null +++ b/templates/embedFrame.ejs @@ -0,0 +1,8 @@ +
+

Rss Feeds

+

+ + + + +

diff --git a/update.js b/update.js deleted file mode 100644 index 67022cf..0000000 --- a/update.js +++ /dev/null @@ -1,61 +0,0 @@ -// Main job is to check pads periodically for activity and notify owners when someone begins editing and when someone finishes. - var db = require('../../src/node/db/DB').db, - API = require('../../src/node/db/API.js'), - async = require('../../src/node_modules/async'), -settings = require('../../src/node/utils/Settings'); - -// Settings -- EDIT THESE IN settings.json not here.. -//var pluginSettings = settings.ep_rss; -//var checkFrequency = pluginSettings.checkFrequency || 60000; // 10 seconds -//var staleTime = pluginSettings.staleTime || 300000; // 5 minutes -//var fromName = pluginSettings.fromName || "Etherpad"; -//var fromEmail = pluginSettings.fromEmail || "pad@etherpad.org"; -//var urlToPads = pluginSettings.urlToPads || "http://beta.etherpad.org/p/"; -// -// A timer object we maintain to control how we send emails -//var timers = {}; - -exports.padUpdate = function (hook_name, _pad) { -// var pad = _pad.pad; -// var padId = pad.id; -// exports.sendUpdates(padId); -// -// // does an interval not exist for this pad? -// if(!timers[padId]){ -// console.debug("Someone started editing "+padId); -// exports.notifyBegin(padId); -// console.debug("Created an interval time check for "+padId); -// // if not then create one and write it to the timers object -// timers[padId] = exports.createInterval(padId, checkFrequency); -// }else{ // an interval already exists so don't create -// -// } -} -// -exports.sendUpdates = function(padId){ -// // check to see if we can delete this interval -// API.getLastEdited(padId, function(callback, message){ -// // we delete an interval if a pad hasn't been edited in X seconds. -// var currTS = new Date().getTime(); -// if(currTS - message.lastEdited > staleTime){ -// exports.notifyEnd(padId); -// / console.warn("Interval went stale so deleting it from object and timer"); -// var interval = timers[padId]; -// clearInterval(timers[padId]); // remove the interval timer -// delete timers[padId]; // remove the entry from the padId -// }else{ -// console.debug("email timeout not stale so not deleting"); -// } -// }); -// // The status of the users relationship with the pad -- IE if it's subscribed to this pad / if it's already on the pad -// // This comes frmo the database -// var userStatus = {}; // I'm not even sure we use this value.. I put it here when drunk or something -} - -// Creates an interval process to check to send Updates based on checkFrequency and it returns an ID -exports.createInterval = function(padId){ -// return setInterval(function(){ -// exports.sendUpdates(padId), checkFrequency -// }); -} -