Mercurial > psgxs
diff modules/http/mod_atom.js @ 33:62cbb1c49bc5
Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 05 Nov 2010 14:01:45 +0100 |
parents | |
children | bc717575e66a |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/modules/http/mod_atom.js @@ -0,0 +1,55 @@ +var config = require('../../configuration'); +var storage = require('../../storage'); +var forms = require('../../forms'); +var errors = require('../../errors'); +var makeError = errors.makeError; +var NS = require('../../namespaces'); +var xmpp = require('xmpp'); + +exports.atom = { + url: /^\/atom/, + func: function (req, res) { + var url = require('url').parse(req.url); + nodeID = url.pathname.substr(url.pathname.indexOf('/', 1)+1); + + var children; + if (nodeID && nodeID != '') { + var md = storage.getMetadata(nodeID); + if (md['pubsub#type'] != NS.ATOM) + return false; + + var response = xmpp.stanza('feed', {xmlns: 'http://www.w3.org/2005/Atom'}); + res.writeHead(200, {'Content-Type': 'text/xml'}); + if (!storage.existsNode(nodeID)) + return false; + + if (md['pubsub#title']) + response.c('title').t(md['pubsub#title']).up(); + if (md['pubsub#description']) + response.c('subtitle').t(md['pubsub#description']).up(); + if (md['pubsub#creation_date']) + response.c('published').t(md['pubsub#creation_date']).up(); + + children = storage.getItems(nodeID); + if (typeof children == 'number') + return false; + + for (var i in children) + response.cnode(children[i].content).up(); + } else { + res.writeHead(200, {'Content-Type': 'text/xml'}); + var response = xmpp.stanza('ul', {xmlns: 'http://www.w3.org/1999/xhtml'}); + + children = storage.getChildren(); + if (typeof children == 'number') + return false; + + for (var i in children) + response.c('li').c('a', {href: i}).t(i).up().up(); + } + + res.end(response.toString()); + + return true; + }, +}